import{GenericError as e}from"../utils/errors/ErrorsClass.mjs";import{validateTag as t}from"../utils/validation/validateTag.mjs";import{TagModel as n}from"../models/tag.model.mjs";const r=async(e,t=0,r=100,i)=>{let a=n.find(e).skip(t).limit(r);return i&&Object.keys(i).length>0&&(a=a.sort(i)),await a},i=async t=>{let r=await n.findById(t);if(!r)throw new e(`TAG_NOT_FOUND`,{tagId:t});return r},a=async(e,t)=>await n.find({key:{$in:e},organizationId:t}),o=async t=>{let r=await n.countDocuments(t);if(r===void 0)throw new e(`TAG_COUNT_FAILED`,{filters:t});return r},s=async r=>{let i=await t(r,[`key`]);if(Object.keys(i).length>0)throw new e(`TAG_INVALID_FIELDS`,{errors:i});return await n.create(r)},c=async(r,a)=>{let o=t(a,Object.keys(a));if(Object.keys(o).length>0)throw new e(`TAG_INVALID_FIELDS`,{tagId:r,errors:o});if((await n.updateOne({_id:r},a)).matchedCount===0)throw new e(`TAG_UPDATE_FAILED`,{tagId:r});return await i(r)},l=async t=>{let r=await n.findByIdAndDelete(t);if(!r)throw new e(`TAG_NOT_FOUND`,{tagId:t});return r};export{o as countTags,s as createTag,l as deleteTagById,r as findTags,i as getTagById,a as getTagsByKeys,c as updateTagById};
//# sourceMappingURL=tag.service.mjs.map