import{GenericError as e}from"../utils/errors/ErrorsClass.mjs";import{validateUser as t}from"../utils/validation/validateUser.mjs";import{UserModel as n}from"../models/user.model.mjs";const r=async r=>{let i=t(r,[`email`]);if(Object.keys(i).length>0)throw new e(`USER_INVALID_FIELDS`,{userEmail:r.email,errors:i});let a=await n.create(r);if(!a)throw new e(`USER_CREATION_FAILED`,{userEmail:r.email});return a},i=async e=>await n.findOne({email:e}),a=async e=>await n.find({email:{$in:e}}),o=async e=>await n.exists({email:e})!==null,s=async e=>await n.findById(e),c=async e=>await n.find({_id:{$in:e}}),l=async(e,t,r,i)=>{let a=n.find(e).skip(t).limit(r);return i&&Object.keys(i).length>0&&(a=a.sort(i)),await a},u=async t=>{let r=await n.countDocuments(t);if(r===void 0)throw new e(`USER_COUNT_FAILED`);return r},d=async(r,i)=>{let a=t(i,Object.keys(i));if(Object.keys(a).length>0)throw new e(`USER_INVALID_FIELDS`,{userId:r,errors:a});if((await n.updateOne({_id:r},{$set:i})).matchedCount===0)throw new e(`USER_UPDATE_FAILED`,{userId:r});let o=await n.findById(r);if(!o)throw new e(`USER_UPDATED_USER_NOT_FOUND`,{userId:r});return o},f=async t=>{await s(t);let r=await n.findByIdAndDelete(t);if(!r)throw new e(`USER_NOT_FOUND`,{userId:t});return r};export{o as checkUserExists,u as countUsers,r as createUser,f as deleteUser,l as findUsers,i as getUserByEmail,s as getUserById,a as getUsersByEmails,c as getUsersByIds,d as updateUserById};
//# sourceMappingURL=user.service.mjs.map