@hed-hog/content 0.0.0

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,28 @@
1
+ import { PaginationDTO } from "@hed-hog/api-pagination";
2
+ import { ContentService } from "./content.service";
3
+ import { ContentCreateDTO } from "./dto/content-create.dto";
4
+ import { ContentUpdateDTO } from "./dto/content-update.dto";
5
+ export declare class ContentController {
6
+ private readonly contentService;
7
+ constructor(contentService: ContentService);
8
+ getContentStats(): Promise<{
9
+ total: any;
10
+ totalPublished: any;
11
+ totalDraft: any;
12
+ totalEnabledLanguages: number;
13
+ }>;
14
+ getContent(id: number): Promise<any>;
15
+ getContents(locale: string, paginationParams: PaginationDTO, query: any): Promise<{
16
+ total: any;
17
+ lastPage: number;
18
+ page: number;
19
+ pageSize: number;
20
+ prev: number;
21
+ next: number;
22
+ data: any;
23
+ }>;
24
+ deleteContent(locale: string, id: number): Promise<any>;
25
+ createContent(localeStr: string, { slug, status, locale }: ContentCreateDTO): Promise<any>;
26
+ updateContent(localeStr: string, id: number, { locale, slug, status }: ContentUpdateDTO): Promise<any>;
27
+ }
28
+ //# sourceMappingURL=content.controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.controller.d.ts","sourceRoot":"","sources":["../src/content.controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAYpE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,qBACa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAAd,cAAc,EAAE,cAAc;IAI3C,eAAe;;;;;;IAKf,UAAU,CAA4B,EAAE,EAAE,MAAM;IAKhD,WAAW,CAAW,MAAM,EAAE,MAAM,EAAgB,gBAAgB,EAAE,aAAa,EAAW,KAAK,EAAE,GAAG;;;;;;;;;IAKxG,aAAa,CAAW,MAAM,EAAE,MAAM,EAA6B,EAAE,EAAE,MAAM;IAK7E,aAAa,CAAW,SAAS,EAAE,MAAM,EAAU,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,gBAAgB;IAS7F,aAAa,CACP,SAAS,EAAE,MAAM,EACA,EAAE,EAAE,MAAM,EAC7B,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,gBAAgB;CAQrD"}
@@ -0,0 +1,105 @@
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.ContentController = 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 content_service_1 = require("./content.service");
20
+ const content_create_dto_1 = require("./dto/content-create.dto");
21
+ const content_update_dto_1 = require("./dto/content-update.dto");
22
+ let ContentController = class ContentController {
23
+ constructor(contentService) {
24
+ this.contentService = contentService;
25
+ }
26
+ async getContentStats() {
27
+ return this.contentService.getContentStats();
28
+ }
29
+ async getContent(id) {
30
+ return this.contentService.getContent(id);
31
+ }
32
+ async getContents(locale, paginationParams, query) {
33
+ return this.contentService.getContents(locale, paginationParams, query);
34
+ }
35
+ async deleteContent(locale, id) {
36
+ return this.contentService.deleteContent(locale, id);
37
+ }
38
+ async createContent(localeStr, { slug, status, locale }) {
39
+ return this.contentService.createContent(localeStr, {
40
+ slug,
41
+ status,
42
+ locale,
43
+ });
44
+ }
45
+ async updateContent(localeStr, id, { locale, slug, status }) {
46
+ return this.contentService.updateContent(localeStr, id, {
47
+ locale,
48
+ slug,
49
+ status,
50
+ });
51
+ }
52
+ };
53
+ exports.ContentController = ContentController;
54
+ __decorate([
55
+ (0, common_1.Get)('stats'),
56
+ __metadata("design:type", Function),
57
+ __metadata("design:paramtypes", []),
58
+ __metadata("design:returntype", Promise)
59
+ ], ContentController.prototype, "getContentStats", null);
60
+ __decorate([
61
+ (0, common_1.Get)(':id'),
62
+ __param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
63
+ __metadata("design:type", Function),
64
+ __metadata("design:paramtypes", [Number]),
65
+ __metadata("design:returntype", Promise)
66
+ ], ContentController.prototype, "getContent", null);
67
+ __decorate([
68
+ (0, common_1.Get)(),
69
+ __param(0, (0, api_locale_1.Locale)()),
70
+ __param(1, (0, api_pagination_1.Pagination)()),
71
+ __param(2, (0, common_1.Query)()),
72
+ __metadata("design:type", Function),
73
+ __metadata("design:paramtypes", [String, api_pagination_1.PaginationDTO, Object]),
74
+ __metadata("design:returntype", Promise)
75
+ ], ContentController.prototype, "getContents", null);
76
+ __decorate([
77
+ (0, common_1.Delete)(':id'),
78
+ __param(0, (0, api_locale_1.Locale)()),
79
+ __param(1, (0, common_1.Param)('id', common_1.ParseIntPipe)),
80
+ __metadata("design:type", Function),
81
+ __metadata("design:paramtypes", [String, Number]),
82
+ __metadata("design:returntype", Promise)
83
+ ], ContentController.prototype, "deleteContent", null);
84
+ __decorate([
85
+ (0, common_1.Post)(),
86
+ __param(0, (0, api_locale_1.Locale)()),
87
+ __param(1, (0, common_1.Body)()),
88
+ __metadata("design:type", Function),
89
+ __metadata("design:paramtypes", [String, content_create_dto_1.ContentCreateDTO]),
90
+ __metadata("design:returntype", Promise)
91
+ ], ContentController.prototype, "createContent", null);
92
+ __decorate([
93
+ (0, common_1.Patch)(':id'),
94
+ __param(0, (0, api_locale_1.Locale)()),
95
+ __param(1, (0, common_1.Param)('id', common_1.ParseIntPipe)),
96
+ __param(2, (0, common_1.Body)()),
97
+ __metadata("design:type", Function),
98
+ __metadata("design:paramtypes", [String, Number, content_update_dto_1.ContentUpdateDTO]),
99
+ __metadata("design:returntype", Promise)
100
+ ], ContentController.prototype, "updateContent", null);
101
+ exports.ContentController = ContentController = __decorate([
102
+ (0, common_1.Controller)('content'),
103
+ __metadata("design:paramtypes", [content_service_1.ContentService])
104
+ ], ContentController);
105
+ //# sourceMappingURL=content.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.controller.js","sourceRoot":"","sources":["../src/content.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAA6C;AAC7C,4DAAoE;AACpE,2CAUwB;AACxB,uDAAmD;AACnD,iEAA4D;AAC5D,iEAA4D;AAGrD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,YACmB,cAA8B;QAA9B,mBAAc,GAAd,cAAc,CAAgB;IAC9C,CAAC;IAGE,AAAN,KAAK,CAAC,eAAe;QACnB,OAAO,IAAI,CAAC,cAAc,CAAC,eAAe,EAAE,CAAC;IAC/C,CAAC;IAGK,AAAN,KAAK,CAAC,UAAU,CAA4B,EAAU;QACpD,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;IAGK,AAAN,KAAK,CAAC,WAAW,CAAW,MAAc,EAAgB,gBAA+B,EAAW,KAAU;QAC5G,OAAO,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,MAAM,EAAE,gBAAgB,EAAE,KAAK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,CAAA;;6CAA2B,qCAAgB;;sDAMlG;AAGK;IADL,IAAA,cAAK,EAAC,KAAK,CAAC;IAEV,WAAA,IAAA,mBAAM,GAAE,CAAA;IACR,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;IACzB,WAAA,IAAA,aAAI,GAAE,CAAA;;qDAA2B,qCAAgB;;sDAOnD;4BA7CU,iBAAiB;IAD7B,IAAA,mBAAU,EAAC,SAAS,CAAC;qCAGe,gCAAc;GAFtC,iBAAiB,CA8C7B"}
@@ -0,0 +1,3 @@
1
+ export declare class ContentModule {
2
+ }
3
+ //# sourceMappingURL=content.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.module.d.ts","sourceRoot":"","sources":["../src/content.module.ts"],"names":[],"mappings":"AAOA,qBAUa,aAAa;CAAG"}
@@ -0,0 +1,31 @@
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.ContentModule = void 0;
10
+ const api_locale_1 = require("@hed-hog/api-locale");
11
+ const api_pagination_1 = require("@hed-hog/api-pagination");
12
+ const api_prisma_1 = require("@hed-hog/api-prisma");
13
+ const common_1 = require("@nestjs/common");
14
+ const content_controller_1 = require("./content.controller");
15
+ const content_service_1 = require("./content.service");
16
+ let ContentModule = class ContentModule {
17
+ };
18
+ exports.ContentModule = ContentModule;
19
+ exports.ContentModule = ContentModule = __decorate([
20
+ (0, common_1.Module)({
21
+ imports: [
22
+ (0, common_1.forwardRef)(() => api_locale_1.LocaleModule),
23
+ (0, common_1.forwardRef)(() => api_prisma_1.PrismaModule),
24
+ (0, common_1.forwardRef)(() => api_pagination_1.PaginationModule),
25
+ ],
26
+ controllers: [content_controller_1.ContentController],
27
+ providers: [content_service_1.ContentService],
28
+ exports: [(0, common_1.forwardRef)(() => content_service_1.ContentService)],
29
+ })
30
+ ], ContentModule);
31
+ //# sourceMappingURL=content.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.module.js","sourceRoot":"","sources":["../src/content.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAmD;AACnD,4DAA2D;AAC3D,oDAAmD;AACnD,2CAAoD;AACpD,6DAAyD;AACzD,uDAAmD;AAY5C,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,sCAAa;wBAAb,aAAa;IAVzB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,yBAAY,CAAC;YAC9B,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,yBAAY,CAAC;YAC9B,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,iCAAgB,CAAC;SACnC;QACD,WAAW,EAAE,CAAC,sCAAiB,CAAC;QAChC,SAAS,EAAE,CAAC,gCAAc,CAAC;QAC3B,OAAO,EAAE,CAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,gCAAc,CAAC,CAAC;KAC5C,CAAC;GACW,aAAa,CAAG"}
@@ -0,0 +1,31 @@
1
+ import { LocaleService } from '@hed-hog/api-locale';
2
+ import { PaginationDTO, PaginationService } from '@hed-hog/api-pagination';
3
+ import { PrismaService } from '@hed-hog/api-prisma';
4
+ import { ContentCreateDTO } from './dto/content-create.dto';
5
+ import { ContentUpdateDTO } from './dto/content-update.dto';
6
+ export declare class ContentService {
7
+ private readonly prisma;
8
+ private readonly pagination;
9
+ private readonly locale;
10
+ constructor(prisma: PrismaService, pagination: PaginationService, locale: LocaleService);
11
+ getContentStats(): Promise<{
12
+ total: any;
13
+ totalPublished: any;
14
+ totalDraft: any;
15
+ totalEnabledLanguages: number;
16
+ }>;
17
+ getContent(id: number): Promise<any>;
18
+ getContents(locale: string, paginationParams: PaginationDTO, query: any): Promise<{
19
+ total: any;
20
+ lastPage: number;
21
+ page: number;
22
+ pageSize: number;
23
+ prev: number;
24
+ next: number;
25
+ data: any;
26
+ }>;
27
+ deleteContent(locale: string, id: number): Promise<any>;
28
+ createContent(localeStr: string, { locale, slug, status }: ContentCreateDTO): Promise<any>;
29
+ updateContent(localeStr: string, id: number, { locale, slug, status }: ContentUpdateDTO): Promise<any>;
30
+ }
31
+ //# sourceMappingURL=content.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.service.d.ts","sourceRoot":"","sources":["../src/content.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,qBACa,cAAc;IAEvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAFN,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,iBAAiB,EAC7B,MAAM,EAAE,aAAa;IAGlC,eAAe;;;;;;IAyBf,UAAU,CAAC,EAAE,EAAE,MAAM;IASrB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG;;;;;;;;;IAqCvE,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAcxC,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,gBAAgB;IAuC3E,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,gBAAgB;CAmD9F"}
@@ -0,0 +1,173 @@
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.ContentService = void 0;
13
+ const api_1 = require("@hed-hog/api");
14
+ const api_locale_1 = require("@hed-hog/api-locale");
15
+ const api_pagination_1 = require("@hed-hog/api-pagination");
16
+ const api_prisma_1 = require("@hed-hog/api-prisma");
17
+ const common_1 = require("@nestjs/common");
18
+ let ContentService = class ContentService {
19
+ constructor(prisma, pagination, locale) {
20
+ this.prisma = prisma;
21
+ this.pagination = pagination;
22
+ this.locale = locale;
23
+ }
24
+ async getContentStats() {
25
+ const statuses = ['published', 'draft'];
26
+ const [total, counts, enabledLanguagesCount] = await Promise.all([
27
+ this.prisma.content.count({}),
28
+ Promise.all(statuses.map((status) => this.prisma.content.count({
29
+ where: { status: status },
30
+ }))),
31
+ this.prisma.locale.count({
32
+ where: { enabled: true },
33
+ }),
34
+ ]);
35
+ return {
36
+ total,
37
+ totalPublished: counts[0],
38
+ totalDraft: counts[1],
39
+ totalEnabledLanguages: enabledLanguagesCount,
40
+ };
41
+ }
42
+ async getContent(id) {
43
+ return (0, api_1.itemTranslations)('content_locale', await this.locale.getModelWithLocaleWhere('content', {
44
+ id: Number(id),
45
+ }));
46
+ }
47
+ async getContents(locale, paginationParams, query) {
48
+ const localeRecord = await this.locale.getByCode(locale);
49
+ if (!localeRecord) {
50
+ throw new common_1.BadRequestException((0, api_locale_1.getLocaleText)('localeNotFound', locale, `Locale ${locale} not found`).replace('{{locale}}', locale));
51
+ }
52
+ const fields = ['slug'];
53
+ const OR = this.prisma.createInsensitiveSearch(fields, paginationParams);
54
+ const AND = [];
55
+ if (query.status && query.status !== 'all') {
56
+ AND.push({
57
+ status: query.status,
58
+ });
59
+ }
60
+ const result = await this.pagination.paginate(this.prisma.content, paginationParams, {
61
+ where: {
62
+ OR,
63
+ AND,
64
+ },
65
+ include: {
66
+ content_locale: {
67
+ where: {
68
+ locale_id: localeRecord.id,
69
+ },
70
+ },
71
+ },
72
+ }, locale);
73
+ result.data = result.data.map((content) => (0, api_1.itemTranslations)('content_locale', content));
74
+ return result;
75
+ }
76
+ async deleteContent(locale, id) {
77
+ const content = await this.prisma.content.findUnique({
78
+ where: { id: Number(id) },
79
+ });
80
+ if (!content) {
81
+ throw new common_1.NotFoundException((0, api_locale_1.getLocaleText)('contentNotFound', locale, 'Content not found'));
82
+ }
83
+ return this.prisma.content.delete({
84
+ where: { id: Number(id) },
85
+ });
86
+ }
87
+ async createContent(localeStr, { locale, slug, status }) {
88
+ const existingContent = await this.prisma.content.findUnique({
89
+ where: { slug },
90
+ });
91
+ if (existingContent) {
92
+ throw new common_1.BadRequestException((0, api_locale_1.getLocaleText)('contentWithSlugExists', localeStr, 'Content with this slug already exists'));
93
+ }
94
+ const content = await this.prisma.content.create({
95
+ data: {
96
+ slug,
97
+ status,
98
+ },
99
+ });
100
+ if (!content) {
101
+ throw new common_1.BadRequestException((0, api_locale_1.getLocaleText)('failedToCreateContent', localeStr, 'Failed to create content'));
102
+ }
103
+ for (const [localeCode, localeData] of Object.entries(locale)) {
104
+ const localeRecord = await this.locale.getByCode(localeCode);
105
+ if (!localeRecord) {
106
+ throw new common_1.BadRequestException((0, api_locale_1.getLocaleText)('localeNotFound', localeStr, `Locale ${localeCode} not found`).replace('{{locale}}', localeCode));
107
+ }
108
+ await this.prisma.content_locale.create({
109
+ data: {
110
+ title: localeData.title,
111
+ body: localeData.body,
112
+ content_id: content.id,
113
+ locale_id: localeRecord.id,
114
+ },
115
+ });
116
+ }
117
+ return content;
118
+ }
119
+ async updateContent(localeStr, id, { locale, slug, status }) {
120
+ const content = await this.prisma.content.findUnique({
121
+ where: { id: Number(id) },
122
+ });
123
+ if (!content) {
124
+ throw new common_1.NotFoundException((0, api_locale_1.getLocaleText)('contentNotFound', localeStr, 'Content not found'));
125
+ }
126
+ const contentUpdated = await this.prisma.content.update({
127
+ where: { id: Number(id) },
128
+ data: {
129
+ slug,
130
+ status,
131
+ },
132
+ });
133
+ if (locale) {
134
+ for (const [localeCode, localeData] of Object.entries(locale)) {
135
+ const localeRecord = await this.locale.getByCode(localeCode);
136
+ if (!localeRecord) {
137
+ throw new common_1.BadRequestException((0, api_locale_1.getLocaleText)('localeNotFound', localeStr, `Locale ${localeCode} not found`).replace('{{locale}}', localeCode));
138
+ }
139
+ const existingLocale = await this.prisma.category_locale.findFirst({
140
+ where: {
141
+ category_id: Number(id),
142
+ locale_id: localeRecord.id,
143
+ },
144
+ });
145
+ if (existingLocale) {
146
+ await this.prisma.content_locale.update({
147
+ where: { id: existingLocale.id },
148
+ data: { title: localeData.title, body: localeData.body },
149
+ });
150
+ }
151
+ else {
152
+ await this.prisma.content_locale.create({
153
+ data: {
154
+ content_id: Number(id),
155
+ locale_id: localeRecord.id,
156
+ title: localeData.title,
157
+ body: localeData.body,
158
+ },
159
+ });
160
+ }
161
+ }
162
+ }
163
+ return contentUpdated;
164
+ }
165
+ };
166
+ exports.ContentService = ContentService;
167
+ exports.ContentService = ContentService = __decorate([
168
+ (0, common_1.Injectable)(),
169
+ __metadata("design:paramtypes", [api_prisma_1.PrismaService,
170
+ api_pagination_1.PaginationService,
171
+ api_locale_1.LocaleService])
172
+ ], ContentService);
173
+ //# sourceMappingURL=content.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.service.js","sourceRoot":"","sources":["../src/content.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAAgD;AAChD,oDAAmE;AACnE,4DAA2E;AAC3E,oDAAoD;AACpD,2CAAoF;AAK7E,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YACmB,MAAqB,EACrB,UAA6B,EAC7B,MAAqB;QAFrB,WAAM,GAAN,MAAM,CAAe;QACrB,eAAU,GAAV,UAAU,CAAmB;QAC7B,WAAM,GAAN,MAAM,CAAe;IACrC,CAAC;IAEJ,KAAK,CAAC,eAAe;QACnB,MAAM,QAAQ,GAAG,CAAC,WAAW,EAAE,OAAO,CAAU,CAAC;QAEjD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,qBAAqB,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC/D,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,CAAC,GAAG,CACT,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACtB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;gBACxB,KAAK,EAAE,EAAE,MAAM,EAAE,MAAa,EAAE;aACjC,CAAC,CACH,CACF;YACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;gBACvB,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;aACzB,CAAC;SACH,CAAC,CAAC;QAEH,OAAO;YACL,KAAK;YACL,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC;YACzB,UA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C;oBACN,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC;wBACtC,IAAI,EAAE;4BACJ,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC;4BACtB,SAAS,EAAE,YAAY,CAAC,EAAE;4BAC1B,KAAK,EAAE,UAAU,CAAC,KAAK;4BACvB,IAAI,EAAE,UAAU,CAAC,IAAI;yBACtB;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,cAAc,CAAA;IACvB,CAAC;CACF,CAAA;AAtLY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;qCAGgB,0BAAa;QACT,kCAAiB;QACrB,0BAAa;GAJ7B,cAAc,CAsL1B"}
@@ -0,0 +1,9 @@
1
+ export declare class ContentCreateDTO {
2
+ slug: string;
3
+ locale: Record<string, {
4
+ title: string;
5
+ body: string;
6
+ }>;
7
+ status: 'draft' | 'published';
8
+ }
9
+ //# sourceMappingURL=content-create.dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-create.dto.d.ts","sourceRoot":"","sources":["../../src/dto/content-create.dto.ts"],"names":[],"mappings":"AAGA,qBAAa,gBAAgB;IAQ3B,IAAI,EAAE,MAAM,CAAC;IASb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAUxD,MAAM,EAAE,OAAO,GAAG,WAAW,CAAC;CAC/B"}
@@ -0,0 +1,45 @@
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.ContentCreateDTO = void 0;
13
+ const api_locale_1 = require("@hed-hog/api-locale");
14
+ const class_validator_1 = require("class-validator");
15
+ class ContentCreateDTO {
16
+ }
17
+ exports.ContentCreateDTO = ContentCreateDTO;
18
+ __decorate([
19
+ (0, class_validator_1.IsString)({
20
+ message: (args) => (0, api_locale_1.getLocaleText)('validation.slugMustBeString', args.value),
21
+ }),
22
+ (0, class_validator_1.IsNotEmpty)({
23
+ message: (args) => (0, api_locale_1.getLocaleText)('validation.slugRequired', args.value),
24
+ }),
25
+ __metadata("design:type", String)
26
+ ], ContentCreateDTO.prototype, "slug", void 0);
27
+ __decorate([
28
+ (0, class_validator_1.IsObject)({
29
+ message: (args) => (0, api_locale_1.getLocaleText)('validation.localeMustBeObject', args.value),
30
+ }),
31
+ (0, class_validator_1.IsNotEmpty)({
32
+ message: (args) => (0, api_locale_1.getLocaleText)('validation.localeRequired', args.value),
33
+ }),
34
+ __metadata("design:type", Object)
35
+ ], ContentCreateDTO.prototype, "locale", void 0);
36
+ __decorate([
37
+ (0, class_validator_1.IsString)({
38
+ message: (args) => (0, api_locale_1.getLocaleText)('validation.statusMustBeString', args.value),
39
+ }),
40
+ (0, class_validator_1.IsEnum)(['draft', 'published'], {
41
+ message: (args) => (0, api_locale_1.getLocaleText)('validation.statusMustBeEnum', args.value),
42
+ }),
43
+ __metadata("design:type", String)
44
+ ], ContentCreateDTO.prototype, "status", void 0);
45
+ //# sourceMappingURL=content-create.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-create.dto.js","sourceRoot":"","sources":["../../src/dto/content-create.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAoD;AACpD,qDAAyE;AAEzE,MAAa,gBAAgB;CA4B5B;AA5BD,4CA4BC;AApBC;IAPC,IAAA,0BAAQ,EAAC;QACR,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAChB,IAAA,0BAAa,EAAC,6BAA6B,EAAE,IAAI,CAAC,KAAK,CAAC;KAC3D,CAAC;IACD,IAAA,4BAAU,EAAC;QACV,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,0BAAa,EAAC,yBAAyB,EAAE,IAAI,CAAC,KAAK,CAAC;KACxE,CAAC;;8CACW;AASb;IAPC,IAAA,0BAAQ,EAAC;QACR,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAChB,IAAA,0BAAa,EAAC,+BAA+B,EAAE,IAAI,CAAC,KAAK,CAAC;KAC7D,CAAC;IACD,IAAA,4BAAU,EAAC;QACV,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,0BAAa,EAAC,2BAA2B,EAAE,IAAI,CAAC,KAAK,CAAC;KAC1E,CAAC;;gDACsD;AAUxD;IARC,IAAA,0BAAQ,EAAC;QACR,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAChB,IAAA,0BAAa,EAAC,+BAA+B,EAAE,IAAI,CAAC,KAAK,CAAC;KAC7D,CAAC;IACD,IAAA,wBAAM,EAAC,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE;QAC9B,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAChB,IAAA,0BAAa,EAAC,6BAA6B,EAAE,IAAI,CAAC,KAAK,CAAC;KAC3D,CAAC;;gDAC4B"}
@@ -0,0 +1,6 @@
1
+ import { ContentCreateDTO } from './content-create.dto';
2
+ declare const ContentUpdateDTO_base: import("@nestjs/mapped-types").MappedType<Partial<ContentCreateDTO>>;
3
+ export declare class ContentUpdateDTO extends ContentUpdateDTO_base {
4
+ }
5
+ export {};
6
+ //# sourceMappingURL=content-update.dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-update.dto.d.ts","sourceRoot":"","sources":["../../src/dto/content-update.dto.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;;AAExD,qBAAa,gBAAiB,SAAQ,qBAA6B;CAAG"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContentUpdateDTO = void 0;
4
+ const mapped_types_1 = require("@nestjs/mapped-types");
5
+ const content_create_dto_1 = require("./content-create.dto");
6
+ class ContentUpdateDTO extends (0, mapped_types_1.PartialType)(content_create_dto_1.ContentCreateDTO) {
7
+ }
8
+ exports.ContentUpdateDTO = ContentUpdateDTO;
9
+ //# sourceMappingURL=content-update.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-update.dto.js","sourceRoot":"","sources":["../../src/dto/content-update.dto.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AACnD,6DAAwD;AAExD,MAAa,gBAAiB,SAAQ,IAAA,0BAAW,EAAC,qCAAgB,CAAC;CAAG;AAAtE,4CAAsE"}
@@ -0,0 +1,2 @@
1
+ export * from './content.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,kBAAkB,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("./content.module"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC"}
@@ -0,0 +1,10 @@
1
+ - url: /content
2
+ icon: book-marked
3
+ name:
4
+ en: Content
5
+ pt: Conteúdo
6
+ slug: /content
7
+ relations:
8
+ role:
9
+ - where:
10
+ slug: admin
@@ -0,0 +1,36 @@
1
+ - url: /content
2
+ method: GET
3
+ relations:
4
+ role:
5
+ - where:
6
+ slug: admin
7
+ - url: /content
8
+ method: POST
9
+ relations:
10
+ role:
11
+ - where:
12
+ slug: admin
13
+ - url: /content/stats
14
+ method: GET
15
+ relations:
16
+ role:
17
+ - where:
18
+ slug: admin
19
+ - url: /content/:id
20
+ method: GET
21
+ relations:
22
+ role:
23
+ - where:
24
+ slug: admin
25
+ - url: /content/:id
26
+ method: PATCH
27
+ relations:
28
+ role:
29
+ - where:
30
+ slug: admin
31
+ - url: /content/:id
32
+ method: DELETE
33
+ relations:
34
+ role:
35
+ - where:
36
+ slug: admin
@@ -0,0 +1,18 @@
1
+ columns:
2
+ - type: pk
3
+ - type: slug
4
+ - name: status
5
+ type: enum
6
+ values: [draft, published]
7
+ - name: title
8
+ type: locale_varchar
9
+ locale:
10
+ en: Title
11
+ pt: Título
12
+ - name: body
13
+ type: locale_text
14
+ locale:
15
+ en: Body
16
+ pt: Corpo
17
+ - type: created_at
18
+ - type: updated_at
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@hed-hog/content",
3
+ "version": "0.0.0",
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/api-locale": "0.0.10",
13
+ "@hed-hog/core": "0.0.13",
14
+ "@hed-hog/api-pagination": "0.0.3",
15
+ "@hed-hog/api-prisma": "0.0.4",
16
+ "@hed-hog/api": "0.0.3"
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/contact-us",
33
+ "build": "tsc --project tsconfig.production.json",
34
+ "patch": "npx ts-node ../../scripts/patch.ts libraries/contact-us",
35
+ "prod": "pnpm run patch && pnpm run build && pnpm publish --access public --no-git-checks"
36
+ }
37
+ }
@@ -0,0 +1,65 @@
1
+ import { Locale } from "@hed-hog/api-locale";
2
+ import { Pagination, PaginationDTO } from "@hed-hog/api-pagination";
3
+ import {
4
+ Body,
5
+ Controller,
6
+ Delete,
7
+ Get,
8
+ Param,
9
+ ParseIntPipe,
10
+ Patch,
11
+ Post,
12
+ Query
13
+ } from "@nestjs/common";
14
+ import { ContentService } from "./content.service";
15
+ import { ContentCreateDTO } from "./dto/content-create.dto";
16
+ import { ContentUpdateDTO } from "./dto/content-update.dto";
17
+
18
+ @Controller('content')
19
+ export class ContentController {
20
+ constructor(
21
+ private readonly contentService: ContentService
22
+ ) {}
23
+
24
+ @Get('stats')
25
+ async getContentStats() {
26
+ return this.contentService.getContentStats();
27
+ }
28
+
29
+ @Get(':id')
30
+ async getContent(@Param('id', ParseIntPipe) id: number) {
31
+ return this.contentService.getContent(id);
32
+ }
33
+
34
+ @Get()
35
+ async getContents(@Locale() locale: string, @Pagination() paginationParams: PaginationDTO, @Query() query: any) {
36
+ return this.contentService.getContents(locale, paginationParams, query);
37
+ }
38
+
39
+ @Delete(':id')
40
+ async deleteContent(@Locale() locale: string, @Param('id', ParseIntPipe) id: number) {
41
+ return this.contentService.deleteContent(locale, id);
42
+ }
43
+
44
+ @Post()
45
+ async createContent(@Locale() localeStr: string, @Body() { slug, status, locale }: ContentCreateDTO) {
46
+ return this.contentService.createContent(localeStr, {
47
+ slug,
48
+ status,
49
+ locale,
50
+ });
51
+ }
52
+
53
+ @Patch(':id')
54
+ async updateContent(
55
+ @Locale() localeStr: string,
56
+ @Param('id', ParseIntPipe) id: number,
57
+ @Body() { locale, slug, status }: ContentUpdateDTO,
58
+ ) {
59
+ return this.contentService.updateContent(localeStr, id, {
60
+ locale,
61
+ slug,
62
+ status,
63
+ });
64
+ }
65
+ }
@@ -0,0 +1,18 @@
1
+ import { LocaleModule } from '@hed-hog/api-locale';
2
+ import { PaginationModule } from '@hed-hog/api-pagination';
3
+ import { PrismaModule } from '@hed-hog/api-prisma';
4
+ import { forwardRef, Module } from '@nestjs/common';
5
+ import { ContentController } from './content.controller';
6
+ import { ContentService } from './content.service';
7
+
8
+ @Module({
9
+ imports: [
10
+ forwardRef(() => LocaleModule),
11
+ forwardRef(() => PrismaModule),
12
+ forwardRef(() => PaginationModule),
13
+ ],
14
+ controllers: [ContentController],
15
+ providers: [ContentService],
16
+ exports: [forwardRef(() => ContentService)],
17
+ })
18
+ export class ContentModule {}
@@ -0,0 +1,192 @@
1
+ import { itemTranslations } from '@hed-hog/api';
2
+ import { getLocaleText, LocaleService } from '@hed-hog/api-locale';
3
+ import { PaginationDTO, PaginationService } from '@hed-hog/api-pagination';
4
+ import { PrismaService } from '@hed-hog/api-prisma';
5
+ import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
6
+ import { ContentCreateDTO } from './dto/content-create.dto';
7
+ import { ContentUpdateDTO } from './dto/content-update.dto';
8
+
9
+ @Injectable()
10
+ export class ContentService {
11
+ constructor(
12
+ private readonly prisma: PrismaService,
13
+ private readonly pagination: PaginationService,
14
+ private readonly locale: LocaleService,
15
+ ) {}
16
+
17
+ async getContentStats() {
18
+ const statuses = ['published', 'draft'] as const;
19
+
20
+ const [total, counts, enabledLanguagesCount] = await Promise.all([
21
+ this.prisma.content.count({}),
22
+ Promise.all(
23
+ statuses.map((status) =>
24
+ this.prisma.content.count({
25
+ where: { status: status as any },
26
+ }),
27
+ ),
28
+ ),
29
+ this.prisma.locale.count({
30
+ where: { enabled: true },
31
+ }),
32
+ ]);
33
+
34
+ return {
35
+ total,
36
+ totalPublished: counts[0],
37
+ totalDraft: counts[1],
38
+ totalEnabledLanguages: enabledLanguagesCount,
39
+ };
40
+ }
41
+
42
+ async getContent(id: number) {
43
+ return itemTranslations(
44
+ 'content_locale',
45
+ await this.locale.getModelWithLocaleWhere('content', {
46
+ id: Number(id),
47
+ }),
48
+ );
49
+ }
50
+
51
+ async getContents(locale: string, paginationParams: PaginationDTO, query: any) {
52
+ const localeRecord = await this.locale.getByCode(locale);
53
+ if (!localeRecord) {
54
+ throw new BadRequestException(getLocaleText('localeNotFound', locale, `Locale ${locale} not found`).replace('{{locale}}', locale));
55
+ }
56
+
57
+ const fields = ['slug'];
58
+ const OR = this.prisma.createInsensitiveSearch(fields, paginationParams);
59
+ const AND = [];
60
+
61
+ if (query.status && query.status !== 'all') {
62
+ AND.push({
63
+ status: query.status,
64
+ });
65
+ }
66
+
67
+ const result = await this.pagination.paginate(this.prisma.content, paginationParams, {
68
+ where: {
69
+ OR,
70
+ AND,
71
+ },
72
+ include: {
73
+ content_locale: {
74
+ where: {
75
+ locale_id: localeRecord.id,
76
+ },
77
+ },
78
+ },
79
+ }, locale);
80
+
81
+ result.data = result.data.map((content) =>
82
+ itemTranslations('content_locale', content),
83
+ );
84
+
85
+ return result;
86
+ }
87
+
88
+ async deleteContent(locale: string, id: number) {
89
+ const content = await this.prisma.content.findUnique({
90
+ where: { id: Number(id) },
91
+ });
92
+
93
+ if (!content) {
94
+ throw new NotFoundException(getLocaleText('contentNotFound', locale, 'Content not found'),);
95
+ }
96
+
97
+ return this.prisma.content.delete({
98
+ where: { id: Number(id) },
99
+ });
100
+ }
101
+
102
+ async createContent(localeStr: string, { locale, slug, status }: ContentCreateDTO) {
103
+ const existingContent = await this.prisma.content.findUnique({
104
+ where: { slug },
105
+ });
106
+
107
+ if (existingContent) {
108
+ throw new BadRequestException(getLocaleText('contentWithSlugExists', localeStr, 'Content with this slug already exists'));
109
+ }
110
+
111
+ const content = await this.prisma.content.create({
112
+ data: {
113
+ slug,
114
+ status,
115
+ },
116
+ });
117
+
118
+ if (!content) {
119
+ throw new BadRequestException(getLocaleText('failedToCreateContent', localeStr, 'Failed to create content'));
120
+ }
121
+
122
+ for (const [localeCode, localeData] of Object.entries(locale)) {
123
+ const localeRecord = await this.locale.getByCode(localeCode);
124
+ if (!localeRecord) {
125
+ throw new BadRequestException(getLocaleText('localeNotFound', localeStr, `Locale ${localeCode} not found`).replace('{{locale}}', localeCode));
126
+ }
127
+
128
+ await this.prisma.content_locale.create({
129
+ data: {
130
+ title: localeData.title,
131
+ body: localeData.body,
132
+ content_id: content.id,
133
+ locale_id: localeRecord.id,
134
+ },
135
+ });
136
+ }
137
+
138
+ return content;
139
+ }
140
+
141
+ async updateContent(localeStr: string, id: number, { locale, slug, status }: ContentUpdateDTO) {
142
+ const content = await this.prisma.content.findUnique({
143
+ where: { id: Number(id) },
144
+ });
145
+
146
+ if (!content) {
147
+ throw new NotFoundException(getLocaleText('contentNotFound', localeStr, 'Content not found'));
148
+ }
149
+
150
+ const contentUpdated = await this.prisma.content.update({
151
+ where: { id: Number(id) },
152
+ data: {
153
+ slug,
154
+ status,
155
+ },
156
+ });
157
+
158
+ if (locale) {
159
+ for (const [localeCode, localeData] of Object.entries(locale)) {
160
+ const localeRecord = await this.locale.getByCode(localeCode);
161
+ if (!localeRecord) {
162
+ throw new BadRequestException(getLocaleText('localeNotFound', localeStr, `Locale ${localeCode} not found`).replace('{{locale}}', localeCode));
163
+ }
164
+
165
+ const existingLocale = await this.prisma.category_locale.findFirst({
166
+ where: {
167
+ category_id: Number(id),
168
+ locale_id: localeRecord.id,
169
+ },
170
+ });
171
+
172
+ if (existingLocale) {
173
+ await this.prisma.content_locale.update({
174
+ where: { id: existingLocale.id },
175
+ data: { title: localeData.title, body: localeData.body },
176
+ });
177
+ } else {
178
+ await this.prisma.content_locale.create({
179
+ data: {
180
+ content_id: Number(id),
181
+ locale_id: localeRecord.id,
182
+ title: localeData.title,
183
+ body: localeData.body,
184
+ },
185
+ });
186
+ }
187
+ }
188
+ }
189
+
190
+ return contentUpdated
191
+ }
192
+ }
@@ -0,0 +1,32 @@
1
+ import { getLocaleText } from '@hed-hog/api-locale';
2
+ import { IsEnum, IsNotEmpty, IsObject, IsString } from 'class-validator';
3
+
4
+ export class ContentCreateDTO {
5
+ @IsString({
6
+ message: (args) =>
7
+ getLocaleText('validation.slugMustBeString', args.value),
8
+ })
9
+ @IsNotEmpty({
10
+ message: (args) => getLocaleText('validation.slugRequired', args.value),
11
+ })
12
+ slug: string;
13
+
14
+ @IsObject({
15
+ message: (args) =>
16
+ getLocaleText('validation.localeMustBeObject', args.value),
17
+ })
18
+ @IsNotEmpty({
19
+ message: (args) => getLocaleText('validation.localeRequired', args.value),
20
+ })
21
+ locale: Record<string, { title: string, body: string }>;
22
+
23
+ @IsString({
24
+ message: (args) =>
25
+ getLocaleText('validation.statusMustBeString', args.value),
26
+ })
27
+ @IsEnum(['draft', 'published'], {
28
+ message: (args) =>
29
+ getLocaleText('validation.statusMustBeEnum', args.value),
30
+ })
31
+ status: 'draft' | 'published';
32
+ }
@@ -0,0 +1,4 @@
1
+ import { PartialType } from '@nestjs/mapped-types';
2
+ import { ContentCreateDTO } from './content-create.dto';
3
+
4
+ export class ContentUpdateDTO extends PartialType(ContentCreateDTO) {}
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './content.module';
2
+
@@ -0,0 +1,14 @@
1
+ {
2
+ "contentNotFound": "Content not found",
3
+ "contentWithSlugExists": "Content with this slug already exists",
4
+ "failedToCreateContent": "Failed to create content",
5
+ "localeNotFound": "Locale {{locale}} not found",
6
+ "validation": {
7
+ "slugMustBeString": "Slug must be a string",
8
+ "slugRequired": "Slug is required",
9
+ "localeMustBeObject": "Locale must be an object",
10
+ "localeRequired": "Locale is required",
11
+ "statusMustBeString": "Status must be a string",
12
+ "statusMustBeEnum": "Status must be 'draft' or 'published'"
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "contentNotFound": "Conteúdo não encontrado",
3
+ "contentWithSlugExists": "Conteúdo com este slug já existe",
4
+ "failedToCreateContent": "Falha ao criar o conteúdo",
5
+ "localeNotFound": "Locale {{locale}} não encontrado",
6
+ "validation": {
7
+ "slugMustBeString": "Slug deve ser uma string",
8
+ "slugRequired": "Slug é obrigatório",
9
+ "localeMustBeObject": "Locale deve ser um objeto",
10
+ "localeRequired": "Locale é obrigatório",
11
+ "statusMustBeString": "Status deve ser uma string",
12
+ "statusMustBeEnum": "Status deve ser 'draft' ou 'published'"
13
+ }
14
+ }