import CategoryRepository from '../../repository/admin/CategoryRepository'; import CategoryLinkRepository from '../../repository/admin/CategoryLinkRepository'; import { createLog, updateLog } from '../../utils/LogActivity'; import { CustomRequest } from '../../types/token/CustomRequest'; // export const storeCategoryLinkService = async (tags: string[], source_type: string, source_id: string, req: CustomRequest) => { // const result = []; // for (let i = 0; i < tags.length; i++) { // const tag = tags[i]; // const existCategoryTag = await CategoryRepository.findByTag(tag); // let categoryId: string = ""; // if (!existCategoryTag) { // const created = await CategoryRepository.create({ tag: tag, description: null }); // categoryId = created.id; // await createLog(req, created); // } else { // categoryId = existCategoryTag.id; // } // const data = await CategoryLinkRepository.create({ // category_id: categoryId, // source_type: source_type, // source_id: source_id, // }); // await createLog(req, data); // result.push(data); // } // }; // export const updateCategoryLinkService = async (newTags: string[], source_type: string, source_id: string, req: CustomRequest) => { // const result = []; // const oldLinks = await CategoryLinkRepository.findBySource(source_type, source_id); // for (const link of oldLinks) { // await CategoryLinkRepository.deleteById(link.id); // } // for (const tag of newTags) { // let category = await CategoryRepository.findByTag(tag); // if (!category) { // category = await CategoryRepository.create({ tag, description: null }); // await createLog(req, category); // } // const newLink = await CategoryLinkRepository.create({ // category_id: category.id, // source_type, // source_id, // }); // await updateLog(req, newLink); // result.push(newLink); // } // return result; // };