import{ensureMongoDocumentToObject as e}from"../utils/ensureMongoDocumentToObject.mjs";import{GenericError as t}from"../utils/errors/ErrorsClass.mjs";import{removeObjectKeys as n}from"../utils/removeObjectKeys.mjs";import{validateProject as r}from"../utils/validation/validateProject.mjs";import{ProjectModel as i}from"../models/project.model.mjs";const a=async(e,t=0,n=100,r)=>{let a=i.find(e).skip(t).limit(n);return r&&Object.keys(r).length>0&&(a=a.sort(r)),await a},o=async e=>{let n=await i.findById(e);if(!n)throw new t(`PROJECT_NOT_DEFINED`,{projectId:e});return n},s=async e=>{let n=await i.countDocuments(e);if(n===void 0)throw new t(`PROJECT_COUNT_FAILED`,{filters:e});return n},c=async e=>{e.oAuth2Access&&=void 0;let n=await r(e,[`name`]);if(Object.keys(n).length>0)throw new t(`PROJECT_INVALID_FIELDS`,{errors:n});return await i.create(e)},l=async(a,s)=>{let c=n(e(s),[`id`,`oAuth2Access`,`organizationId`]),l=r(s,Object.keys(c));if(Object.keys(l).length>0)throw new t(`PROJECT_INVALID_FIELDS`,{projectId:a,errors:l});if((await i.updateOne({_id:a},c)).matchedCount===0)throw new t(`PROJECT_UPDATE_FAILED`,{projectId:a});return await o(a)},u=async e=>{let n=await i.findByIdAndDelete(e);if(!n)throw new t(`PROJECT_NOT_DEFINED`,{projectId:e});return n};export{s as countProjects,c as createProject,u as deleteProjectById,a as findProjects,o as getProjectById,l as updateProjectById};
//# sourceMappingURL=project.service.mjs.map