@hed-hog/faq 0.0.2

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.
@@ -0,0 +1,5 @@
1
+ export declare class FAQDTO {
2
+ question: string;
3
+ answer: string;
4
+ }
5
+ //# sourceMappingURL=faq.dto.d.ts.map
@@ -0,0 +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;IAIjB,MAAM,EAAE,MAAM,CAAC;CAClB"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FAQDTO = void 0;
13
+ const class_validator_1 = require("class-validator");
14
+ class FAQDTO {
15
+ }
16
+ exports.FAQDTO = FAQDTO;
17
+ __decorate([
18
+ (0, class_validator_1.IsString)(),
19
+ (0, class_validator_1.IsNotEmpty)(),
20
+ __metadata("design:type", String)
21
+ ], FAQDTO.prototype, "question", void 0);
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);
27
+ //# sourceMappingURL=faq.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"faq.dto.js","sourceRoot":"","sources":["../../src/dto/faq.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAuD;AAEvD,MAAa,MAAM;CAQlB;AARD,wBAQC;AALG;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;wCACI;AAIjB;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;sCACE"}
@@ -0,0 +1,29 @@
1
+ import { FAQDTO } from './dto/faq.dto';
2
+ import { FAQService } from './faq.service';
3
+ export declare class FAQController {
4
+ private readonly faqService;
5
+ constructor(faqService: FAQService);
6
+ list(paginationParams: any, locale: string): Promise<{
7
+ data: any[];
8
+ total: any;
9
+ page: number;
10
+ pageSize: any;
11
+ prev: number;
12
+ next: number;
13
+ lastPage: number;
14
+ }>;
15
+ getFAQStats(): Promise<{
16
+ total: any;
17
+ }>;
18
+ getById(id: number, locale: string): Promise<any>;
19
+ create(body: FAQDTO, locale: string): Promise<any>;
20
+ update(id: number, body: Partial<FAQDTO>, locale: string): Promise<{
21
+ updated: any;
22
+ message: string;
23
+ }>;
24
+ delete(id: number): Promise<{
25
+ deleted: boolean;
26
+ message: string;
27
+ }>;
28
+ }
29
+ //# sourceMappingURL=faq.controller.d.ts.map
@@ -0,0 +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,EAC3B,MAAM,EAAE,MAAM;IAYpB,MAAM,CACF,IAAI,EAAE,MAAM,EACV,MAAM,EAAE,MAAM;IAMpB,MAAM,CACiB,EAAE,EAAE,MAAM,EAC7B,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EACnB,MAAM,EAAE,MAAM;;;;IAMpB,MAAM,CAA4B,EAAE,EAAE,MAAM;;;;CAGnD"}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.FAQController = void 0;
16
+ const api_locale_1 = require("@hed-hog/api-locale");
17
+ const api_pagination_1 = require("@hed-hog/api-pagination");
18
+ const common_1 = require("@nestjs/common");
19
+ const faq_dto_1 = require("./dto/faq.dto");
20
+ const faq_service_1 = require("./faq.service");
21
+ let FAQController = class FAQController {
22
+ constructor(faqService) {
23
+ this.faqService = faqService;
24
+ }
25
+ async list(paginationParams, locale) {
26
+ return this.faqService.list(paginationParams, locale);
27
+ }
28
+ async getFAQStats() {
29
+ return this.faqService.getStats();
30
+ }
31
+ async getById(id, locale) {
32
+ const faq = await this.faqService.getById(id, locale);
33
+ if (!faq) {
34
+ throw new common_1.NotFoundException('FAQ not found');
35
+ }
36
+ return faq;
37
+ }
38
+ async create(body, locale) {
39
+ return this.faqService.create(body, locale);
40
+ }
41
+ async update(id, body, locale) {
42
+ return this.faqService.update(id, body, locale);
43
+ }
44
+ async delete(id) {
45
+ return this.faqService.delete(id);
46
+ }
47
+ };
48
+ exports.FAQController = FAQController;
49
+ __decorate([
50
+ (0, common_1.Get)(),
51
+ __param(0, (0, api_pagination_1.Pagination)()),
52
+ __param(1, (0, api_locale_1.Locale)()),
53
+ __metadata("design:type", Function),
54
+ __metadata("design:paramtypes", [Object, String]),
55
+ __metadata("design:returntype", Promise)
56
+ ], FAQController.prototype, "list", null);
57
+ __decorate([
58
+ (0, common_1.Get)('stats'),
59
+ __metadata("design:type", Function),
60
+ __metadata("design:paramtypes", []),
61
+ __metadata("design:returntype", Promise)
62
+ ], FAQController.prototype, "getFAQStats", null);
63
+ __decorate([
64
+ (0, common_1.Get)(':id'),
65
+ __param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
66
+ __param(1, (0, api_locale_1.Locale)()),
67
+ __metadata("design:type", Function),
68
+ __metadata("design:paramtypes", [Number, String]),
69
+ __metadata("design:returntype", Promise)
70
+ ], FAQController.prototype, "getById", null);
71
+ __decorate([
72
+ (0, common_1.Post)(),
73
+ __param(0, (0, common_1.Body)()),
74
+ __param(1, (0, api_locale_1.Locale)()),
75
+ __metadata("design:type", Function),
76
+ __metadata("design:paramtypes", [faq_dto_1.FAQDTO, String]),
77
+ __metadata("design:returntype", Promise)
78
+ ], FAQController.prototype, "create", null);
79
+ __decorate([
80
+ (0, common_1.Patch)(':id'),
81
+ __param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
82
+ __param(1, (0, common_1.Body)()),
83
+ __param(2, (0, api_locale_1.Locale)()),
84
+ __metadata("design:type", Function),
85
+ __metadata("design:paramtypes", [Number, Object, String]),
86
+ __metadata("design:returntype", Promise)
87
+ ], FAQController.prototype, "update", null);
88
+ __decorate([
89
+ (0, common_1.Delete)(':id'),
90
+ __param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
91
+ __metadata("design:type", Function),
92
+ __metadata("design:paramtypes", [Number]),
93
+ __metadata("design:returntype", Promise)
94
+ ], FAQController.prototype, "delete", null);
95
+ exports.FAQController = FAQController = __decorate([
96
+ (0, common_1.Controller)('faq'),
97
+ __metadata("design:paramtypes", [faq_service_1.FAQService])
98
+ ], FAQController);
99
+ //# sourceMappingURL=faq.controller.js.map
@@ -0,0 +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,EAC3B,MAAc;QAExB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAEtD,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,0BAAiB,CAAC,eAAe,CAAC,CAAC;QAC/C,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;IAGK,AAAN,KAAK,CAAC,MAAM,CACF,IAAY,EACV,MAAc;QAExB,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAC7C,CAAC;IAGK,A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@@
1
+ {"version":3,"file":"faq.module.d.ts","sourceRoot":"","sources":["../src/faq.module.ts"],"names":[],"mappings":"AAIA,qBAMa,SAAS;CAAG"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.FAQModule = void 0;
10
+ const api_locale_1 = require("@hed-hog/api-locale");
11
+ const common_1 = require("@nestjs/common");
12
+ const faq_controller_1 = require("./faq.controller");
13
+ const faq_service_1 = require("./faq.service");
14
+ let FAQModule = class FAQModule {
15
+ };
16
+ exports.FAQModule = FAQModule;
17
+ exports.FAQModule = FAQModule = __decorate([
18
+ (0, common_1.Module)({
19
+ imports: [(0, common_1.forwardRef)(() => api_locale_1.LocaleModule)],
20
+ controllers: [faq_controller_1.FAQController],
21
+ providers: [faq_service_1.FAQService],
22
+ exports: [(0, common_1.forwardRef)(() => faq_service_1.FAQService)],
23
+ })
24
+ ], FAQModule);
25
+ //# sourceMappingURL=faq.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"faq.module.js","sourceRoot":"","sources":["../src/faq.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAmD;AACnD,2CAAoD;AACpD,qDAAiD;AACjD,+CAA2C;AAOpC,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,8BAAS;oBAAT,SAAS;IANrB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,yBAAY,CAAC,CAAC;QACzC,WAAW,EAAE,CAAC,8BAAa,CAAC;QAC5B,SAAS,EAAE,CAAC,wBAAU,CAAC;QACvB,OAAO,EAAE,CAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,wBAAU,CAAC,CAAC;KACxC,CAAC;GACW,SAAS,CAAG"}
@@ -0,0 +1,31 @@
1
+ import { LocaleService } from '@hed-hog/api-locale';
2
+ import { PrismaService } from '@hed-hog/api-prisma';
3
+ import { FAQDTO } from './dto/faq.dto';
4
+ export declare class FAQService {
5
+ private readonly prisma;
6
+ private readonly localeService;
7
+ constructor(prisma: PrismaService, localeService: LocaleService);
8
+ list(paginationParams: any, locale: string): Promise<{
9
+ data: any[];
10
+ total: any;
11
+ page: number;
12
+ pageSize: any;
13
+ prev: number;
14
+ next: number;
15
+ lastPage: number;
16
+ }>;
17
+ getStats(): Promise<{
18
+ total: any;
19
+ }>;
20
+ create(body: FAQDTO, locale: string): Promise<any>;
21
+ getById(id: number, locale: string): Promise<any>;
22
+ update(id: number, body: Partial<FAQDTO>, locale: string): Promise<{
23
+ updated: any;
24
+ message: string;
25
+ }>;
26
+ delete(id: number): Promise<{
27
+ deleted: boolean;
28
+ message: string;
29
+ }>;
30
+ }
31
+ //# sourceMappingURL=faq.service.d.ts.map
@@ -0,0 +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;cAoEzB,GAAG,EAAE;;;;;;;;IAUjB,QAAQ;;;IAOR,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAyBnC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAsBlC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM;;;;IAyBxD,MAAM,CAAC,EAAE,EAAE,MAAM;;;;CAqBxB"}
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.FAQService = void 0;
16
+ const api_locale_1 = require("@hed-hog/api-locale");
17
+ const api_prisma_1 = require("@hed-hog/api-prisma");
18
+ const common_1 = require("@nestjs/common");
19
+ let FAQService = class FAQService {
20
+ constructor(prisma, localeService) {
21
+ this.prisma = prisma;
22
+ this.localeService = localeService;
23
+ }
24
+ async list(paginationParams, locale) {
25
+ var _a;
26
+ const localeRecord = await this.localeService.getByCode(locale);
27
+ if (!localeRecord) {
28
+ throw new Error(`Locale ${locale} not found`);
29
+ }
30
+ const localeId = localeRecord.id;
31
+ const searchRaw = ((_a = paginationParams.search) !== null && _a !== void 0 ? _a : '').toString().trim();
32
+ const hasSearch = searchRaw.length > 0;
33
+ const like = `%${searchRaw.toLowerCase()}%`;
34
+ const rowsQuery = hasSearch
35
+ ? this.prisma.$queryRaw `
36
+ SELECT
37
+ f.id AS faq_id,
38
+ fl.locale_id,
39
+ fl.question,
40
+ fl.answer
41
+ FROM faq AS f
42
+ JOIN faq_locale AS fl
43
+ ON fl.faq_id = f.id
44
+ WHERE fl.locale_id = ${localeId}
45
+ AND (
46
+ LOWER(f.slug) LIKE ${like}
47
+ OR LOWER(fl.question) LIKE ${like}
48
+ OR LOWER(fl.answer) LIKE ${like}
49
+ )
50
+ ORDER BY f.id DESC
51
+ LIMIT ${paginationParams.take}
52
+ OFFSET ${paginationParams.skip}
53
+ `
54
+ : this.prisma.$queryRaw `
55
+ SELECT
56
+ f.id AS faq_id,
57
+ fl.locale_id,
58
+ fl.question,
59
+ fl.answer
60
+ FROM faq AS f
61
+ JOIN faq_locale AS fl
62
+ ON fl.faq_id = f.id
63
+ WHERE fl.locale_id = ${localeId}
64
+ ORDER BY f.id DESC
65
+ LIMIT ${paginationParams.take}
66
+ OFFSET ${paginationParams.skip}
67
+ `;
68
+ const countQuery = this.prisma.faq.count({
69
+ where: Object.assign({ faq_locale: { some: { locale_id: localeId } } }, (hasSearch && {
70
+ OR: [
71
+ { slug: { contains: searchRaw, mode: 'insensitive' } },
72
+ { faq_locale: { some: { locale_id: localeId, question: { contains: searchRaw, mode: 'insensitive' } } } },
73
+ { faq_locale: { some: { locale_id: localeId, answer: { contains: searchRaw, mode: 'insensitive' } } } },
74
+ ],
75
+ })),
76
+ });
77
+ const [rows, total] = await Promise.all([rowsQuery, countQuery]);
78
+ const pageSize = paginationParams.take;
79
+ const page = Math.floor(paginationParams.skip / pageSize) + 1;
80
+ const lastPage = Math.max(1, Math.ceil(total / pageSize));
81
+ const prev = page > 1 ? page - 1 : null;
82
+ const next = page < lastPage ? page + 1 : null;
83
+ return {
84
+ data: rows,
85
+ total,
86
+ page,
87
+ pageSize,
88
+ prev,
89
+ next,
90
+ lastPage,
91
+ };
92
+ }
93
+ async getStats() {
94
+ const [total] = await Promise.all([this.prisma.faq.count()]);
95
+ return {
96
+ total,
97
+ };
98
+ }
99
+ async create(body, locale) {
100
+ const localeRecord = await this.localeService.getByCode(locale);
101
+ if (!localeRecord) {
102
+ throw new Error(`Locale ${locale} not found`);
103
+ }
104
+ const { question, answer } = body;
105
+ 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
+ },
118
+ });
119
+ return faq;
120
+ }
121
+ async getById(id, locale) {
122
+ const localeRecord = await this.localeService.getByCode(locale);
123
+ if (!localeRecord) {
124
+ throw new Error(`Locale ${locale} not found`);
125
+ }
126
+ const faq = await this.prisma.faq.findUnique({
127
+ where: { id },
128
+ include: {
129
+ faq_locale: {
130
+ where: { locale_id: localeRecord.id },
131
+ },
132
+ },
133
+ });
134
+ if (!faq) {
135
+ return null;
136
+ }
137
+ return faq;
138
+ }
139
+ async update(id, body, locale) {
140
+ const localeRecord = await this.localeService.getByCode(locale);
141
+ if (!localeRecord) {
142
+ throw new Error(`Locale ${locale} not found`);
143
+ }
144
+ const { question, answer } = body;
145
+ const updated = await this.prisma.faq_locale.updateMany({
146
+ where: {
147
+ faq_id: id,
148
+ locale_id: localeRecord.id,
149
+ },
150
+ data: Object.assign(Object.assign({}, (question && { question })), (answer && { answer })),
151
+ });
152
+ return {
153
+ updated: updated.count,
154
+ message: updated.count > 0 ? 'FAQ updated successfully' : 'FAQ not found',
155
+ };
156
+ }
157
+ async delete(id) {
158
+ const faq = await this.prisma.faq.findUnique({
159
+ where: { id },
160
+ });
161
+ if (!faq) {
162
+ return {
163
+ deleted: false,
164
+ message: 'FAQ not found',
165
+ };
166
+ }
167
+ await this.prisma.faq.delete({
168
+ where: { id },
169
+ });
170
+ return {
171
+ deleted: true,
172
+ message: 'FAQ deleted successfully',
173
+ };
174
+ }
175
+ };
176
+ exports.FAQService = FAQService;
177
+ exports.FAQService = FAQService = __decorate([
178
+ (0, common_1.Injectable)(),
179
+ __param(1, (0, common_1.Inject)((0, common_1.forwardRef)(() => api_locale_1.LocaleService))),
180
+ __metadata("design:paramtypes", [api_prisma_1.PrismaService,
181
+ api_locale_1.LocaleService])
182
+ ], FAQService);
183
+ //# sourceMappingURL=faq.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"faq.service.js","sourceRoot":"","sources":["../src/faq.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAAoD;AACpD,oDAAoD;AACpD,2CAAgE;AAIzD,IAAM,UAAU,GAAhB,MAAM,UAAU;IACrB,YACmB,MAAqB,EAErB,aAA4B;QAF5B,WAAM,GAAN,MAAM,CAAe;QAErB,kBAAa,GAAb,aAAa,CAAe;IAC5C,CAAC;IAEJ,KAAK,CAAC,IAAI,CAAC,gBAAgB,EAAE,MAAc;;QACzC,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAChE,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,UAAU,MAAM,YAAY,CAAC,CAAC;QAChD,CAAC;QACD,MAAM,QAAQ,GAAG,YAAY,CAAC,EAAE,CAAC;QAEjC,MAAM,SAAS,GAAG,CAAC,MAAA,gBAAgB,CAAC,MAAM,mCAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;QACpE,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QACvC,MAAM,IAAI,GAAG,IAAI,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC;QAE5C,MAAM,SAAS,GAAG,SA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AAE,MAAM,EAAE,CAAC,CAC1B;SACF,CAAC,CAAC;QAEH,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,KAAK;YACtB,OAAO,EAAE,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,eAAe;SAC1E,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC;YAC3C,KAAK,EAAE,EAAE,EAAE,EAAE;SACd,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,eAAe;aACzB,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,0BAA0B;SACpC,CAAC;IACJ,CAAC;CACF,CAAA;AAzLY,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,CAyLtB"}
@@ -0,0 +1,2 @@
1
+ export * from './faq.module';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./faq.module"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B"}
@@ -0,0 +1,36 @@
1
+ - url: /faq
2
+ method: GET
3
+ relations:
4
+ role:
5
+ - where:
6
+ slug: admin
7
+ - url: /faq
8
+ method: POST
9
+ relations:
10
+ role:
11
+ - where:
12
+ slug: admin
13
+ - url: /faq/stats
14
+ method: GET
15
+ relations:
16
+ role:
17
+ - where:
18
+ slug: admin
19
+ - url: /faq/:id
20
+ method: GET
21
+ relations:
22
+ role:
23
+ - where:
24
+ slug: admin
25
+ - url: /faq/:id
26
+ method: PATCH
27
+ relations:
28
+ role:
29
+ - where:
30
+ slug: admin
31
+ - url: /faq
32
+ method: DELETE
33
+ relations:
34
+ role:
35
+ - where:
36
+ slug: admin
@@ -0,0 +1,15 @@
1
+ columns:
2
+ - type: pk
3
+ - name: question
4
+ type: locale_varchar
5
+ length: 255
6
+ locale:
7
+ en: Question
8
+ pt: Pergunta
9
+ - name: answer
10
+ type: locale_text
11
+ locale:
12
+ en: Answer
13
+ pt: Resposta
14
+ - type: created_at
15
+ - type: updated_at
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@hed-hog/faq",
3
+ "version": "0.0.2",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "dependencies": {
7
+ "@nestjs/common": "*",
8
+ "@nestjs/config": "^4.0.2",
9
+ "@nestjs/core": "^11",
10
+ "@nestjs/jwt": "^11",
11
+ "@nestjs/mapped-types": "*",
12
+ "@hed-hog/admin": "0.0.129",
13
+ "@hed-hog/api": "0.0.3",
14
+ "@hed-hog/api-locale": "0.0.10",
15
+ "@hed-hog/api-pagination": "0.0.3",
16
+ "@hed-hog/api-prisma": "0.0.4"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.js"
22
+ },
23
+ "./package.json": "./package.json"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "src",
28
+ "hedhog"
29
+ ],
30
+ "scripts": {
31
+ "lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
32
+ "prebuild": "npx ts-node ../../scripts/build-dependencies.ts libraries/faq",
33
+ "build": "tsc --project tsconfig.production.json",
34
+ "patch": "npx ts-node ../../scripts/patch.ts libraries/faq",
35
+ "prod": "pnpm run patch && pnpm run build && pnpm publish --access public --no-git-checks"
36
+ }
37
+ }
@@ -0,0 +1,11 @@
1
+ import { IsNotEmpty, IsString } from "class-validator";
2
+
3
+ export class FAQDTO{
4
+ @IsString()
5
+ @IsNotEmpty()
6
+ question: string;
7
+
8
+ @IsString()
9
+ @IsNotEmpty()
10
+ answer: string;
11
+ }
@@ -0,0 +1,69 @@
1
+ import { Locale } from '@hed-hog/api-locale';
2
+ import { Pagination } from '@hed-hog/api-pagination';
3
+ import {
4
+ Body,
5
+ Controller,
6
+ Delete,
7
+ Get,
8
+ NotFoundException,
9
+ Param,
10
+ ParseIntPipe,
11
+ Patch,
12
+ Post,
13
+ } from '@nestjs/common';
14
+ import { FAQDTO } from './dto/faq.dto';
15
+ import { FAQService } from './faq.service';
16
+
17
+ @Controller('faq')
18
+ export class FAQController {
19
+ constructor(private readonly faqService: FAQService) { }
20
+
21
+ @Get()
22
+ async list(
23
+ @Pagination() paginationParams,
24
+ @Locale() locale: string,
25
+ ) {
26
+ return this.faqService.list(paginationParams, locale)
27
+ }
28
+
29
+ @Get('stats')
30
+ async getFAQStats() {
31
+ return this.faqService.getStats()
32
+ }
33
+
34
+ @Get(':id')
35
+ async getById(
36
+ @Param('id', ParseIntPipe) id: number,
37
+ @Locale() locale: string,
38
+ ) {
39
+ const faq = await this.faqService.getById(id, locale);
40
+
41
+ if (!faq) {
42
+ throw new NotFoundException('FAQ not found');
43
+ }
44
+
45
+ return faq;
46
+ }
47
+
48
+ @Post()
49
+ async create(
50
+ @Body() body: FAQDTO,
51
+ @Locale() locale: string,
52
+ ) {
53
+ return this.faqService.create(body, locale)
54
+ }
55
+
56
+ @Patch(':id')
57
+ async update(
58
+ @Param('id', ParseIntPipe) id: number,
59
+ @Body() body: Partial<FAQDTO>,
60
+ @Locale() locale: string,
61
+ ) {
62
+ return this.faqService.update(id, body, locale);
63
+ }
64
+
65
+ @Delete(':id')
66
+ async delete(@Param('id', ParseIntPipe) id: number) {
67
+ return this.faqService.delete(id);
68
+ }
69
+ }
@@ -0,0 +1,11 @@
1
+ import { LocaleModule } from '@hed-hog/api-locale';
2
+ import { forwardRef, Module } from '@nestjs/common';
3
+ import { FAQController } from './faq.controller';
4
+ import { FAQService } from './faq.service';
5
+ @Module({
6
+ imports: [forwardRef(() => LocaleModule)],
7
+ controllers: [FAQController],
8
+ providers: [FAQService],
9
+ exports: [forwardRef(() => FAQService)],
10
+ })
11
+ export class FAQModule {}
@@ -0,0 +1,192 @@
1
+ import { LocaleService } from '@hed-hog/api-locale';
2
+ import { PrismaService } from '@hed-hog/api-prisma';
3
+ import { Inject, Injectable, forwardRef } from '@nestjs/common';
4
+ import { FAQDTO } from './dto/faq.dto';
5
+
6
+ @Injectable()
7
+ export class FAQService {
8
+ constructor(
9
+ private readonly prisma: PrismaService,
10
+ @Inject(forwardRef(() => LocaleService))
11
+ private readonly localeService: LocaleService,
12
+ ) {}
13
+
14
+ async list(paginationParams, locale: string) {
15
+ const localeRecord = await this.localeService.getByCode(locale);
16
+ if (!localeRecord) {
17
+ throw new Error(`Locale ${locale} not found`);
18
+ }
19
+ const localeId = localeRecord.id;
20
+
21
+ const searchRaw = (paginationParams.search ?? '').toString().trim();
22
+ const hasSearch = searchRaw.length > 0;
23
+ const like = `%${searchRaw.toLowerCase()}%`;
24
+
25
+ const rowsQuery = hasSearch
26
+ ? this.prisma.$queryRaw`
27
+ SELECT
28
+ f.id AS faq_id,
29
+ fl.locale_id,
30
+ fl.question,
31
+ fl.answer
32
+ FROM faq AS f
33
+ JOIN faq_locale AS fl
34
+ ON fl.faq_id = f.id
35
+ WHERE fl.locale_id = ${localeId}
36
+ AND (
37
+ LOWER(f.slug) LIKE ${like}
38
+ OR LOWER(fl.question) LIKE ${like}
39
+ OR LOWER(fl.answer) LIKE ${like}
40
+ )
41
+ ORDER BY f.id DESC
42
+ LIMIT ${paginationParams.take}
43
+ OFFSET ${paginationParams.skip}
44
+ `
45
+ : this.prisma.$queryRaw`
46
+ SELECT
47
+ f.id AS faq_id,
48
+ fl.locale_id,
49
+ fl.question,
50
+ fl.answer
51
+ FROM faq AS f
52
+ JOIN faq_locale AS fl
53
+ ON fl.faq_id = f.id
54
+ WHERE fl.locale_id = ${localeId}
55
+ ORDER BY f.id DESC
56
+ LIMIT ${paginationParams.take}
57
+ OFFSET ${paginationParams.skip}
58
+ `;
59
+
60
+ const countQuery = this.prisma.faq.count({
61
+ where: {
62
+ faq_locale: { some: { locale_id: localeId } },
63
+ ...(hasSearch && {
64
+ OR: [
65
+ { slug: { contains: searchRaw, mode: 'insensitive' } },
66
+ { faq_locale: { some: { locale_id: localeId, question: { contains: searchRaw, mode: 'insensitive' } } } },
67
+ { faq_locale: { some: { locale_id: localeId, answer: { contains: searchRaw, mode: 'insensitive' } } } },
68
+ ],
69
+ }),
70
+ },
71
+ });
72
+
73
+ const [rows, total] = await Promise.all([rowsQuery, countQuery]);
74
+
75
+ const pageSize = paginationParams.take;
76
+ const page = Math.floor(paginationParams.skip / pageSize) + 1;
77
+ const lastPage = Math.max(1, Math.ceil(total / pageSize));
78
+ const prev = page > 1 ? page - 1 : null;
79
+ const next = page < lastPage ? page + 1 : null;
80
+
81
+ return {
82
+ data: rows as any[],
83
+ total,
84
+ page,
85
+ pageSize,
86
+ prev,
87
+ next,
88
+ lastPage,
89
+ };
90
+ }
91
+
92
+ async getStats(){
93
+ const [total] = await Promise.all([this.prisma.faq.count()]);
94
+ return {
95
+ total,
96
+ };
97
+ }
98
+
99
+ async create(body: FAQDTO, locale: string){
100
+ const localeRecord = await this.localeService.getByCode(locale);
101
+ if (!localeRecord) {
102
+ throw new Error(`Locale ${locale} not found`);
103
+ }
104
+
105
+ const { question, answer } = body;
106
+ const faq = await this.prisma.faq.create({
107
+ data: {
108
+ faq_locale: {
109
+ create: {
110
+ locale_id: localeRecord.id,
111
+ question,
112
+ answer,
113
+ },
114
+ },
115
+ },
116
+ include: {
117
+ faq_locale: true,
118
+ },
119
+ });
120
+
121
+ return faq;
122
+ }
123
+
124
+ async getById(id: number, locale: string){
125
+ const localeRecord = await this.localeService.getByCode(locale);
126
+ if (!localeRecord) {
127
+ throw new Error(`Locale ${locale} not found`);
128
+ }
129
+
130
+ const faq = await this.prisma.faq.findUnique({
131
+ where: { id },
132
+ include: {
133
+ faq_locale: {
134
+ where: { locale_id: localeRecord.id },
135
+ },
136
+ },
137
+ });
138
+
139
+ if (!faq) {
140
+ return null;
141
+ }
142
+
143
+ return faq;
144
+ }
145
+
146
+ async update(id: number, body: Partial<FAQDTO>, locale: string){
147
+ const localeRecord = await this.localeService.getByCode(locale);
148
+ if (!localeRecord) {
149
+ throw new Error(`Locale ${locale} not found`);
150
+ }
151
+
152
+ const { question, answer } = body;
153
+
154
+ const updated = await this.prisma.faq_locale.updateMany({
155
+ where: {
156
+ faq_id: id,
157
+ locale_id: localeRecord.id,
158
+ },
159
+ data: {
160
+ ...(question && { question }),
161
+ ...(answer && { answer }),
162
+ },
163
+ });
164
+
165
+ return {
166
+ updated: updated.count,
167
+ message: updated.count > 0 ? 'FAQ updated successfully' : 'FAQ not found',
168
+ };
169
+ }
170
+
171
+ async delete(id: number){
172
+ const faq = await this.prisma.faq.findUnique({
173
+ where: { id },
174
+ });
175
+
176
+ if (!faq) {
177
+ return {
178
+ deleted: false,
179
+ message: 'FAQ not found',
180
+ };
181
+ }
182
+
183
+ await this.prisma.faq.delete({
184
+ where: { id },
185
+ });
186
+
187
+ return {
188
+ deleted: true,
189
+ message: 'FAQ deleted successfully',
190
+ };
191
+ }
192
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './faq.module';
2
+