@duvdu-v1/duvdu 1.1.222 → 1.1.223
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.
|
@@ -11,4 +11,13 @@ export declare function filterTagsForCategory(categoryId: string, subcategoryId:
|
|
|
11
11
|
filteredTags: Itag[];
|
|
12
12
|
media: string | undefined;
|
|
13
13
|
}>;
|
|
14
|
+
export declare function filterRelatedCategoryForCategory(categoryId: string, relatedCategories: Array<{
|
|
15
|
+
category: string;
|
|
16
|
+
subCategories?: Array<{
|
|
17
|
+
subCategory: string;
|
|
18
|
+
tags: Array<{
|
|
19
|
+
tag: string;
|
|
20
|
+
}>;
|
|
21
|
+
}>;
|
|
22
|
+
}>, lang: string): Promise<boolean>;
|
|
14
23
|
export {};
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.filterTagsForCategory = void 0;
|
|
12
|
+
exports.filterRelatedCategoryForCategory = exports.filterTagsForCategory = void 0;
|
|
13
13
|
const bad_request_error_1 = require("../errors/bad-request-error");
|
|
14
14
|
const notfound_error_1 = require("../errors/notfound-error");
|
|
15
15
|
const category_model_1 = require("../models/category.model");
|
|
@@ -17,7 +17,7 @@ const cycles_1 = require("../types/cycles");
|
|
|
17
17
|
function filterTagsForCategory(categoryId, subcategoryId, tagIds, cycle, lang) {
|
|
18
18
|
var _a;
|
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
const category = yield category_model_1.Categories.findOne({ _id: categoryId });
|
|
20
|
+
const category = yield category_model_1.Categories.findOne({ _id: categoryId, isRelated: false });
|
|
21
21
|
if (!category)
|
|
22
22
|
throw new notfound_error_1.NotFound({ en: 'Category not found', ar: 'الفئة غير موجودة' }, lang);
|
|
23
23
|
if (category.cycle !== cycle)
|
|
@@ -55,3 +55,47 @@ function filterTagsForCategory(categoryId, subcategoryId, tagIds, cycle, lang) {
|
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
exports.filterTagsForCategory = filterTagsForCategory;
|
|
58
|
+
function filterRelatedCategoryForCategory(categoryId, relatedCategories, lang) {
|
|
59
|
+
var _a;
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
// Validate main category exists and is not a related category
|
|
62
|
+
const mainCategory = yield category_model_1.Categories.findOne({ _id: categoryId, isRelated: false });
|
|
63
|
+
if (!mainCategory) {
|
|
64
|
+
throw new notfound_error_1.NotFound({ en: 'Category not found', ar: 'الفئة غير موجودة' }, lang);
|
|
65
|
+
}
|
|
66
|
+
// Get all related category IDs
|
|
67
|
+
const relatedCategoryIds = relatedCategories.map(rc => rc.category);
|
|
68
|
+
// Fetch all related categories in one query
|
|
69
|
+
const relatedCategoryDocs = yield category_model_1.Categories.find({
|
|
70
|
+
_id: { $in: relatedCategoryIds },
|
|
71
|
+
isRelated: true
|
|
72
|
+
});
|
|
73
|
+
if (relatedCategoryDocs.length !== relatedCategoryIds.length) {
|
|
74
|
+
throw new bad_request_error_1.BadRequestError({ en: 'One or more related categories not found', ar: 'واحد أو أكثر من الفئات المرتبطة غير موجودة' }, lang);
|
|
75
|
+
}
|
|
76
|
+
// Validate each related category's subcategories and tags
|
|
77
|
+
for (const relatedCategory of relatedCategories) {
|
|
78
|
+
const categoryDoc = relatedCategoryDocs.find(doc => doc._id.toString() === relatedCategory.category);
|
|
79
|
+
if (relatedCategory.subCategories) {
|
|
80
|
+
for (const subCat of relatedCategory.subCategories) {
|
|
81
|
+
// Find matching subcategory in the category document
|
|
82
|
+
const foundSubCategory = (_a = categoryDoc === null || categoryDoc === void 0 ? void 0 : categoryDoc.subCategories) === null || _a === void 0 ? void 0 : _a.find((sc) => sc._id.toString() === subCat.subCategory);
|
|
83
|
+
if (!foundSubCategory) {
|
|
84
|
+
throw new bad_request_error_1.BadRequestError({ en: 'Invalid subcategory ID', ar: 'معرف الفئة الفرعية غير صالح' }, lang);
|
|
85
|
+
}
|
|
86
|
+
// Validate tags
|
|
87
|
+
if (subCat.tags && subCat.tags.length > 0) {
|
|
88
|
+
const validTagIds = foundSubCategory.tags.map((tag) => tag._id.toString());
|
|
89
|
+
const providedTagIds = subCat.tags.map(t => t.tag);
|
|
90
|
+
const invalidTags = providedTagIds.filter(tagId => !validTagIds.includes(tagId));
|
|
91
|
+
if (invalidTags.length > 0) {
|
|
92
|
+
throw new bad_request_error_1.BadRequestError({ en: 'Invalid tags found', ar: 'تم العثور على علامات غير صالحة' }, lang);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
exports.filterRelatedCategoryForCategory = filterRelatedCategoryForCategory;
|