@hed-hog/faq 0.0.3 → 0.0.5
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/dto/faq.dto.d.ts +4 -2
- package/dist/dto/faq.dto.d.ts.map +1 -1
- package/dist/dto/faq.dto.js +3 -8
- package/dist/dto/faq.dto.js.map +1 -1
- package/dist/faq.controller.d.ts +45 -13
- package/dist/faq.controller.d.ts.map +1 -1
- package/dist/faq.controller.js +9 -12
- package/dist/faq.controller.js.map +1 -1
- package/dist/faq.service.d.ts +45 -13
- package/dist/faq.service.d.ts.map +1 -1
- package/dist/faq.service.js +48 -43
- package/dist/faq.service.js.map +1 -1
- package/hedhog/table/faq.yaml +4 -1
- package/package.json +3 -3
- package/src/dto/faq.dto.ts +3 -7
- package/src/faq.controller.ts +3 -6
- package/src/faq.service.ts +61 -51
package/dist/dto/faq.dto.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faq.dto.d.ts","sourceRoot":"","sources":["../../src/dto/faq.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,MAAM;IAGf,QAAQ,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"faq.dto.d.ts","sourceRoot":"","sources":["../../src/dto/faq.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,MAAM;IAGf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChE"}
|
package/dist/dto/faq.dto.js
CHANGED
|
@@ -15,13 +15,8 @@ class FAQDTO {
|
|
|
15
15
|
}
|
|
16
16
|
exports.FAQDTO = FAQDTO;
|
|
17
17
|
__decorate([
|
|
18
|
-
(0, class_validator_1.
|
|
18
|
+
(0, class_validator_1.IsObject)(),
|
|
19
19
|
(0, class_validator_1.IsNotEmpty)(),
|
|
20
|
-
__metadata("design:type",
|
|
21
|
-
], FAQDTO.prototype, "
|
|
22
|
-
__decorate([
|
|
23
|
-
(0, class_validator_1.IsString)(),
|
|
24
|
-
(0, class_validator_1.IsNotEmpty)(),
|
|
25
|
-
__metadata("design:type", String)
|
|
26
|
-
], FAQDTO.prototype, "answer", void 0);
|
|
20
|
+
__metadata("design:type", Object)
|
|
21
|
+
], FAQDTO.prototype, "locale", void 0);
|
|
27
22
|
//# sourceMappingURL=faq.dto.js.map
|
package/dist/dto/faq.dto.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faq.dto.js","sourceRoot":"","sources":["../../src/dto/faq.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAuD;AAEvD,MAAa,MAAM;
|
|
1
|
+
{"version":3,"file":"faq.dto.js","sourceRoot":"","sources":["../../src/dto/faq.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAuD;AAEvD,MAAa,MAAM;CAIlB;AAJD,wBAIC;AADG;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;sCACgD"}
|
package/dist/faq.controller.d.ts
CHANGED
|
@@ -15,39 +15,71 @@ export declare class FAQController {
|
|
|
15
15
|
getFAQStats(): Promise<{
|
|
16
16
|
total: number;
|
|
17
17
|
}>;
|
|
18
|
-
getById(id: number
|
|
19
|
-
|
|
18
|
+
getById(id: number): Promise<{
|
|
19
|
+
locale: Record<string, {
|
|
20
|
+
question: string;
|
|
21
|
+
answer: string;
|
|
22
|
+
}>;
|
|
23
|
+
faq_locale: ({
|
|
24
|
+
locale: {
|
|
25
|
+
code: string;
|
|
26
|
+
};
|
|
27
|
+
} & {
|
|
20
28
|
id: number;
|
|
21
29
|
created_at: Date;
|
|
22
|
-
locale_id: number;
|
|
23
30
|
updated_at: Date;
|
|
31
|
+
locale_id: number;
|
|
24
32
|
faq_id: number;
|
|
25
33
|
question: string;
|
|
26
34
|
answer: string;
|
|
27
|
-
}[];
|
|
28
|
-
} & {
|
|
35
|
+
})[];
|
|
29
36
|
id: number;
|
|
30
37
|
created_at: Date;
|
|
31
38
|
updated_at: Date;
|
|
32
39
|
}>;
|
|
33
|
-
create(body: FAQDTO
|
|
34
|
-
|
|
40
|
+
create(body: FAQDTO): Promise<{
|
|
41
|
+
locale: Record<string, {
|
|
42
|
+
question: string;
|
|
43
|
+
answer: string;
|
|
44
|
+
}>;
|
|
45
|
+
faq_locale: ({
|
|
46
|
+
locale: {
|
|
47
|
+
code: string;
|
|
48
|
+
};
|
|
49
|
+
} & {
|
|
35
50
|
id: number;
|
|
36
51
|
created_at: Date;
|
|
37
|
-
locale_id: number;
|
|
38
52
|
updated_at: Date;
|
|
53
|
+
locale_id: number;
|
|
39
54
|
faq_id: number;
|
|
40
55
|
question: string;
|
|
41
56
|
answer: string;
|
|
42
|
-
}[];
|
|
43
|
-
} & {
|
|
57
|
+
})[];
|
|
44
58
|
id: number;
|
|
45
59
|
created_at: Date;
|
|
46
60
|
updated_at: Date;
|
|
47
61
|
}>;
|
|
48
|
-
update(id: number, body: Partial<FAQDTO
|
|
49
|
-
|
|
50
|
-
|
|
62
|
+
update(id: number, body: Partial<FAQDTO>): Promise<{
|
|
63
|
+
locale: Record<string, {
|
|
64
|
+
question: string;
|
|
65
|
+
answer: string;
|
|
66
|
+
}>;
|
|
67
|
+
faq_locale: ({
|
|
68
|
+
locale: {
|
|
69
|
+
code: string;
|
|
70
|
+
};
|
|
71
|
+
} & {
|
|
72
|
+
id: number;
|
|
73
|
+
created_at: Date;
|
|
74
|
+
updated_at: Date;
|
|
75
|
+
locale_id: number;
|
|
76
|
+
faq_id: number;
|
|
77
|
+
question: string;
|
|
78
|
+
answer: string;
|
|
79
|
+
})[];
|
|
80
|
+
id: number;
|
|
81
|
+
created_at: Date;
|
|
82
|
+
updated_at: Date;
|
|
51
83
|
}>;
|
|
52
84
|
delete(id: number): Promise<{
|
|
53
85
|
deleted: boolean;
|
|
@@ -1 +1 @@
|
|
|
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;AAE3C,qBACa,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,
|
|
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;AAE3C,qBACa,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;;;;;;;;;;;;;;;;;;;;;;IAYjC,MAAM,CACF,IAAI,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;IAMhB,MAAM,CACiB,EAAE,EAAE,MAAM,EAC7B,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;IAMzB,MAAM,CAA4B,EAAE,EAAE,MAAM;;;;CAGnD"}
|
package/dist/faq.controller.js
CHANGED
|
@@ -28,18 +28,18 @@ let FAQController = class FAQController {
|
|
|
28
28
|
async getFAQStats() {
|
|
29
29
|
return this.faqService.getStats();
|
|
30
30
|
}
|
|
31
|
-
async getById(id
|
|
32
|
-
const faq = await this.faqService.getById(id
|
|
31
|
+
async getById(id) {
|
|
32
|
+
const faq = await this.faqService.getById(id);
|
|
33
33
|
if (!faq) {
|
|
34
34
|
throw new common_1.NotFoundException('FAQ not found');
|
|
35
35
|
}
|
|
36
36
|
return faq;
|
|
37
37
|
}
|
|
38
|
-
async create(body
|
|
39
|
-
return this.faqService.create(body
|
|
38
|
+
async create(body) {
|
|
39
|
+
return this.faqService.create(body);
|
|
40
40
|
}
|
|
41
|
-
async update(id, body
|
|
42
|
-
return this.faqService.update(id, body
|
|
41
|
+
async update(id, body) {
|
|
42
|
+
return this.faqService.update(id, body);
|
|
43
43
|
}
|
|
44
44
|
async delete(id) {
|
|
45
45
|
return this.faqService.delete(id);
|
|
@@ -63,26 +63,23 @@ __decorate([
|
|
|
63
63
|
__decorate([
|
|
64
64
|
(0, common_1.Get)(':id'),
|
|
65
65
|
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
|
|
66
|
-
__param(1, (0, api_locale_1.Locale)()),
|
|
67
66
|
__metadata("design:type", Function),
|
|
68
|
-
__metadata("design:paramtypes", [Number
|
|
67
|
+
__metadata("design:paramtypes", [Number]),
|
|
69
68
|
__metadata("design:returntype", Promise)
|
|
70
69
|
], FAQController.prototype, "getById", null);
|
|
71
70
|
__decorate([
|
|
72
71
|
(0, common_1.Post)(),
|
|
73
72
|
__param(0, (0, common_1.Body)()),
|
|
74
|
-
__param(1, (0, api_locale_1.Locale)()),
|
|
75
73
|
__metadata("design:type", Function),
|
|
76
|
-
__metadata("design:paramtypes", [faq_dto_1.FAQDTO
|
|
74
|
+
__metadata("design:paramtypes", [faq_dto_1.FAQDTO]),
|
|
77
75
|
__metadata("design:returntype", Promise)
|
|
78
76
|
], FAQController.prototype, "create", null);
|
|
79
77
|
__decorate([
|
|
80
78
|
(0, common_1.Patch)(':id'),
|
|
81
79
|
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
|
|
82
80
|
__param(1, (0, common_1.Body)()),
|
|
83
|
-
__param(2, (0, api_locale_1.Locale)()),
|
|
84
81
|
__metadata("design:type", Function),
|
|
85
|
-
__metadata("design:paramtypes", [Number, Object
|
|
82
|
+
__metadata("design:paramtypes", [Number, Object]),
|
|
86
83
|
__metadata("design:returntype", Promise)
|
|
87
84
|
], FAQController.prototype, "update", null);
|
|
88
85
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faq.controller.js","sourceRoot":"","sources":["../src/faq.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAA6C;AAC7C,4DAAqD;AACrD,2CAUwB;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;IACtD,CAAC;IAGK,AAAN,KAAK,CAAC,WAAW;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAA;IACnC,CAAC;IAGK,AAAN,KAAK,CAAC,OAAO,CACgB,EAAU
|
|
1
|
+
{"version":3,"file":"faq.controller.js","sourceRoot":"","sources":["../src/faq.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAA6C;AAC7C,4DAAqD;AACrD,2CAUwB;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;IACtD,CAAC;IAGK,AAAN,KAAK,CAAC,WAAW;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAA;IACnC,CAAC;IAGK,AAAN,K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AAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;;;;2CAEtC;wBA/CU,aAAa;IADzB,IAAA,mBAAU,EAAC,KAAK,CAAC;qCAEyB,wBAAU;GADxC,aAAa,CAgDzB"}
|
package/dist/faq.service.d.ts
CHANGED
|
@@ -17,39 +17,71 @@ export declare class FAQService {
|
|
|
17
17
|
getStats(): Promise<{
|
|
18
18
|
total: number;
|
|
19
19
|
}>;
|
|
20
|
-
create(body: FAQDTO
|
|
21
|
-
|
|
20
|
+
create(body: FAQDTO): Promise<{
|
|
21
|
+
locale: Record<string, {
|
|
22
|
+
question: string;
|
|
23
|
+
answer: string;
|
|
24
|
+
}>;
|
|
25
|
+
faq_locale: ({
|
|
26
|
+
locale: {
|
|
27
|
+
code: string;
|
|
28
|
+
};
|
|
29
|
+
} & {
|
|
22
30
|
id: number;
|
|
23
31
|
created_at: Date;
|
|
24
|
-
locale_id: number;
|
|
25
32
|
updated_at: Date;
|
|
33
|
+
locale_id: number;
|
|
26
34
|
faq_id: number;
|
|
27
35
|
question: string;
|
|
28
36
|
answer: string;
|
|
29
|
-
}[];
|
|
30
|
-
} & {
|
|
37
|
+
})[];
|
|
31
38
|
id: number;
|
|
32
39
|
created_at: Date;
|
|
33
40
|
updated_at: Date;
|
|
34
41
|
}>;
|
|
35
|
-
getById(id: number
|
|
36
|
-
|
|
42
|
+
getById(id: number): Promise<{
|
|
43
|
+
locale: Record<string, {
|
|
44
|
+
question: string;
|
|
45
|
+
answer: string;
|
|
46
|
+
}>;
|
|
47
|
+
faq_locale: ({
|
|
48
|
+
locale: {
|
|
49
|
+
code: string;
|
|
50
|
+
};
|
|
51
|
+
} & {
|
|
37
52
|
id: number;
|
|
38
53
|
created_at: Date;
|
|
39
|
-
locale_id: number;
|
|
40
54
|
updated_at: Date;
|
|
55
|
+
locale_id: number;
|
|
41
56
|
faq_id: number;
|
|
42
57
|
question: string;
|
|
43
58
|
answer: string;
|
|
44
|
-
}[];
|
|
45
|
-
} & {
|
|
59
|
+
})[];
|
|
46
60
|
id: number;
|
|
47
61
|
created_at: Date;
|
|
48
62
|
updated_at: Date;
|
|
49
63
|
}>;
|
|
50
|
-
update(id: number, body: Partial<FAQDTO
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
update(id: number, body: Partial<FAQDTO>): Promise<{
|
|
65
|
+
locale: Record<string, {
|
|
66
|
+
question: string;
|
|
67
|
+
answer: string;
|
|
68
|
+
}>;
|
|
69
|
+
faq_locale: ({
|
|
70
|
+
locale: {
|
|
71
|
+
code: string;
|
|
72
|
+
};
|
|
73
|
+
} & {
|
|
74
|
+
id: number;
|
|
75
|
+
created_at: Date;
|
|
76
|
+
updated_at: Date;
|
|
77
|
+
locale_id: number;
|
|
78
|
+
faq_id: number;
|
|
79
|
+
question: string;
|
|
80
|
+
answer: string;
|
|
81
|
+
})[];
|
|
82
|
+
id: number;
|
|
83
|
+
created_at: Date;
|
|
84
|
+
updated_at: Date;
|
|
53
85
|
}>;
|
|
54
86
|
delete(id: number): Promise<{
|
|
55
87
|
deleted: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"faq.service.d.ts","sourceRoot":"","sources":["../src/faq.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,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;IAGzC,IAAI,CAAC,gBAAgB,KAAA,EAAE,MAAM,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"faq.service.d.ts","sourceRoot":"","sources":["../src/faq.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,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;IAGzC,IAAI,CAAC,gBAAgB,KAAA,EAAE,MAAM,EAAE,MAAM;cAkEzB,GAAG,EAAE;;;;;;;;IAUjB,QAAQ;;;IAOR,MAAM,CAAC,IAAI,EAAE,MAAM;;sBAoDa,MAAM;oBAAU,MAAM;;;;;;;;;;;;;;;;;;;IAzBtD,OAAO,CAAC,EAAE,EAAE,MAAM;;sBAyBc,MAAM;oBAAU,MAAM;;;;;;;;;;;;;;;;;;;IAQtD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC;;sBARR,MAAM;oBAAU,MAAM;;;;;;;;;;;;;;;;;;;IA+BtD,MAAM,CAAC,EAAE,EAAE,MAAM;;;;CAqBxB"}
|
package/dist/faq.service.js
CHANGED
|
@@ -43,8 +43,7 @@ let FAQService = class FAQService {
|
|
|
43
43
|
ON fl.faq_id = f.id
|
|
44
44
|
WHERE fl.locale_id = ${localeId}
|
|
45
45
|
AND (
|
|
46
|
-
LOWER(
|
|
47
|
-
OR LOWER(fl.question) LIKE ${like}
|
|
46
|
+
LOWER(fl.question) LIKE ${like}
|
|
48
47
|
OR LOWER(fl.answer) LIKE ${like}
|
|
49
48
|
)
|
|
50
49
|
ORDER BY f.id DESC
|
|
@@ -95,63 +94,69 @@ let FAQService = class FAQService {
|
|
|
95
94
|
total,
|
|
96
95
|
};
|
|
97
96
|
}
|
|
98
|
-
async create(body
|
|
99
|
-
const
|
|
100
|
-
if (!localeRecord) {
|
|
101
|
-
throw new Error(`Locale ${locale} not found`);
|
|
102
|
-
}
|
|
103
|
-
const { question, answer } = body;
|
|
97
|
+
async create(body) {
|
|
98
|
+
const { locale } = body;
|
|
104
99
|
const faq = await this.prisma.faq.create({
|
|
105
|
-
data: {
|
|
106
|
-
|
|
107
|
-
|
|
100
|
+
data: {},
|
|
101
|
+
});
|
|
102
|
+
if (locale) {
|
|
103
|
+
await Promise.all(Object.entries(locale).map(async ([localeCode, localeData]) => {
|
|
104
|
+
const localeRecord = await this.localeService.getByCode(localeCode);
|
|
105
|
+
await this.prisma.faq_locale.create({
|
|
106
|
+
data: {
|
|
107
|
+
faq_id: faq.id,
|
|
108
108
|
locale_id: localeRecord.id,
|
|
109
|
-
question,
|
|
110
|
-
answer,
|
|
109
|
+
question: localeData.question,
|
|
110
|
+
answer: localeData.answer,
|
|
111
111
|
},
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
include: {
|
|
115
|
-
faq_locale: true,
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
return faq;
|
|
119
|
-
}
|
|
120
|
-
async getById(id, locale) {
|
|
121
|
-
const localeRecord = await this.localeService.getByCode(locale);
|
|
122
|
-
if (!localeRecord) {
|
|
123
|
-
throw new Error(`Locale ${locale} not found`);
|
|
112
|
+
});
|
|
113
|
+
}));
|
|
124
114
|
}
|
|
115
|
+
return this.getById(faq.id);
|
|
116
|
+
}
|
|
117
|
+
async getById(id) {
|
|
125
118
|
const faq = await this.prisma.faq.findUnique({
|
|
126
119
|
where: { id },
|
|
127
120
|
include: {
|
|
128
121
|
faq_locale: {
|
|
129
|
-
|
|
122
|
+
include: {
|
|
123
|
+
locale: {
|
|
124
|
+
select: { code: true },
|
|
125
|
+
},
|
|
126
|
+
},
|
|
130
127
|
},
|
|
131
128
|
},
|
|
132
129
|
});
|
|
133
130
|
if (!faq) {
|
|
134
131
|
return null;
|
|
135
132
|
}
|
|
136
|
-
|
|
133
|
+
const localeData = faq.faq_locale.reduce((acc, item) => {
|
|
134
|
+
const localeCode = item.locale.code;
|
|
135
|
+
acc[localeCode] = {
|
|
136
|
+
question: item.question,
|
|
137
|
+
answer: item.answer,
|
|
138
|
+
};
|
|
139
|
+
return acc;
|
|
140
|
+
}, {});
|
|
141
|
+
return Object.assign(Object.assign({}, faq), { locale: localeData });
|
|
137
142
|
}
|
|
138
|
-
async update(id, body
|
|
139
|
-
const
|
|
140
|
-
if (
|
|
141
|
-
|
|
143
|
+
async update(id, body) {
|
|
144
|
+
const { locale } = body;
|
|
145
|
+
if (locale) {
|
|
146
|
+
await Promise.all(Object.entries(locale).map(async ([localeCode, localeData]) => {
|
|
147
|
+
const localeRecord = await this.localeService.getByCode(localeCode);
|
|
148
|
+
await this.prisma.$executeRaw `
|
|
149
|
+
INSERT INTO faq_locale (faq_id, locale_id, question, answer)
|
|
150
|
+
VALUES (${id}, ${localeRecord.id}, ${localeData.question}, ${localeData.answer})
|
|
151
|
+
ON CONFLICT (faq_id, locale_id)
|
|
152
|
+
DO UPDATE SET
|
|
153
|
+
question = EXCLUDED.question,
|
|
154
|
+
answer = EXCLUDED.answer,
|
|
155
|
+
updated_at = NOW()
|
|
156
|
+
`;
|
|
157
|
+
}));
|
|
142
158
|
}
|
|
143
|
-
|
|
144
|
-
const updated = await this.prisma.faq_locale.updateMany({
|
|
145
|
-
where: {
|
|
146
|
-
faq_id: id,
|
|
147
|
-
locale_id: localeRecord.id,
|
|
148
|
-
},
|
|
149
|
-
data: Object.assign(Object.assign({}, (question && { question })), (answer && { answer })),
|
|
150
|
-
});
|
|
151
|
-
return {
|
|
152
|
-
updated: updated.count,
|
|
153
|
-
message: updated.count > 0 ? 'FAQ updated successfully' : 'FAQ not found',
|
|
154
|
-
};
|
|
159
|
+
return this.getById(id);
|
|
155
160
|
}
|
|
156
161
|
async delete(id) {
|
|
157
162
|
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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AE,EAAE,EAAE,EAAE;SACd,CAAC,CAAC;QAEH,OAAO;YACL,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,0BAA0B;SACpC,CAAC;IACJ,CAAC;CACF,CAAA;AAlMY,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,CAkMtB"}
|
package/hedhog/table/faq.yaml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hed-hog/faq",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"@nestjs/core": "^11",
|
|
10
10
|
"@nestjs/jwt": "^11",
|
|
11
11
|
"@nestjs/mapped-types": "*",
|
|
12
|
-
"@hed-hog/admin": "0.0.129",
|
|
13
|
-
"@hed-hog/api": "0.0.3",
|
|
14
12
|
"@hed-hog/api-locale": "0.0.10",
|
|
13
|
+
"@hed-hog/admin": "0.0.130",
|
|
14
|
+
"@hed-hog/api": "0.0.3",
|
|
15
15
|
"@hed-hog/api-pagination": "0.0.3",
|
|
16
16
|
"@hed-hog/api-prisma": "0.0.4"
|
|
17
17
|
},
|
package/src/dto/faq.dto.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { IsNotEmpty,
|
|
1
|
+
import { IsNotEmpty, IsObject } from "class-validator";
|
|
2
2
|
|
|
3
3
|
export class FAQDTO{
|
|
4
|
-
@
|
|
4
|
+
@IsObject()
|
|
5
5
|
@IsNotEmpty()
|
|
6
|
-
question: string;
|
|
7
|
-
|
|
8
|
-
@IsString()
|
|
9
|
-
@IsNotEmpty()
|
|
10
|
-
answer: string;
|
|
6
|
+
locale: Record<string, { question: string; answer: string }>;
|
|
11
7
|
}
|
package/src/faq.controller.ts
CHANGED
|
@@ -34,9 +34,8 @@ export class FAQController {
|
|
|
34
34
|
@Get(':id')
|
|
35
35
|
async getById(
|
|
36
36
|
@Param('id', ParseIntPipe) id: number,
|
|
37
|
-
@Locale() locale: string,
|
|
38
37
|
) {
|
|
39
|
-
const faq = await this.faqService.getById(id
|
|
38
|
+
const faq = await this.faqService.getById(id);
|
|
40
39
|
|
|
41
40
|
if (!faq) {
|
|
42
41
|
throw new NotFoundException('FAQ not found');
|
|
@@ -48,18 +47,16 @@ export class FAQController {
|
|
|
48
47
|
@Post()
|
|
49
48
|
async create(
|
|
50
49
|
@Body() body: FAQDTO,
|
|
51
|
-
@Locale() locale: string,
|
|
52
50
|
) {
|
|
53
|
-
return this.faqService.create(body
|
|
51
|
+
return this.faqService.create(body)
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
@Patch(':id')
|
|
57
55
|
async update(
|
|
58
56
|
@Param('id', ParseIntPipe) id: number,
|
|
59
57
|
@Body() body: Partial<FAQDTO>,
|
|
60
|
-
@Locale() locale: string,
|
|
61
58
|
) {
|
|
62
|
-
return this.faqService.update(id, body
|
|
59
|
+
return this.faqService.update(id, body);
|
|
63
60
|
}
|
|
64
61
|
|
|
65
62
|
@Delete(':id')
|
package/src/faq.service.ts
CHANGED
|
@@ -34,8 +34,7 @@ export class FAQService {
|
|
|
34
34
|
ON fl.faq_id = f.id
|
|
35
35
|
WHERE fl.locale_id = ${localeId}
|
|
36
36
|
AND (
|
|
37
|
-
LOWER(
|
|
38
|
-
OR LOWER(fl.question) LIKE ${like}
|
|
37
|
+
LOWER(fl.question) LIKE ${like}
|
|
39
38
|
OR LOWER(fl.answer) LIKE ${like}
|
|
40
39
|
)
|
|
41
40
|
ORDER BY f.id DESC
|
|
@@ -95,42 +94,43 @@ export class FAQService {
|
|
|
95
94
|
};
|
|
96
95
|
}
|
|
97
96
|
|
|
98
|
-
async create(body: FAQDTO
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
throw new Error(`Locale ${locale} not found`);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const { question, answer } = body;
|
|
97
|
+
async create(body: FAQDTO) {
|
|
98
|
+
const { locale } = body;
|
|
99
|
+
|
|
105
100
|
const faq = await this.prisma.faq.create({
|
|
106
|
-
data: {
|
|
107
|
-
faq_locale: {
|
|
108
|
-
create: {
|
|
109
|
-
locale_id: localeRecord.id,
|
|
110
|
-
question,
|
|
111
|
-
answer,
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
include: {
|
|
116
|
-
faq_locale: true,
|
|
117
|
-
},
|
|
101
|
+
data: {},
|
|
118
102
|
});
|
|
119
103
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
104
|
+
if (locale) {
|
|
105
|
+
await Promise.all(
|
|
106
|
+
Object.entries(locale).map(async ([localeCode, localeData]) => {
|
|
107
|
+
const localeRecord = await this.localeService.getByCode(localeCode);
|
|
108
|
+
|
|
109
|
+
await this.prisma.faq_locale.create({
|
|
110
|
+
data: {
|
|
111
|
+
faq_id: faq.id,
|
|
112
|
+
locale_id: localeRecord.id,
|
|
113
|
+
question: localeData.question,
|
|
114
|
+
answer: localeData.answer,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
})
|
|
118
|
+
);
|
|
127
119
|
}
|
|
128
120
|
|
|
121
|
+
return this.getById(faq.id);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async getById(id: number) {
|
|
129
125
|
const faq = await this.prisma.faq.findUnique({
|
|
130
126
|
where: { id },
|
|
131
127
|
include: {
|
|
132
128
|
faq_locale: {
|
|
133
|
-
|
|
129
|
+
include: {
|
|
130
|
+
locale: {
|
|
131
|
+
select: { code: true },
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
134
|
},
|
|
135
135
|
},
|
|
136
136
|
});
|
|
@@ -139,32 +139,42 @@ export class FAQService {
|
|
|
139
139
|
return null;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
const localeData = faq.faq_locale.reduce((acc, item) => {
|
|
143
|
+
const localeCode = item.locale.code;
|
|
144
|
+
acc[localeCode] = {
|
|
145
|
+
question: item.question,
|
|
146
|
+
answer: item.answer,
|
|
147
|
+
};
|
|
148
|
+
return acc;
|
|
149
|
+
}, {} as Record<string, { question: string; answer: string }>);
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
...faq,
|
|
153
|
+
locale: localeData,
|
|
154
|
+
};
|
|
143
155
|
}
|
|
144
156
|
|
|
145
|
-
async update(id: number, body: Partial<FAQDTO
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
157
|
+
async update(id: number, body: Partial<FAQDTO>) {
|
|
158
|
+
const { locale } = body;
|
|
159
|
+
|
|
160
|
+
if (locale) {
|
|
161
|
+
await Promise.all(
|
|
162
|
+
Object.entries(locale).map(async ([localeCode, localeData]) => {
|
|
163
|
+
const localeRecord = await this.localeService.getByCode(localeCode);
|
|
164
|
+
await this.prisma.$executeRaw`
|
|
165
|
+
INSERT INTO faq_locale (faq_id, locale_id, question, answer)
|
|
166
|
+
VALUES (${id}, ${localeRecord.id}, ${localeData.question}, ${localeData.answer})
|
|
167
|
+
ON CONFLICT (faq_id, locale_id)
|
|
168
|
+
DO UPDATE SET
|
|
169
|
+
question = EXCLUDED.question,
|
|
170
|
+
answer = EXCLUDED.answer,
|
|
171
|
+
updated_at = NOW()
|
|
172
|
+
`;
|
|
173
|
+
})
|
|
174
|
+
);
|
|
149
175
|
}
|
|
150
176
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const updated = await this.prisma.faq_locale.updateMany({
|
|
154
|
-
where: {
|
|
155
|
-
faq_id: id,
|
|
156
|
-
locale_id: localeRecord.id,
|
|
157
|
-
},
|
|
158
|
-
data: {
|
|
159
|
-
...(question && { question }),
|
|
160
|
-
...(answer && { answer }),
|
|
161
|
-
},
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
return {
|
|
165
|
-
updated: updated.count,
|
|
166
|
-
message: updated.count > 0 ? 'FAQ updated successfully' : 'FAQ not found',
|
|
167
|
-
};
|
|
177
|
+
return this.getById(id);
|
|
168
178
|
}
|
|
169
179
|
|
|
170
180
|
async delete(id: number){
|