@hed-hog/category 0.0.2 → 0.0.3
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/dist/category.controller.d.ts +26 -7
- package/dist/category.controller.d.ts.map +1 -1
- package/dist/category.controller.js +24 -15
- package/dist/category.controller.js.map +1 -1
- package/dist/category.service.d.ts +26 -7
- package/dist/category.service.d.ts.map +1 -1
- package/dist/category.service.js +85 -34
- package/dist/category.service.js.map +1 -1
- package/dist/dto/category.dto.d.ts +3 -1
- package/dist/dto/category.dto.d.ts.map +1 -1
- package/dist/dto/category.dto.js +4 -4
- package/dist/dto/category.dto.js.map +1 -1
- package/hedhog/data/route.yaml +6 -0
- package/package.json +1 -1
- package/src/category.controller.ts +14 -10
- package/src/category.service.ts +95 -35
- package/src/dto/category.dto.ts +10 -9
|
@@ -3,6 +3,7 @@ import { CategoryDTO } from './dto/category.dto';
|
|
|
3
3
|
export declare class CategoryController {
|
|
4
4
|
private readonly categoryService;
|
|
5
5
|
constructor(categoryService: CategoryService);
|
|
6
|
+
getRootCategories(locale: string): Promise<any[]>;
|
|
6
7
|
getStats(): Promise<{
|
|
7
8
|
total: number;
|
|
8
9
|
totalActive: number;
|
|
@@ -10,16 +11,25 @@ export declare class CategoryController {
|
|
|
10
11
|
totalRoot: number;
|
|
11
12
|
}>;
|
|
12
13
|
getById(id: number): Promise<{
|
|
14
|
+
category_locale: {
|
|
15
|
+
name: string;
|
|
16
|
+
id: number;
|
|
17
|
+
created_at: Date;
|
|
18
|
+
locale_id: number;
|
|
19
|
+
updated_at: Date;
|
|
20
|
+
category_id: number;
|
|
21
|
+
}[];
|
|
22
|
+
} & {
|
|
13
23
|
id: number;
|
|
14
24
|
created_at: Date;
|
|
15
25
|
updated_at: Date;
|
|
16
26
|
slug: string;
|
|
17
27
|
icon: string;
|
|
18
28
|
color: string;
|
|
19
|
-
category_id: number;
|
|
29
|
+
category_id: number | null;
|
|
20
30
|
status: import("@prisma/client").$Enums.category_status_enum;
|
|
21
31
|
}>;
|
|
22
|
-
getByParent(categoryId: string): Promise<any[]>;
|
|
32
|
+
getByParent(categoryId: string, locale: string): Promise<any[]>;
|
|
23
33
|
findAll(paginationParams: any, locale: string, status: string, parent: string): Promise<{
|
|
24
34
|
total: any;
|
|
25
35
|
lastPage: number;
|
|
@@ -36,27 +46,36 @@ export declare class CategoryController {
|
|
|
36
46
|
slug: string;
|
|
37
47
|
icon: string;
|
|
38
48
|
color: string;
|
|
39
|
-
category_id: number;
|
|
49
|
+
category_id: number | null;
|
|
40
50
|
status: import("@prisma/client").$Enums.category_status_enum;
|
|
41
51
|
}>;
|
|
42
|
-
create(
|
|
52
|
+
create({ locale, slug, category_id, color, icon, status }: CategoryDTO): Promise<{
|
|
43
53
|
id: number;
|
|
44
54
|
created_at: Date;
|
|
45
55
|
updated_at: Date;
|
|
46
56
|
slug: string;
|
|
47
57
|
icon: string;
|
|
48
58
|
color: string;
|
|
49
|
-
category_id: number;
|
|
59
|
+
category_id: number | null;
|
|
50
60
|
status: import("@prisma/client").$Enums.category_status_enum;
|
|
51
61
|
}>;
|
|
52
|
-
update(id: number,
|
|
62
|
+
update(id: number, { locale, slug, category_id, color, icon, status }: Partial<CategoryDTO>): Promise<{
|
|
63
|
+
category_locale: {
|
|
64
|
+
name: string;
|
|
65
|
+
id: number;
|
|
66
|
+
created_at: Date;
|
|
67
|
+
locale_id: number;
|
|
68
|
+
updated_at: Date;
|
|
69
|
+
category_id: number;
|
|
70
|
+
}[];
|
|
71
|
+
} & {
|
|
53
72
|
id: number;
|
|
54
73
|
created_at: Date;
|
|
55
74
|
updated_at: Date;
|
|
56
75
|
slug: string;
|
|
57
76
|
icon: string;
|
|
58
77
|
color: string;
|
|
59
|
-
category_id: number;
|
|
78
|
+
category_id: number | null;
|
|
60
79
|
status: import("@prisma/client").$Enums.category_status_enum;
|
|
61
80
|
}>;
|
|
62
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"category.controller.d.ts","sourceRoot":"","sources":["../src/category.controller.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,qBACa,kBAAkB;IAE3B,OAAO,CAAC,QAAQ,CAAC,eAAe;gBAAf,eAAe,EAAE,eAAe;IAI7C,QAAQ;;;;;;IAKR,OAAO,CAA4B,EAAE,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"category.controller.d.ts","sourceRoot":"","sources":["../src/category.controller.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,qBACa,kBAAkB;IAE3B,OAAO,CAAC,QAAQ,CAAC,eAAe;gBAAf,eAAe,EAAE,eAAe;IAI7C,iBAAiB,CAAW,MAAM,EAAE,MAAM;IAK1C,QAAQ;;;;;;IAKR,OAAO,CAA4B,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;;;;;IAK7C,WAAW,CACM,UAAU,EAAE,MAAM,EAC7B,MAAM,EAAE,MAAM;IAMpB,OAAO,CACG,gBAAgB,KAAA,EACpB,MAAM,EAAE,MAAM,EACP,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM;;;;;;;;;IAM3B,MAAM,CAA4B,EAAE,EAAE,MAAM;;;;;;;;;;IAK5C,MAAM,CACF,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,WAAW;;;;;;;;;;IAenE,MAAM,CACiB,EAAE,EAAE,MAAM,EAC7B,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,WAAW,CAAC;;;;;;;;;;;;;;;;;;;CAcnF"}
|
|
@@ -22,14 +22,17 @@ let CategoryController = class CategoryController {
|
|
|
22
22
|
constructor(categoryService) {
|
|
23
23
|
this.categoryService = categoryService;
|
|
24
24
|
}
|
|
25
|
+
async getRootCategories(locale) {
|
|
26
|
+
return this.categoryService.getRootCategories(locale);
|
|
27
|
+
}
|
|
25
28
|
async getStats() {
|
|
26
29
|
return this.categoryService.getStats();
|
|
27
30
|
}
|
|
28
31
|
async getById(id) {
|
|
29
32
|
return this.categoryService.getById(id);
|
|
30
33
|
}
|
|
31
|
-
async getByParent(categoryId) {
|
|
32
|
-
return this.categoryService.getByParent(categoryId);
|
|
34
|
+
async getByParent(categoryId, locale) {
|
|
35
|
+
return this.categoryService.getByParent(categoryId, locale);
|
|
33
36
|
}
|
|
34
37
|
async findAll(paginationParams, locale, status, parent) {
|
|
35
38
|
return this.categoryService.findAll(paginationParams, locale, status, parent);
|
|
@@ -37,9 +40,9 @@ let CategoryController = class CategoryController {
|
|
|
37
40
|
async delete(id) {
|
|
38
41
|
return this.categoryService.delete(id);
|
|
39
42
|
}
|
|
40
|
-
async create(
|
|
41
|
-
return this.categoryService.create(
|
|
42
|
-
|
|
43
|
+
async create({ locale, slug, category_id, color, icon, status }) {
|
|
44
|
+
return this.categoryService.create({
|
|
45
|
+
locale,
|
|
43
46
|
slug,
|
|
44
47
|
category_id,
|
|
45
48
|
color,
|
|
@@ -47,9 +50,9 @@ let CategoryController = class CategoryController {
|
|
|
47
50
|
status,
|
|
48
51
|
});
|
|
49
52
|
}
|
|
50
|
-
async update(id,
|
|
51
|
-
return this.categoryService.update(id,
|
|
52
|
-
|
|
53
|
+
async update(id, { locale, slug, category_id, color, icon, status }) {
|
|
54
|
+
return this.categoryService.update(id, {
|
|
55
|
+
locale,
|
|
53
56
|
slug,
|
|
54
57
|
category_id,
|
|
55
58
|
color,
|
|
@@ -59,6 +62,13 @@ let CategoryController = class CategoryController {
|
|
|
59
62
|
}
|
|
60
63
|
};
|
|
61
64
|
exports.CategoryController = CategoryController;
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, common_1.Get)('root'),
|
|
67
|
+
__param(0, (0, api_locale_1.Locale)()),
|
|
68
|
+
__metadata("design:type", Function),
|
|
69
|
+
__metadata("design:paramtypes", [String]),
|
|
70
|
+
__metadata("design:returntype", Promise)
|
|
71
|
+
], CategoryController.prototype, "getRootCategories", null);
|
|
62
72
|
__decorate([
|
|
63
73
|
(0, common_1.Get)('stats'),
|
|
64
74
|
__metadata("design:type", Function),
|
|
@@ -75,8 +85,9 @@ __decorate([
|
|
|
75
85
|
__decorate([
|
|
76
86
|
(0, common_1.Get)('parent/:categoryId'),
|
|
77
87
|
__param(0, (0, common_1.Param)('categoryId')),
|
|
88
|
+
__param(1, (0, api_locale_1.Locale)()),
|
|
78
89
|
__metadata("design:type", Function),
|
|
79
|
-
__metadata("design:paramtypes", [String]),
|
|
90
|
+
__metadata("design:paramtypes", [String, String]),
|
|
80
91
|
__metadata("design:returntype", Promise)
|
|
81
92
|
], CategoryController.prototype, "getByParent", null);
|
|
82
93
|
__decorate([
|
|
@@ -98,19 +109,17 @@ __decorate([
|
|
|
98
109
|
], CategoryController.prototype, "delete", null);
|
|
99
110
|
__decorate([
|
|
100
111
|
(0, common_1.Post)(),
|
|
101
|
-
__param(0, (0,
|
|
102
|
-
__param(1, (0, common_1.Body)()),
|
|
112
|
+
__param(0, (0, common_1.Body)()),
|
|
103
113
|
__metadata("design:type", Function),
|
|
104
|
-
__metadata("design:paramtypes", [
|
|
114
|
+
__metadata("design:paramtypes", [category_dto_1.CategoryDTO]),
|
|
105
115
|
__metadata("design:returntype", Promise)
|
|
106
116
|
], CategoryController.prototype, "create", null);
|
|
107
117
|
__decorate([
|
|
108
118
|
(0, common_1.Patch)(':id'),
|
|
109
119
|
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
|
|
110
|
-
__param(1, (0,
|
|
111
|
-
__param(2, (0, common_1.Body)()),
|
|
120
|
+
__param(1, (0, common_1.Body)()),
|
|
112
121
|
__metadata("design:type", Function),
|
|
113
|
-
__metadata("design:paramtypes", [Number,
|
|
122
|
+
__metadata("design:paramtypes", [Number, Object]),
|
|
114
123
|
__metadata("design:returntype", Promise)
|
|
115
124
|
], CategoryController.prototype, "update", null);
|
|
116
125
|
exports.CategoryController = CategoryController = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"category.controller.js","sourceRoot":"","sources":["../src/category.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAA6C;AAC7C,4DAAqD;AACrD,2CAUwB;AACxB,yDAAqD;AACrD,qDAAiD;AAG1C,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC7B,YACmB,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAChD,CAAC;IAGE,AAAN,KAAK,CAAC,QAAQ;QACZ,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAA;IACxC,CAAC;IAGK,AAAN,KAAK,CAAC,OAAO,CAA4B,EAAU;QACjD,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IACzC,CAAC;IAGK,AAAN,KAAK,CAAC,WAAW,
|
|
1
|
+
{"version":3,"file":"category.controller.js","sourceRoot":"","sources":["../src/category.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAA6C;AAC7C,4DAAqD;AACrD,2CAUwB;AACxB,yDAAqD;AACrD,qDAAiD;AAG1C,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC7B,YACmB,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAChD,CAAC;IAGE,AAAN,KAAK,CAAC,iBAAiB,CAAW,MAAc;QAC9C,OAAO,IAAI,CAAC,eAAe,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAA;IACvD,CAAC;IAGK,AAAN,KAAK,CAAC,QAAQ;QACZ,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAA;IACxC,CAAC;IAGK,AAAN,KA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GK;IADL,IAAA,YAAG,EAAC,OAAO,CAAC;;;;kDAGZ;AAGK;IADL,IAAA,YAAG,EAAC,KAAK,CAAC;IACI,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;;;;iDAEvC;AAGK;IADL,IAAA,YAAG,EAAC,oBAAoB,CAAC;IAEvB,WAAA,IAAA,cAAK,EAAC,YAAY,CAAC,CAAA;IACnB,WAAA,IAAA,mBAAM,GAAE,CAAA;;;;qDAGV;AAGK;IADL,IAAA,YAAG,GAAE;IAEH,WAAA,IAAA,2BAAU,GAAE,CAAA;IACZ,WAAA,IAAA,mBAAM,GAAE,CAAA;IACR,WAAA,IAAA,cAAK,EAAC,QAAQ,CAAC,CAAA;IACf,WAAA,IAAA,cAAK,EAAC,QAAQ,CAAC,CAAA;;;;iDAGjB;AAGK;IADL,IAAA,eAAM,EAAC,KAAK,CAAC;IACA,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;;;;gDAEtC;AAGK;IADL,IAAA,aAAI,GAAE;IAEJ,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAqD,0BAAW;;gDAYxE;AAGK;IADL,IAAA,cAAK,EAAC,KAAK,CAAC;IAEV,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;IACzB,WAAA,IAAA,aAAI,GAAE,CAAA;;;;gDAaR;6BA3EU,kBAAkB;IAD9B,IAAA,mBAAU,EAAC,UAAU,CAAC;qCAGe,kCAAe;GAFxC,kBAAkB,CA4E9B"}
|
|
@@ -14,16 +14,26 @@ export declare class CategoryService {
|
|
|
14
14
|
totalRoot: number;
|
|
15
15
|
}>;
|
|
16
16
|
getById(id: number): Promise<{
|
|
17
|
+
category_locale: {
|
|
18
|
+
name: string;
|
|
19
|
+
id: number;
|
|
20
|
+
created_at: Date;
|
|
21
|
+
locale_id: number;
|
|
22
|
+
updated_at: Date;
|
|
23
|
+
category_id: number;
|
|
24
|
+
}[];
|
|
25
|
+
} & {
|
|
17
26
|
id: number;
|
|
18
27
|
created_at: Date;
|
|
19
28
|
updated_at: Date;
|
|
20
29
|
slug: string;
|
|
21
30
|
icon: string;
|
|
22
31
|
color: string;
|
|
23
|
-
category_id: number;
|
|
32
|
+
category_id: number | null;
|
|
24
33
|
status: import("@prisma/client").$Enums.category_status_enum;
|
|
25
34
|
}>;
|
|
26
|
-
|
|
35
|
+
getRootCategories(locale: string): Promise<any[]>;
|
|
36
|
+
getByParent(id: string, locale: string): Promise<any[]>;
|
|
27
37
|
findAll(paginationParams: PaginationDTO, locale: string, status: string, parent: string): Promise<{
|
|
28
38
|
total: any;
|
|
29
39
|
lastPage: number;
|
|
@@ -40,27 +50,36 @@ export declare class CategoryService {
|
|
|
40
50
|
slug: string;
|
|
41
51
|
icon: string;
|
|
42
52
|
color: string;
|
|
43
|
-
category_id: number;
|
|
53
|
+
category_id: number | null;
|
|
44
54
|
status: import("@prisma/client").$Enums.category_status_enum;
|
|
45
55
|
}>;
|
|
46
|
-
create(
|
|
56
|
+
create({ locale, slug, category_id, color, icon, status }: CategoryDTO): Promise<{
|
|
47
57
|
id: number;
|
|
48
58
|
created_at: Date;
|
|
49
59
|
updated_at: Date;
|
|
50
60
|
slug: string;
|
|
51
61
|
icon: string;
|
|
52
62
|
color: string;
|
|
53
|
-
category_id: number;
|
|
63
|
+
category_id: number | null;
|
|
54
64
|
status: import("@prisma/client").$Enums.category_status_enum;
|
|
55
65
|
}>;
|
|
56
|
-
update(id: number,
|
|
66
|
+
update(id: number, { locale, slug, category_id, color, icon, status }: Partial<CategoryDTO>): Promise<{
|
|
67
|
+
category_locale: {
|
|
68
|
+
name: string;
|
|
69
|
+
id: number;
|
|
70
|
+
created_at: Date;
|
|
71
|
+
locale_id: number;
|
|
72
|
+
updated_at: Date;
|
|
73
|
+
category_id: number;
|
|
74
|
+
}[];
|
|
75
|
+
} & {
|
|
57
76
|
id: number;
|
|
58
77
|
created_at: Date;
|
|
59
78
|
updated_at: Date;
|
|
60
79
|
slug: string;
|
|
61
80
|
icon: string;
|
|
62
81
|
color: string;
|
|
63
|
-
category_id: number;
|
|
82
|
+
category_id: number | null;
|
|
64
83
|
status: import("@prisma/client").$Enums.category_status_enum;
|
|
65
84
|
}>;
|
|
66
85
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"category.service.d.ts","sourceRoot":"","sources":["../src/category.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,qBACa,eAAe;IAExB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAE3B,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAHb,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,iBAAiB,EAE7B,aAAa,EAAE,aAAa;IAGzC,QAAQ;;;;;;IAoBR,OAAO,CAAC,EAAE,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"category.service.d.ts","sourceRoot":"","sources":["../src/category.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,qBACa,eAAe;IAExB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAE3B,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAHb,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,iBAAiB,EAE7B,aAAa,EAAE,aAAa;IAGzC,QAAQ;;;;;;IAoBR,OAAO,CAAC,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;;;;;IAelB,iBAAiB,CAAC,MAAM,EAAE,MAAM;IAuBhC,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAsBtC,OAAO,CAAC,gBAAgB,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;;;;;;IAgDvF,MAAM,CAAC,EAAE,EAAE,MAAM;;;;;;;;;;IAcjB,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,WAAW;;;;;;;;;;IAkCtE,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,WAAW,CAAC;;;;;;;;;;;;;;;;;;;CAsDlG"}
|
package/dist/category.service.js
CHANGED
|
@@ -43,20 +43,57 @@ let CategoryService = class CategoryService {
|
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
async getById(id) {
|
|
46
|
-
|
|
46
|
+
const category = await this.prisma.category.findUnique({
|
|
47
47
|
where: { id: Number(id) },
|
|
48
|
+
include: {
|
|
49
|
+
category_locale: true,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
if (!category) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return category;
|
|
56
|
+
}
|
|
57
|
+
async getRootCategories(locale) {
|
|
58
|
+
const localeRecord = await this.localeService.getByCode(locale);
|
|
59
|
+
if (!localeRecord) {
|
|
60
|
+
throw new common_1.BadRequestException(`Locale ${locale} not found`);
|
|
61
|
+
}
|
|
62
|
+
const categories = await this.prisma.category.findMany({
|
|
63
|
+
where: { category_id: null, status: 'active' },
|
|
64
|
+
include: {
|
|
65
|
+
category_locale: {
|
|
66
|
+
where: {
|
|
67
|
+
locale_id: localeRecord.id,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
orderBy: { id: 'asc' },
|
|
48
72
|
});
|
|
73
|
+
return categories.map((category) => (0, api_1.itemTranslations)('category_locale', category));
|
|
49
74
|
}
|
|
50
|
-
async getByParent(id) {
|
|
75
|
+
async getByParent(id, locale) {
|
|
76
|
+
const localeRecord = await this.localeService.getByCode(locale);
|
|
77
|
+
if (!localeRecord) {
|
|
78
|
+
throw new common_1.BadRequestException(`Locale ${locale} not found`);
|
|
79
|
+
}
|
|
51
80
|
const categories = await this.prisma.category.findMany({
|
|
52
81
|
where: { category_id: Number(id) },
|
|
53
82
|
include: {
|
|
54
|
-
category_locale:
|
|
83
|
+
category_locale: {
|
|
84
|
+
where: {
|
|
85
|
+
locale_id: localeRecord.id,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
55
88
|
},
|
|
56
89
|
});
|
|
57
90
|
return categories.map((category) => (0, api_1.itemTranslations)('category_locale', category));
|
|
58
91
|
}
|
|
59
92
|
async findAll(paginationParams, locale, status, parent) {
|
|
93
|
+
const localeRecord = await this.localeService.getByCode(locale);
|
|
94
|
+
if (!localeRecord) {
|
|
95
|
+
throw new common_1.BadRequestException(`Locale ${locale} not found`);
|
|
96
|
+
}
|
|
60
97
|
const fields = ['slug'];
|
|
61
98
|
const OR = this.prisma.createInsensitiveSearch(fields, paginationParams);
|
|
62
99
|
const AND = [];
|
|
@@ -74,7 +111,11 @@ let CategoryService = class CategoryService {
|
|
|
74
111
|
AND,
|
|
75
112
|
},
|
|
76
113
|
include: {
|
|
77
|
-
category_locale:
|
|
114
|
+
category_locale: {
|
|
115
|
+
where: {
|
|
116
|
+
locale_id: localeRecord.id,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
78
119
|
},
|
|
79
120
|
}, locale);
|
|
80
121
|
result.data = result.data.map((category) => (0, api_1.itemTranslations)('category_locale', category));
|
|
@@ -91,11 +132,7 @@ let CategoryService = class CategoryService {
|
|
|
91
132
|
where: { id: Number(id) },
|
|
92
133
|
});
|
|
93
134
|
}
|
|
94
|
-
async create(
|
|
95
|
-
const localeRecord = await this.localeService.getByCode(locale);
|
|
96
|
-
if (!localeRecord) {
|
|
97
|
-
throw new common_1.BadRequestException(`Locale ${locale} not found`);
|
|
98
|
-
}
|
|
135
|
+
async create({ locale, slug, category_id, color, icon, status }) {
|
|
99
136
|
const category = await this.prisma.category.create({
|
|
100
137
|
data: {
|
|
101
138
|
slug,
|
|
@@ -108,16 +145,23 @@ let CategoryService = class CategoryService {
|
|
|
108
145
|
if (!category) {
|
|
109
146
|
throw new common_1.BadRequestException('Category not created');
|
|
110
147
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
148
|
+
// Process all locales from the locale object
|
|
149
|
+
for (const [localeCode, localeData] of Object.entries(locale)) {
|
|
150
|
+
const localeRecord = await this.localeService.getByCode(localeCode);
|
|
151
|
+
if (!localeRecord) {
|
|
152
|
+
throw new common_1.BadRequestException(`Locale ${localeCode} not found`);
|
|
153
|
+
}
|
|
154
|
+
await this.prisma.category_locale.create({
|
|
155
|
+
data: {
|
|
156
|
+
name: localeData.name,
|
|
157
|
+
category_id: category.id,
|
|
158
|
+
locale_id: localeRecord.id,
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
}
|
|
114
162
|
return category;
|
|
115
163
|
}
|
|
116
|
-
async update(id,
|
|
117
|
-
const localeRecord = await this.localeService.getByCode(locale);
|
|
118
|
-
if (!localeRecord) {
|
|
119
|
-
throw new common_1.BadRequestException(`Locale ${locale} not found`);
|
|
120
|
-
}
|
|
164
|
+
async update(id, { locale, slug, category_id, color, icon, status }) {
|
|
121
165
|
const category = await this.prisma.category.findUnique({
|
|
122
166
|
where: { id: Number(id) },
|
|
123
167
|
});
|
|
@@ -134,27 +178,34 @@ let CategoryService = class CategoryService {
|
|
|
134
178
|
status,
|
|
135
179
|
},
|
|
136
180
|
});
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
where: { id: existingLocale.id },
|
|
147
|
-
data: { name },
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
await this.prisma.category_locale.create({
|
|
152
|
-
data: {
|
|
181
|
+
// Process all locales from the locale object
|
|
182
|
+
if (locale) {
|
|
183
|
+
for (const [localeCode, localeData] of Object.entries(locale)) {
|
|
184
|
+
const localeRecord = await this.localeService.getByCode(localeCode);
|
|
185
|
+
if (!localeRecord) {
|
|
186
|
+
throw new common_1.BadRequestException(`Locale ${localeCode} not found`);
|
|
187
|
+
}
|
|
188
|
+
const existingLocale = await this.prisma.category_locale.findFirst({
|
|
189
|
+
where: {
|
|
153
190
|
category_id: Number(id),
|
|
154
191
|
locale_id: localeRecord.id,
|
|
155
|
-
name,
|
|
156
192
|
},
|
|
157
193
|
});
|
|
194
|
+
if (existingLocale) {
|
|
195
|
+
await this.prisma.category_locale.update({
|
|
196
|
+
where: { id: existingLocale.id },
|
|
197
|
+
data: { name: localeData.name },
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
await this.prisma.category_locale.create({
|
|
202
|
+
data: {
|
|
203
|
+
category_id: Number(id),
|
|
204
|
+
locale_id: localeRecord.id,
|
|
205
|
+
name: localeData.name,
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
}
|
|
158
209
|
}
|
|
159
210
|
}
|
|
160
211
|
return this.getById(id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"category.service.js","sourceRoot":"","sources":["../src/category.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sCAAgD;AAChD,oDAAoD;AACpD,4DAA2E;AAC3E,oDAAoD;AACpD,2CAA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,KAAK,EAAE;wBACL,WAAW,EAAE,MAAM,CAAC,EAAE,CAAC;wBACvB,SAAS,EAAE,YAAY,CAAC,EAAE;qBAC3B;iBACF,CAAC,CAAC;gBAEH,IAAI,cAAc,EAAE,CAAC;oBACnB,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC;wBACvC,KAAK,EAAE,EAAE,EAAE,EAAE,cAAc,CAAC,EAAE,EAAE;wBAChC,IAAI,EAAE,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE;qBAChC,CAAC,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACN,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC;wBACvC,IAAI,EAAE;4BACJ,WAAW,EAAE,MAAM,CAAC,EAAE,CAAC;4BACvB,SAAS,EAAE,YAAY,CAAC,EAAE;4BAC1B,IAAI,EAAE,UAAU,CAAC,IAAI;yBACtB;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;CACF,CAAA;AA9OY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,0BAAa,CAAC,CAAC,CAAA;qCAFf,0BAAa;QACT,kCAAiB;QAEd,0BAAa;GALpC,eAAe,CA8O3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"category.dto.d.ts","sourceRoot":"","sources":["../../src/dto/category.dto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"category.dto.d.ts","sourceRoot":"","sources":["../../src/dto/category.dto.ts"],"names":[],"mappings":"AAUA,qBAAa,WAAW;IAGtB,IAAI,EAAE,MAAM,CAAC;IAIb,WAAW,CAAC,EAAE,MAAM,CAAC;IAOrB,KAAK,CAAC,EAAE,MAAM,CAAC;IAIf,IAAI,CAAC,EAAE,MAAM,CAAC;IAMd,MAAM,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;IAI/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC1C"}
|
package/dist/dto/category.dto.js
CHANGED
|
@@ -45,8 +45,8 @@ __decorate([
|
|
|
45
45
|
__metadata("design:type", String)
|
|
46
46
|
], CategoryDTO.prototype, "status", void 0);
|
|
47
47
|
__decorate([
|
|
48
|
-
(0, class_validator_1.
|
|
49
|
-
(0, class_validator_1.IsNotEmpty)(
|
|
50
|
-
__metadata("design:type",
|
|
51
|
-
], CategoryDTO.prototype, "
|
|
48
|
+
(0, class_validator_1.IsObject)(),
|
|
49
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
50
|
+
__metadata("design:type", Object)
|
|
51
|
+
], CategoryDTO.prototype, "locale", void 0);
|
|
52
52
|
//# sourceMappingURL=category.dto.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"category.dto.js","sourceRoot":"","sources":["../../src/dto/category.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"category.dto.js","sourceRoot":"","sources":["../../src/dto/category.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAQyB;AAEzB,MAAa,WAAW;CA6BvB;AA7BD,kCA6BC;AA1BC;IAFC,IAAA,0BAAQ,EAAC,EAAE,OAAO,EAAE,6BAA6B,EAAE,CAAC;IACpD,IAAA,4BAAU,EAAC,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAC;;yCACpC;AAIb;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,EAAC,EAAE,EAAE,EAAE,OAAO,EAAE,uCAAuC,EAAE,CAAC;;gDAC9C;AAOrB;IALC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,EAAC,EAAE,OAAO,EAAE,4BAA4B,EAAE,CAAC;IACnD,IAAA,yBAAO,EAAC,oCAAoC,EAAE;QAC7C,OAAO,EAAE,6CAA6C;KACvD,CAAC;;0CACa;AAIf;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,EAAC,EAAE,OAAO,EAAE,8BAA8B,EAAE,CAAC;;yCACxC;AAMd;IAJC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAM,EAAC,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE;QAC9B,OAAO,EAAE,2CAA2C;KACrD,CAAC;;2CAC6B;AAI/B;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;2CAC4B"}
|
package/hedhog/data/route.yaml
CHANGED
package/package.json
CHANGED
|
@@ -20,6 +20,11 @@ export class CategoryController {
|
|
|
20
20
|
private readonly categoryService: CategoryService
|
|
21
21
|
) {}
|
|
22
22
|
|
|
23
|
+
@Get('root')
|
|
24
|
+
async getRootCategories(@Locale() locale: string) {
|
|
25
|
+
return this.categoryService.getRootCategories(locale)
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
@Get('stats')
|
|
24
29
|
async getStats() {
|
|
25
30
|
return this.categoryService.getStats()
|
|
@@ -31,8 +36,11 @@ export class CategoryController {
|
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
@Get('parent/:categoryId')
|
|
34
|
-
async getByParent(
|
|
35
|
-
|
|
39
|
+
async getByParent(
|
|
40
|
+
@Param('categoryId') categoryId: string,
|
|
41
|
+
@Locale() locale: string,
|
|
42
|
+
) {
|
|
43
|
+
return this.categoryService.getByParent(categoryId, locale)
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
@Get()
|
|
@@ -52,13 +60,11 @@ export class CategoryController {
|
|
|
52
60
|
|
|
53
61
|
@Post()
|
|
54
62
|
async create(
|
|
55
|
-
@
|
|
56
|
-
@Body() { name, slug, category_id, color, icon, status }: CategoryDTO,
|
|
63
|
+
@Body() { locale, slug, category_id, color, icon, status }: CategoryDTO,
|
|
57
64
|
) {
|
|
58
65
|
return this.categoryService.create(
|
|
59
|
-
locale,
|
|
60
66
|
{
|
|
61
|
-
|
|
67
|
+
locale,
|
|
62
68
|
slug,
|
|
63
69
|
category_id,
|
|
64
70
|
color,
|
|
@@ -71,14 +77,12 @@ export class CategoryController {
|
|
|
71
77
|
@Patch(':id')
|
|
72
78
|
async update(
|
|
73
79
|
@Param('id', ParseIntPipe) id: number,
|
|
74
|
-
@
|
|
75
|
-
@Body() { name, slug, category_id, color, icon, status }: Partial<CategoryDTO>,
|
|
80
|
+
@Body() { locale, slug, category_id, color, icon, status }: Partial<CategoryDTO>,
|
|
76
81
|
) {
|
|
77
82
|
return this.categoryService.update(
|
|
78
83
|
id,
|
|
79
|
-
locale,
|
|
80
84
|
{
|
|
81
|
-
|
|
85
|
+
locale,
|
|
82
86
|
slug,
|
|
83
87
|
category_id,
|
|
84
88
|
color,
|
package/src/category.service.ts
CHANGED
|
@@ -35,16 +35,57 @@ export class CategoryService {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
async getById(id: number){
|
|
38
|
-
|
|
38
|
+
const category = await this.prisma.category.findUnique({
|
|
39
39
|
where: { id: Number(id) },
|
|
40
|
+
include: {
|
|
41
|
+
category_locale: true,
|
|
42
|
+
},
|
|
40
43
|
});
|
|
44
|
+
|
|
45
|
+
if (!category) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return category;
|
|
41
50
|
}
|
|
42
51
|
|
|
43
|
-
async
|
|
52
|
+
async getRootCategories(locale: string){
|
|
53
|
+
const localeRecord = await this.localeService.getByCode(locale);
|
|
54
|
+
if (!localeRecord) {
|
|
55
|
+
throw new BadRequestException(`Locale ${locale} not found`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const categories = await this.prisma.category.findMany({
|
|
59
|
+
where: { category_id: null, status: 'active' },
|
|
60
|
+
include: {
|
|
61
|
+
category_locale: {
|
|
62
|
+
where: {
|
|
63
|
+
locale_id: localeRecord.id,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
orderBy: { id: 'asc' },
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return categories.map((category) =>
|
|
71
|
+
itemTranslations('category_locale', category),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async getByParent(id: string, locale: string){
|
|
76
|
+
const localeRecord = await this.localeService.getByCode(locale);
|
|
77
|
+
if (!localeRecord) {
|
|
78
|
+
throw new BadRequestException(`Locale ${locale} not found`);
|
|
79
|
+
}
|
|
80
|
+
|
|
44
81
|
const categories = await this.prisma.category.findMany({
|
|
45
82
|
where: { category_id: Number(id) },
|
|
46
83
|
include: {
|
|
47
|
-
category_locale:
|
|
84
|
+
category_locale: {
|
|
85
|
+
where: {
|
|
86
|
+
locale_id: localeRecord.id,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
48
89
|
},
|
|
49
90
|
});
|
|
50
91
|
|
|
@@ -54,6 +95,11 @@ export class CategoryService {
|
|
|
54
95
|
}
|
|
55
96
|
|
|
56
97
|
async findAll(paginationParams: PaginationDTO, locale: string, status: string, parent: string){
|
|
98
|
+
const localeRecord = await this.localeService.getByCode(locale);
|
|
99
|
+
if (!localeRecord) {
|
|
100
|
+
throw new BadRequestException(`Locale ${locale} not found`);
|
|
101
|
+
}
|
|
102
|
+
|
|
57
103
|
const fields = ['slug'];
|
|
58
104
|
const OR = this.prisma.createInsensitiveSearch(fields, paginationParams);
|
|
59
105
|
const AND = [];
|
|
@@ -79,7 +125,11 @@ export class CategoryService {
|
|
|
79
125
|
AND,
|
|
80
126
|
},
|
|
81
127
|
include: {
|
|
82
|
-
category_locale:
|
|
128
|
+
category_locale: {
|
|
129
|
+
where: {
|
|
130
|
+
locale_id: localeRecord.id,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
83
133
|
},
|
|
84
134
|
},
|
|
85
135
|
locale,
|
|
@@ -106,12 +156,7 @@ export class CategoryService {
|
|
|
106
156
|
});
|
|
107
157
|
}
|
|
108
158
|
|
|
109
|
-
async create(
|
|
110
|
-
const localeRecord = await this.localeService.getByCode(locale);
|
|
111
|
-
if (!localeRecord) {
|
|
112
|
-
throw new BadRequestException(`Locale ${locale} not found`);
|
|
113
|
-
}
|
|
114
|
-
|
|
159
|
+
async create({ locale, slug, category_id, color, icon, status }: CategoryDTO){
|
|
115
160
|
const category = await this.prisma.category.create({
|
|
116
161
|
data: {
|
|
117
162
|
slug,
|
|
@@ -126,19 +171,26 @@ export class CategoryService {
|
|
|
126
171
|
throw new BadRequestException('Category not created');
|
|
127
172
|
}
|
|
128
173
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
174
|
+
// Process all locales from the locale object
|
|
175
|
+
for (const [localeCode, localeData] of Object.entries(locale)) {
|
|
176
|
+
const localeRecord = await this.localeService.getByCode(localeCode);
|
|
177
|
+
if (!localeRecord) {
|
|
178
|
+
throw new BadRequestException(`Locale ${localeCode} not found`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
await this.prisma.category_locale.create({
|
|
182
|
+
data: {
|
|
183
|
+
name: localeData.name,
|
|
184
|
+
category_id: category.id,
|
|
185
|
+
locale_id: localeRecord.id,
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
}
|
|
132
189
|
|
|
133
190
|
return category;
|
|
134
191
|
}
|
|
135
192
|
|
|
136
|
-
async update(id: number,
|
|
137
|
-
const localeRecord = await this.localeService.getByCode(locale);
|
|
138
|
-
if (!localeRecord) {
|
|
139
|
-
throw new BadRequestException(`Locale ${locale} not found`);
|
|
140
|
-
}
|
|
141
|
-
|
|
193
|
+
async update(id: number, { locale, slug, category_id, color, icon, status }: Partial<CategoryDTO>){
|
|
142
194
|
const category = await this.prisma.category.findUnique({
|
|
143
195
|
where: { id: Number(id) },
|
|
144
196
|
});
|
|
@@ -158,27 +210,35 @@ export class CategoryService {
|
|
|
158
210
|
},
|
|
159
211
|
});
|
|
160
212
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
213
|
+
// Process all locales from the locale object
|
|
214
|
+
if (locale) {
|
|
215
|
+
for (const [localeCode, localeData] of Object.entries(locale)) {
|
|
216
|
+
const localeRecord = await this.localeService.getByCode(localeCode);
|
|
217
|
+
if (!localeRecord) {
|
|
218
|
+
throw new BadRequestException(`Locale ${localeCode} not found`);
|
|
219
|
+
}
|
|
168
220
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
where: { id: existingLocale.id },
|
|
172
|
-
data: { name },
|
|
173
|
-
});
|
|
174
|
-
} else {
|
|
175
|
-
await this.prisma.category_locale.create({
|
|
176
|
-
data: {
|
|
221
|
+
const existingLocale = await this.prisma.category_locale.findFirst({
|
|
222
|
+
where: {
|
|
177
223
|
category_id: Number(id),
|
|
178
224
|
locale_id: localeRecord.id,
|
|
179
|
-
name,
|
|
180
225
|
},
|
|
181
226
|
});
|
|
227
|
+
|
|
228
|
+
if (existingLocale) {
|
|
229
|
+
await this.prisma.category_locale.update({
|
|
230
|
+
where: { id: existingLocale.id },
|
|
231
|
+
data: { name: localeData.name },
|
|
232
|
+
});
|
|
233
|
+
} else {
|
|
234
|
+
await this.prisma.category_locale.create({
|
|
235
|
+
data: {
|
|
236
|
+
category_id: Number(id),
|
|
237
|
+
locale_id: localeRecord.id,
|
|
238
|
+
name: localeData.name,
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
}
|
|
182
242
|
}
|
|
183
243
|
}
|
|
184
244
|
|
package/src/dto/category.dto.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
IsEnum,
|
|
3
|
+
IsNotEmpty,
|
|
4
|
+
IsNumber,
|
|
5
|
+
IsObject,
|
|
6
|
+
IsOptional,
|
|
7
|
+
IsString,
|
|
8
|
+
Matches,
|
|
8
9
|
} from 'class-validator';
|
|
9
10
|
|
|
10
11
|
export class CategoryDTO {
|
|
@@ -33,7 +34,7 @@ export class CategoryDTO {
|
|
|
33
34
|
})
|
|
34
35
|
status?: 'active' | 'inactive';
|
|
35
36
|
|
|
36
|
-
@
|
|
37
|
-
@IsNotEmpty(
|
|
38
|
-
name: string
|
|
37
|
+
@IsObject()
|
|
38
|
+
@IsNotEmpty()
|
|
39
|
+
locale: Record<string, { name: string }>;
|
|
39
40
|
}
|