import { TagModel } from "../models/TagModel" ; export async function getAllTags ( organization ) { const doc = await TagModel . findOne ( { organization , } ) ; if ( doc ) { return doc . tags ; } return [ ] ; } export async function addTags ( organization , tags ) { tags = tags . filter ( ( x ) => x . length > 1 ) ; if ( ! tags . length ) return ; await TagModel . updateOne ( { organization } , { $addToSet : { tags : { $each : tags } , } , } , { upsert : true , } ) ; } export async function addTagsDiff ( organization , oldTags , newTags ) { const diff = newTags . filter ( ( x ) => ! oldTags . includes ( x ) ) ; if ( diff . length ) { console . log ( diff ) ; await addTags ( organization , diff ) ; } }