finding it hard to send user to client without the password after creation (mongoose)
Here's my current createUser function in /services/user.service.ts.
export const createUser = async (userData: any): Promise<IUser> => {
const existingUser = await User.findOne({ email: userData.email });
if (existingUser) throw new BadRequestError('User already exists.');
const createdUser = await User.create(userData);
const user = omitProperty(
'password',
createdUser.toObject()
);
return user;
};
the quickest and easiest solution i found was cast the user doc into js object and pass it to a omitProperty which returns the object without the property provided in the first param.
But im positive there's a cleaner solution to this, any help?