CategoryLinkService.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import CategoryRepository from '../../repository/admin/CategoryRepository';
  2. import CategoryLinkRepository from '../../repository/admin/CategoryLinkRepository';
  3. import { createLog, updateLog } from '../../utils/LogActivity';
  4. import { CustomRequest } from '../../types/token/CustomRequest';
  5. // export const storeCategoryLinkService = async (tags: string[], source_type: string, source_id: string, req: CustomRequest) => {
  6. // const result = [];
  7. // for (let i = 0; i < tags.length; i++) {
  8. // const tag = tags[i];
  9. // const existCategoryTag = await CategoryRepository.findByTag(tag);
  10. // let categoryId: string = "";
  11. // if (!existCategoryTag) {
  12. // const created = await CategoryRepository.create({ tag: tag, description: null });
  13. // categoryId = created.id;
  14. // await createLog(req, created);
  15. // } else {
  16. // categoryId = existCategoryTag.id;
  17. // }
  18. // const data = await CategoryLinkRepository.create({
  19. // category_id: categoryId,
  20. // source_type: source_type,
  21. // source_id: source_id,
  22. // });
  23. // await createLog(req, data);
  24. // result.push(data);
  25. // }
  26. // };
  27. // export const updateCategoryLinkService = async (newTags: string[], source_type: string, source_id: string, req: CustomRequest) => {
  28. // const result = [];
  29. // const oldLinks = await CategoryLinkRepository.findBySource(source_type, source_id);
  30. // for (const link of oldLinks) {
  31. // await CategoryLinkRepository.deleteById(link.id);
  32. // }
  33. // for (const tag of newTags) {
  34. // let category = await CategoryRepository.findByTag(tag);
  35. // if (!category) {
  36. // category = await CategoryRepository.create({ tag, description: null });
  37. // await createLog(req, category);
  38. // }
  39. // const newLink = await CategoryLinkRepository.create({
  40. // category_id: category.id,
  41. // source_type,
  42. // source_id,
  43. // });
  44. // await updateLog(req, newLink);
  45. // result.push(newLink);
  46. // }
  47. // return result;
  48. // };