@hed-hog/faq 0.0.134 → 0.0.138
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/faq.controller.d.ts +2 -2
- package/dist/faq.controller.d.ts.map +1 -1
- package/dist/faq.controller.js +12 -14
- package/dist/faq.controller.js.map +1 -1
- package/dist/faq.service.d.ts +4 -3
- package/dist/faq.service.d.ts.map +1 -1
- package/dist/faq.service.js +35 -19
- package/dist/faq.service.js.map +1 -1
- package/package.json +6 -6
- package/src/faq.controller.ts +7 -12
- package/src/faq.service.ts +57 -24
package/dist/faq.controller.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export declare class FAQController {
|
|
|
37
37
|
created_at: Date;
|
|
38
38
|
updated_at: Date;
|
|
39
39
|
}>;
|
|
40
|
-
create(body: FAQDTO): Promise<{
|
|
40
|
+
create(locale: string, body: FAQDTO): Promise<{
|
|
41
41
|
locale: Record<string, {
|
|
42
42
|
question: string;
|
|
43
43
|
answer: string;
|
|
@@ -59,7 +59,7 @@ export declare class FAQController {
|
|
|
59
59
|
created_at: Date;
|
|
60
60
|
updated_at: Date;
|
|
61
61
|
}>;
|
|
62
|
-
update(id: number, body: Partial<FAQDTO>): Promise<{
|
|
62
|
+
update(locale: string, id: number, body: Partial<FAQDTO>): Promise<{
|
|
63
63
|
locale: Record<string, {
|
|
64
64
|
question: string;
|
|
65
65
|
answer: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faq.controller.d.ts","sourceRoot":"","sources":["../src/faq.controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"faq.controller.d.ts","sourceRoot":"","sources":["../src/faq.controller.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,qBAEa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,UAAU;IAG7C,IAAI,CACM,gBAAgB,KAAA,EACpB,MAAM,EAAE,MAAM;;;;;;;;;IAMpB,WAAW;;;IAKX,OAAO,CACgB,EAAE,EAAE,MAAM,EAC3B,MAAM,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;IAMpB,MAAM,CACA,MAAM,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;IAMhB,MAAM,CACA,MAAM,EAAE,MAAM,EACG,EAAE,EAAE,MAAM,EAC7B,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;IAMzB,MAAM,CACiB,EAAE,EAAE,MAAM,EAC3B,MAAM,EAAE,MAAM;;;;CAI3B"}
|
package/dist/faq.controller.js
CHANGED
|
@@ -30,17 +30,13 @@ let FAQController = class FAQController {
|
|
|
30
30
|
return this.faqService.getStats();
|
|
31
31
|
}
|
|
32
32
|
async getById(id, locale) {
|
|
33
|
-
|
|
34
|
-
if (!faq) {
|
|
35
|
-
throw new common_1.NotFoundException((0, api_locale_1.getLocaleText)('faqNotFound', locale, 'FAQ not found'));
|
|
36
|
-
}
|
|
37
|
-
return faq;
|
|
33
|
+
return this.faqService.getById(id, locale);
|
|
38
34
|
}
|
|
39
|
-
async create(body) {
|
|
40
|
-
return this.faqService.create(body);
|
|
35
|
+
async create(locale, body) {
|
|
36
|
+
return this.faqService.create(locale, body);
|
|
41
37
|
}
|
|
42
|
-
async update(id, body) {
|
|
43
|
-
return this.faqService.update(id, body);
|
|
38
|
+
async update(locale, id, body) {
|
|
39
|
+
return this.faqService.update(id, body, locale);
|
|
44
40
|
}
|
|
45
41
|
async delete(id, locale) {
|
|
46
42
|
return this.faqService.delete(id, locale);
|
|
@@ -71,17 +67,19 @@ __decorate([
|
|
|
71
67
|
], FAQController.prototype, "getById", null);
|
|
72
68
|
__decorate([
|
|
73
69
|
(0, common_1.Post)(),
|
|
74
|
-
__param(0, (0,
|
|
70
|
+
__param(0, (0, api_locale_1.Locale)()),
|
|
71
|
+
__param(1, (0, common_1.Body)()),
|
|
75
72
|
__metadata("design:type", Function),
|
|
76
|
-
__metadata("design:paramtypes", [faq_dto_1.FAQDTO]),
|
|
73
|
+
__metadata("design:paramtypes", [String, faq_dto_1.FAQDTO]),
|
|
77
74
|
__metadata("design:returntype", Promise)
|
|
78
75
|
], FAQController.prototype, "create", null);
|
|
79
76
|
__decorate([
|
|
80
77
|
(0, common_1.Patch)(':id'),
|
|
81
|
-
__param(0, (0,
|
|
82
|
-
__param(1, (0, common_1.
|
|
78
|
+
__param(0, (0, api_locale_1.Locale)()),
|
|
79
|
+
__param(1, (0, common_1.Param)('id', common_1.ParseIntPipe)),
|
|
80
|
+
__param(2, (0, common_1.Body)()),
|
|
83
81
|
__metadata("design:type", Function),
|
|
84
|
-
__metadata("design:paramtypes", [Number, Object]),
|
|
82
|
+
__metadata("design:paramtypes", [String, Number, Object]),
|
|
85
83
|
__metadata("design:returntype", Promise)
|
|
86
84
|
], FAQController.prototype, "update", null);
|
|
87
85
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faq.controller.js","sourceRoot":"","sources":["../src/faq.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sCAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"faq.controller.js","sourceRoot":"","sources":["../src/faq.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sCAAoC;AACpC,oDAA6C;AAC7C,4DAAqD;AACrD,2CASwB;AACxB,2CAAuC;AACvC,+CAA2C;AAGpC,IAAM,aAAa,GAAnB,MAAM,aAAa;IACxB,YAA6B,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAI,CAAC;IAGlD,AAAN,KAAK,CAAC,IAAI,CACM,gBAAgB,EACpB,MAAc;QAEzB,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAA;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V,WAAA,IAAA,mBAAM,GAAE,CAAA;IACR,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;IACzB,WAAA,IAAA,aAAI,GAAE,CAAA;;;;2CAGR;AAGK;IADL,IAAA,eAAM,EAAC,KAAK,CAAC;IAEX,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;IACzB,WAAA,IAAA,mBAAM,GAAE,CAAA;;;;2CAGV;wBA/CU,aAAa;IAFzB,IAAA,UAAI,GAAE;IACN,IAAA,mBAAU,EAAC,KAAK,CAAC;qCAEyB,wBAAU;GADxC,aAAa,CAgDzB"}
|
package/dist/faq.service.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare class FAQService {
|
|
|
5
5
|
private readonly prisma;
|
|
6
6
|
private readonly localeService;
|
|
7
7
|
constructor(prisma: PrismaService, localeService: LocaleService);
|
|
8
|
+
private validateLocaleData;
|
|
8
9
|
list(paginationParams: any, locale: string): Promise<{
|
|
9
10
|
data: any[];
|
|
10
11
|
total: number;
|
|
@@ -17,7 +18,7 @@ export declare class FAQService {
|
|
|
17
18
|
getStats(): Promise<{
|
|
18
19
|
total: number;
|
|
19
20
|
}>;
|
|
20
|
-
create(body: FAQDTO): Promise<{
|
|
21
|
+
create(localeStr: string, body: FAQDTO): Promise<{
|
|
21
22
|
locale: Record<string, {
|
|
22
23
|
question: string;
|
|
23
24
|
answer: string;
|
|
@@ -39,7 +40,7 @@ export declare class FAQService {
|
|
|
39
40
|
created_at: Date;
|
|
40
41
|
updated_at: Date;
|
|
41
42
|
}>;
|
|
42
|
-
getById(id: number): Promise<{
|
|
43
|
+
getById(id: number, locale: string): Promise<{
|
|
43
44
|
locale: Record<string, {
|
|
44
45
|
question: string;
|
|
45
46
|
answer: string;
|
|
@@ -61,7 +62,7 @@ export declare class FAQService {
|
|
|
61
62
|
created_at: Date;
|
|
62
63
|
updated_at: Date;
|
|
63
64
|
}>;
|
|
64
|
-
update(id: number, body: Partial<FAQDTO
|
|
65
|
+
update(id: number, body: Partial<FAQDTO>, localeStr: string): Promise<{
|
|
65
66
|
locale: Record<string, {
|
|
66
67
|
question: string;
|
|
67
68
|
answer: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faq.service.d.ts","sourceRoot":"","sources":["../src/faq.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAiB,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,qBACa,UAAU;IAEnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAFb,MAAM,EAAE,aAAa,EAErB,aAAa,EAAE,aAAa;
|
|
1
|
+
{"version":3,"file":"faq.service.d.ts","sourceRoot":"","sources":["../src/faq.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAiB,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,qBACa,UAAU;IAEnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAFb,MAAM,EAAE,aAAa,EAErB,aAAa,EAAE,aAAa;IAG/C,OAAO,CAAC,kBAAkB;IA6BpB,IAAI,CAAC,gBAAgB,KAAA,EAAE,MAAM,EAAE,MAAM;;;;;;;;;IAsGrC,QAAQ;;;IAOR,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;;sBAoDN,MAAM;oBAAU,MAAM;;;;;;;;;;;;;;;;;;;IAzBtD,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;sBAyBF,MAAM;oBAAU,MAAM;;;;;;;;;;;;;;;;;;;IAQtD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,MAAM;;sBAR3B,MAAM;oBAAU,MAAM;;;;;;;;;;;;;;;;;;;IAoDtD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,GAAE,MAAa;;;;CAqB/C"}
|
package/dist/faq.service.js
CHANGED
|
@@ -21,6 +21,20 @@ let FAQService = class FAQService {
|
|
|
21
21
|
this.prisma = prisma;
|
|
22
22
|
this.localeService = localeService;
|
|
23
23
|
}
|
|
24
|
+
validateLocaleData(locale, userLocale = 'en') {
|
|
25
|
+
const isLocaleInvalid = !locale ||
|
|
26
|
+
typeof locale !== 'object' ||
|
|
27
|
+
Object.keys(locale).length === 0 ||
|
|
28
|
+
Object.entries(locale).some(([, localeData]) => !localeData ||
|
|
29
|
+
typeof localeData !== 'object' ||
|
|
30
|
+
typeof localeData.question !== 'string' ||
|
|
31
|
+
localeData.question.trim() === '' ||
|
|
32
|
+
typeof localeData.answer !== 'string' ||
|
|
33
|
+
localeData.answer.trim() === '');
|
|
34
|
+
if (isLocaleInvalid) {
|
|
35
|
+
throw new Error((0, api_locale_1.getLocaleText)('faqLocaleInvalid', userLocale, 'O objeto de tradução não pode estar vazio e deve conter pergunta e resposta para cada idioma.'));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
24
38
|
async list(paginationParams, locale) {
|
|
25
39
|
var _a;
|
|
26
40
|
const localeRecord = await this.localeService.getByCode(locale);
|
|
@@ -117,27 +131,26 @@ let FAQService = class FAQService {
|
|
|
117
131
|
total,
|
|
118
132
|
};
|
|
119
133
|
}
|
|
120
|
-
async create(body) {
|
|
134
|
+
async create(localeStr, body) {
|
|
121
135
|
const { locale } = body;
|
|
136
|
+
this.validateLocaleData(locale, localeStr);
|
|
122
137
|
const faq = await this.prisma.faq.create({
|
|
123
138
|
data: {},
|
|
124
139
|
});
|
|
125
|
-
|
|
126
|
-
await
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
return this.getById(faq.id);
|
|
140
|
+
await Promise.all(Object.entries(locale).map(async ([localeCode, localeData]) => {
|
|
141
|
+
const localeRecord = await this.localeService.getByCode(localeCode);
|
|
142
|
+
await this.prisma.faq_locale.create({
|
|
143
|
+
data: {
|
|
144
|
+
faq_id: faq.id,
|
|
145
|
+
locale_id: localeRecord.id,
|
|
146
|
+
question: localeData.question,
|
|
147
|
+
answer: localeData.answer,
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}));
|
|
151
|
+
return this.getById(faq.id, localeStr);
|
|
139
152
|
}
|
|
140
|
-
async getById(id) {
|
|
153
|
+
async getById(id, locale) {
|
|
141
154
|
const faq = await this.prisma.faq.findUnique({
|
|
142
155
|
where: { id },
|
|
143
156
|
include: {
|
|
@@ -151,7 +164,7 @@ let FAQService = class FAQService {
|
|
|
151
164
|
},
|
|
152
165
|
});
|
|
153
166
|
if (!faq) {
|
|
154
|
-
|
|
167
|
+
throw new common_1.NotFoundException((0, api_locale_1.getLocaleText)('faqNotFound', locale, 'FAQ not found'));
|
|
155
168
|
}
|
|
156
169
|
const localeData = faq.faq_locale.reduce((acc, item) => {
|
|
157
170
|
const localeCode = item.locale.code;
|
|
@@ -163,8 +176,11 @@ let FAQService = class FAQService {
|
|
|
163
176
|
}, {});
|
|
164
177
|
return Object.assign(Object.assign({}, faq), { locale: localeData });
|
|
165
178
|
}
|
|
166
|
-
async update(id, body) {
|
|
179
|
+
async update(id, body, localeStr) {
|
|
167
180
|
const { locale } = body;
|
|
181
|
+
if (locale) {
|
|
182
|
+
this.validateLocaleData(locale);
|
|
183
|
+
}
|
|
168
184
|
if (locale) {
|
|
169
185
|
await Promise.all(Object.entries(locale).map(async ([localeCode, localeData]) => {
|
|
170
186
|
const localeRecord = await this.localeService.getByCode(localeCode);
|
|
@@ -195,7 +211,7 @@ let FAQService = class FAQService {
|
|
|
195
211
|
}
|
|
196
212
|
}));
|
|
197
213
|
}
|
|
198
|
-
return this.getById(id);
|
|
214
|
+
return this.getById(id, localeStr);
|
|
199
215
|
}
|
|
200
216
|
async delete(id, locale = 'en') {
|
|
201
217
|
const faq = await this.prisma.faq.findUnique({
|
package/dist/faq.service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faq.service.js","sourceRoot":"","sources":["../src/faq.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAAmE;AACnE,oDAAoD;AACpD,
|
|
1
|
+
{"version":3,"file":"faq.service.js","sourceRoot":"","sources":["../src/faq.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAAmE;AACnE,oDAAoD;AACpD,2CAAmF;AAI5E,IAAM,UAAU,GAAhB,MAAM,UAAU;IACrB,YACmB,MAAqB,EAErB,aAA4B;QAF5B,WAAM,GAAN,MAAM,CAAe;QAErB,kBAAa,GAAb,aAAa,CAAe;IAC5C,CAAC;IAEI,kBAAkB,CACxB,MAA4D,EAC5D,aAAqB,IAAI;QAEzB,MAAM,eAAe,GACnB,CAAC,MAAM;YACP,OAAO,MAAM,KAAK,QAAQ;YAC1B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC;YAChC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CACzB,CAAC,CAAC,EAAE,UAAU,CAAiD,EAAE,EAAE,CACjE,CAAC,UAAU;gBACX,OAAO,UAAU,KAAK,QAAQ;gBAC9B,OAAO,UAAU,CAAC,QAAQ,KAAK,QAAQ;gBACvC,UAAU,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE;gBACjC,OAAO,UAAU,CAAC,MAAM,KAAK,QAAQ;gBACrC,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,K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G,EAAE,CAAC;YACT,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,IAAA,0BAAa,EAAC,aAAa,EAAE,MAAM,EAAE,eAAe,CAAC;aAC/D,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;YAC3B,KAAK,EAAE,EAAE,EAAE,EAAE;SACd,CAAC,CAAC;QAEH,OAAO;YACL,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAA,0BAAa,EAAC,YAAY,EAAE,MAAM,EAAE,0BAA0B,CAAC;SACzE,CAAC;IACJ,CAAC;CACF,CAAA;AA9QY,gCAAU;qBAAV,UAAU;IADtB,IAAA,mBAAU,GAAE;IAIR,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,0BAAa,CAAC,CAAC,CAAA;qCADf,0BAAa;QAEN,0BAAa;GAJpC,UAAU,CA8QtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hed-hog/faq",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.138",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"@nestjs/core": "^11",
|
|
10
10
|
"@nestjs/jwt": "^11",
|
|
11
11
|
"@nestjs/mapped-types": "*",
|
|
12
|
-
"@hed-hog/api-locale": "0.0.
|
|
13
|
-
"@hed-hog/api-
|
|
14
|
-
"@hed-hog/api": "0.0.
|
|
15
|
-
"@hed-hog/core": "0.0.
|
|
16
|
-
"@hed-hog/api
|
|
12
|
+
"@hed-hog/api-locale": "0.0.11",
|
|
13
|
+
"@hed-hog/api-prisma": "0.0.4",
|
|
14
|
+
"@hed-hog/api-pagination": "0.0.5",
|
|
15
|
+
"@hed-hog/core": "0.0.137",
|
|
16
|
+
"@hed-hog/api": "0.0.3"
|
|
17
17
|
},
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
package/src/faq.controller.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { Role } from '@hed-hog/api';
|
|
2
|
-
import { Locale
|
|
2
|
+
import { Locale } from '@hed-hog/api-locale';
|
|
3
3
|
import { Pagination } from '@hed-hog/api-pagination';
|
|
4
4
|
import {
|
|
5
5
|
Body,
|
|
6
6
|
Controller,
|
|
7
7
|
Delete,
|
|
8
8
|
Get,
|
|
9
|
-
NotFoundException,
|
|
10
9
|
Param,
|
|
11
10
|
ParseIntPipe,
|
|
12
11
|
Patch,
|
|
13
|
-
Post
|
|
12
|
+
Post
|
|
14
13
|
} from '@nestjs/common';
|
|
15
14
|
import { FAQDTO } from './dto/faq.dto';
|
|
16
15
|
import { FAQService } from './faq.service';
|
|
@@ -37,28 +36,24 @@ export class FAQController {
|
|
|
37
36
|
@Param('id', ParseIntPipe) id: number,
|
|
38
37
|
@Locale() locale: string,
|
|
39
38
|
) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (!faq) {
|
|
43
|
-
throw new NotFoundException(getLocaleText('faqNotFound', locale, 'FAQ not found'));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return faq;
|
|
39
|
+
return this.faqService.getById(id, locale);
|
|
47
40
|
}
|
|
48
41
|
|
|
49
42
|
@Post()
|
|
50
43
|
async create(
|
|
44
|
+
@Locale() locale: string,
|
|
51
45
|
@Body() body: FAQDTO,
|
|
52
46
|
) {
|
|
53
|
-
return this.faqService.create(body)
|
|
47
|
+
return this.faqService.create(locale, body)
|
|
54
48
|
}
|
|
55
49
|
|
|
56
50
|
@Patch(':id')
|
|
57
51
|
async update(
|
|
52
|
+
@Locale() locale: string,
|
|
58
53
|
@Param('id', ParseIntPipe) id: number,
|
|
59
54
|
@Body() body: Partial<FAQDTO>,
|
|
60
55
|
) {
|
|
61
|
-
return this.faqService.update(id, body);
|
|
56
|
+
return this.faqService.update(id, body, locale);
|
|
62
57
|
}
|
|
63
58
|
|
|
64
59
|
@Delete(':id')
|
package/src/faq.service.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LocaleService, getLocaleText } from '@hed-hog/api-locale';
|
|
2
2
|
import { PrismaService } from '@hed-hog/api-prisma';
|
|
3
|
-
import { Inject, Injectable, forwardRef } from '@nestjs/common';
|
|
3
|
+
import { Inject, Injectable, NotFoundException, forwardRef } from '@nestjs/common';
|
|
4
4
|
import { FAQDTO } from './dto/faq.dto';
|
|
5
5
|
|
|
6
6
|
@Injectable()
|
|
@@ -11,6 +11,35 @@ export class FAQService {
|
|
|
11
11
|
private readonly localeService: LocaleService,
|
|
12
12
|
) {}
|
|
13
13
|
|
|
14
|
+
private validateLocaleData(
|
|
15
|
+
locale: Record<string, { question: string; answer: string }>,
|
|
16
|
+
userLocale: string = 'en'
|
|
17
|
+
): void {
|
|
18
|
+
const isLocaleInvalid =
|
|
19
|
+
!locale ||
|
|
20
|
+
typeof locale !== 'object' ||
|
|
21
|
+
Object.keys(locale).length === 0 ||
|
|
22
|
+
Object.entries(locale).some(
|
|
23
|
+
([, localeData]: [string, { question: string; answer: string }]) =>
|
|
24
|
+
!localeData ||
|
|
25
|
+
typeof localeData !== 'object' ||
|
|
26
|
+
typeof localeData.question !== 'string' ||
|
|
27
|
+
localeData.question.trim() === '' ||
|
|
28
|
+
typeof localeData.answer !== 'string' ||
|
|
29
|
+
localeData.answer.trim() === ''
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (isLocaleInvalid) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
getLocaleText(
|
|
35
|
+
'faqLocaleInvalid',
|
|
36
|
+
userLocale,
|
|
37
|
+
'O objeto de tradução não pode estar vazio e deve conter pergunta e resposta para cada idioma.'
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
14
43
|
async list(paginationParams, locale: string) {
|
|
15
44
|
const localeRecord = await this.localeService.getByCode(locale);
|
|
16
45
|
if (!localeRecord) {
|
|
@@ -120,34 +149,34 @@ export class FAQService {
|
|
|
120
149
|
};
|
|
121
150
|
}
|
|
122
151
|
|
|
123
|
-
async create(body: FAQDTO) {
|
|
152
|
+
async create(localeStr: string, body: FAQDTO) {
|
|
124
153
|
const { locale } = body;
|
|
125
|
-
|
|
154
|
+
|
|
155
|
+
this.validateLocaleData(locale, localeStr);
|
|
156
|
+
|
|
126
157
|
const faq = await this.prisma.faq.create({
|
|
127
158
|
data: {},
|
|
128
159
|
});
|
|
129
160
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
);
|
|
145
|
-
}
|
|
161
|
+
await Promise.all(
|
|
162
|
+
Object.entries(locale).map(async ([localeCode, localeData]) => {
|
|
163
|
+
const localeRecord = await this.localeService.getByCode(localeCode);
|
|
164
|
+
|
|
165
|
+
await this.prisma.faq_locale.create({
|
|
166
|
+
data: {
|
|
167
|
+
faq_id: faq.id,
|
|
168
|
+
locale_id: localeRecord.id,
|
|
169
|
+
question: localeData.question,
|
|
170
|
+
answer: localeData.answer,
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
})
|
|
174
|
+
);
|
|
146
175
|
|
|
147
|
-
return this.getById(faq.id);
|
|
176
|
+
return this.getById(faq.id, localeStr);
|
|
148
177
|
}
|
|
149
178
|
|
|
150
|
-
async getById(id: number) {
|
|
179
|
+
async getById(id: number, locale: string) {
|
|
151
180
|
const faq = await this.prisma.faq.findUnique({
|
|
152
181
|
where: { id },
|
|
153
182
|
include: {
|
|
@@ -162,7 +191,7 @@ export class FAQService {
|
|
|
162
191
|
});
|
|
163
192
|
|
|
164
193
|
if (!faq) {
|
|
165
|
-
|
|
194
|
+
throw new NotFoundException(getLocaleText('faqNotFound', locale, 'FAQ not found'));
|
|
166
195
|
}
|
|
167
196
|
|
|
168
197
|
const localeData = faq.faq_locale.reduce((acc, item) => {
|
|
@@ -180,9 +209,13 @@ export class FAQService {
|
|
|
180
209
|
};
|
|
181
210
|
}
|
|
182
211
|
|
|
183
|
-
async update(id: number, body: Partial<FAQDTO
|
|
212
|
+
async update(id: number, body: Partial<FAQDTO>, localeStr: string) {
|
|
184
213
|
const { locale } = body;
|
|
185
214
|
|
|
215
|
+
if (locale) {
|
|
216
|
+
this.validateLocaleData(locale);
|
|
217
|
+
}
|
|
218
|
+
|
|
186
219
|
if (locale) {
|
|
187
220
|
await Promise.all(
|
|
188
221
|
Object.entries(locale).map(async ([localeCode, localeData]) => {
|
|
@@ -217,7 +250,7 @@ export class FAQService {
|
|
|
217
250
|
);
|
|
218
251
|
}
|
|
219
252
|
|
|
220
|
-
return this.getById(id);
|
|
253
|
+
return this.getById(id, localeStr);
|
|
221
254
|
}
|
|
222
255
|
|
|
223
256
|
async delete(id: number, locale: string = 'en') {
|