@duvdu-v1/duvdu 1.1.37 → 1.1.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.d.ts CHANGED
@@ -60,3 +60,4 @@ export * from './models/allProjects.model';
60
60
  export * from './models/report.model';
61
61
  export * from './models/messages.model';
62
62
  export * from './models/notification.model';
63
+ export * from './services/category.service';
package/build/index.js CHANGED
@@ -76,3 +76,4 @@ __exportStar(require("./models/allProjects.model"), exports);
76
76
  __exportStar(require("./models/report.model"), exports);
77
77
  __exportStar(require("./models/messages.model"), exports);
78
78
  __exportStar(require("./models/notification.model"), exports);
79
+ __exportStar(require("./services/category.service"), exports);
@@ -0,0 +1,13 @@
1
+ interface Itag {
2
+ ar: string;
3
+ en: string;
4
+ }
5
+ interface Ititle {
6
+ ar: string;
7
+ en: string;
8
+ }
9
+ export declare function filterTagsForCategory(categoryId: string, subcategoryId: string, tags: string[], cycle: string): Promise<{
10
+ subCategoryTitle: Ititle;
11
+ filteredTags: Itag[];
12
+ }>;
13
+ export {};
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.filterTagsForCategory = void 0;
13
+ const bad_request_error_1 = require("../errors/bad-request-error");
14
+ const notfound_error_1 = require("../errors/notfound-error");
15
+ const category_model_1 = require("../models/category.model");
16
+ function filterTagsForCategory(categoryId, subcategoryId, tags, cycle) {
17
+ var _a;
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const category = yield category_model_1.Categories.findOne({ _id: categoryId });
20
+ if (!category)
21
+ throw new notfound_error_1.NotFound('Category not found');
22
+ if (category.cycle !== cycle)
23
+ throw new bad_request_error_1.BadRequestError('This category is not related to this cycle');
24
+ const subcategoryFound = (_a = category.subCategories) === null || _a === void 0 ? void 0 : _a.find((subCategory) => subCategory._id.toString() === subcategoryId);
25
+ if (!subcategoryFound)
26
+ throw new bad_request_error_1.BadRequestError('Invalid subcategory');
27
+ function filterTags(tags, searchStrings) {
28
+ return tags.filter(tag => searchStrings.includes(tag.ar) || searchStrings.includes(tag.en));
29
+ }
30
+ const filteredTags = filterTags(subcategoryFound.tags, tags);
31
+ if (filteredTags.length != tags.length)
32
+ throw new bad_request_error_1.BadRequestError('Invalid tags');
33
+ return { subCategoryTitle: subcategoryFound.title, filteredTags };
34
+ });
35
+ }
36
+ exports.filterTagsForCategory = filterTagsForCategory;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duvdu-v1/duvdu",
3
- "version": "1.1.37",
3
+ "version": "1.1.38",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "files": [