@hed-hog/core 0.0.151 → 0.0.152

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.
Files changed (96) hide show
  1. package/dist/dashboard/dashboard/dashboard.controller.d.ts +214 -9
  2. package/dist/dashboard/dashboard/dashboard.controller.d.ts.map +1 -1
  3. package/dist/dashboard/dashboard/dashboard.controller.js +35 -35
  4. package/dist/dashboard/dashboard/dashboard.controller.js.map +1 -1
  5. package/dist/dashboard/dashboard/dashboard.module.d.ts +1 -1
  6. package/dist/dashboard/dashboard/dashboard.module.d.ts.map +1 -1
  7. package/dist/dashboard/dashboard/dashboard.module.js +11 -6
  8. package/dist/dashboard/dashboard/dashboard.module.js.map +1 -1
  9. package/dist/dashboard/dashboard/dashboard.service.d.ts +217 -16
  10. package/dist/dashboard/dashboard/dashboard.service.d.ts.map +1 -1
  11. package/dist/dashboard/dashboard/dashboard.service.js +115 -28
  12. package/dist/dashboard/dashboard/dashboard.service.js.map +1 -1
  13. package/dist/dashboard/dashboard/dto/create.dto.d.ts +4 -2
  14. package/dist/dashboard/dashboard/dto/create.dto.d.ts.map +1 -1
  15. package/dist/dashboard/dashboard/dto/create.dto.js +10 -1
  16. package/dist/dashboard/dashboard/dto/create.dto.js.map +1 -1
  17. package/dist/dashboard/dashboard/dto/index.d.ts +5 -0
  18. package/dist/dashboard/dashboard/dto/index.d.ts.map +1 -0
  19. package/dist/dashboard/dashboard/dto/index.js +25 -0
  20. package/dist/dashboard/dashboard/dto/index.js.map +1 -0
  21. package/dist/dashboard/dashboard/dto/update.dto.d.ts +5 -4
  22. package/dist/dashboard/dashboard/dto/update.dto.d.ts.map +1 -1
  23. package/dist/dashboard/dashboard/dto/update.dto.js +27 -3
  24. package/dist/dashboard/dashboard/dto/update.dto.js.map +1 -1
  25. package/dist/dashboard/dashboard-component/dashboard-component.controller.d.ts +114 -9
  26. package/dist/dashboard/dashboard-component/dashboard-component.controller.d.ts.map +1 -1
  27. package/dist/dashboard/dashboard-component/dashboard-component.controller.js +35 -36
  28. package/dist/dashboard/dashboard-component/dashboard-component.controller.js.map +1 -1
  29. package/dist/dashboard/dashboard-component/dashboard-component.module.js +4 -3
  30. package/dist/dashboard/dashboard-component/dashboard-component.module.js.map +1 -1
  31. package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts +116 -15
  32. package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts.map +1 -1
  33. package/dist/dashboard/dashboard-component/dashboard-component.service.js +109 -22
  34. package/dist/dashboard/dashboard-component/dashboard-component.service.js.map +1 -1
  35. package/dist/dashboard/dashboard-component/dto/create.dto.d.ts +4 -2
  36. package/dist/dashboard/dashboard-component/dto/create.dto.d.ts.map +1 -1
  37. package/dist/dashboard/dashboard-component/dto/create.dto.js +10 -1
  38. package/dist/dashboard/dashboard-component/dto/create.dto.js.map +1 -1
  39. package/dist/dashboard/dashboard-component/dto/index.d.ts +5 -0
  40. package/dist/dashboard/dashboard-component/dto/index.d.ts.map +1 -0
  41. package/dist/dashboard/dashboard-component/dto/index.js +25 -0
  42. package/dist/dashboard/dashboard-component/dto/index.js.map +1 -0
  43. package/dist/dashboard/dashboard-component/dto/update.dto.d.ts +13 -4
  44. package/dist/dashboard/dashboard-component/dto/update.dto.d.ts.map +1 -1
  45. package/dist/dashboard/dashboard-component/dto/update.dto.js +67 -3
  46. package/dist/dashboard/dashboard-component/dto/update.dto.js.map +1 -1
  47. package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts +56 -0
  48. package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts.map +1 -1
  49. package/dist/dashboard/dashboard-core/dashboard-core.controller.js +65 -0
  50. package/dist/dashboard/dashboard-core/dashboard-core.controller.js.map +1 -1
  51. package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts +52 -0
  52. package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts.map +1 -1
  53. package/dist/dashboard/dashboard-core/dashboard-core.service.js +221 -0
  54. package/dist/dashboard/dashboard-core/dashboard-core.service.js.map +1 -1
  55. package/dist/dashboard/dashboard-item/dashboard-item.controller.d.ts +26 -29
  56. package/dist/dashboard/dashboard-item/dashboard-item.controller.d.ts.map +1 -1
  57. package/dist/dashboard/dashboard-item/dashboard-item.controller.js +24 -43
  58. package/dist/dashboard/dashboard-item/dashboard-item.controller.js.map +1 -1
  59. package/dist/dashboard/dashboard-item/dashboard-item.service.d.ts +30 -34
  60. package/dist/dashboard/dashboard-item/dashboard-item.service.d.ts.map +1 -1
  61. package/dist/dashboard/dashboard-item/dashboard-item.service.js +51 -35
  62. package/dist/dashboard/dashboard-item/dashboard-item.service.js.map +1 -1
  63. package/dist/dashboard/dashboard-item/dto/index.d.ts +5 -0
  64. package/dist/dashboard/dashboard-item/dto/index.d.ts.map +1 -0
  65. package/dist/dashboard/dashboard-item/dto/index.js +25 -0
  66. package/dist/dashboard/dashboard-item/dto/index.js.map +1 -0
  67. package/dist/dashboard/dashboard-item/dto/update.dto.d.ts +7 -4
  68. package/dist/dashboard/dashboard-item/dto/update.dto.d.ts.map +1 -1
  69. package/dist/dashboard/dashboard-item/dto/update.dto.js +42 -3
  70. package/dist/dashboard/dashboard-item/dto/update.dto.js.map +1 -1
  71. package/dist/dashboard/dashboard.module.js +1 -1
  72. package/dist/dashboard/dashboard.module.js.map +1 -1
  73. package/hedhog/data/route.yaml +44 -14
  74. package/hedhog/query/dashboard-seed.sql +131 -0
  75. package/package.json +1 -1
  76. package/src/dashboard/dashboard/dashboard.controller.ts +26 -23
  77. package/src/dashboard/dashboard/dashboard.module.ts +7 -2
  78. package/src/dashboard/dashboard/dashboard.service.ts +125 -44
  79. package/src/dashboard/dashboard/dto/create.dto.ts +12 -3
  80. package/src/dashboard/dashboard/dto/index.ts +7 -0
  81. package/src/dashboard/dashboard/dto/update.dto.ts +17 -3
  82. package/src/dashboard/dashboard-component/dashboard-component.controller.ts +22 -19
  83. package/src/dashboard/dashboard-component/dashboard-component.module.ts +3 -3
  84. package/src/dashboard/dashboard-component/dashboard-component.service.ts +128 -39
  85. package/src/dashboard/dashboard-component/dto/create.dto.ts +12 -3
  86. package/src/dashboard/dashboard-component/dto/index.ts +7 -0
  87. package/src/dashboard/dashboard-component/dto/update.dto.ts +49 -3
  88. package/src/dashboard/dashboard-core/dashboard-core.controller.ts +53 -2
  89. package/src/dashboard/dashboard-core/dashboard-core.service.ts +271 -0
  90. package/src/dashboard/dashboard-item/dashboard-item.controller.ts +17 -26
  91. package/src/dashboard/dashboard-item/dashboard-item.service.ts +55 -47
  92. package/src/dashboard/dashboard-item/dto/index.ts +7 -0
  93. package/src/dashboard/dashboard-item/dto/update.dto.ts +27 -3
  94. package/src/dashboard/dashboard.module.ts +2 -2
  95. package/src/language/en.json +4 -1
  96. package/src/language/pt.json +4 -1
@@ -1,4 +1,4 @@
1
- import { DeleteDTO, Role } from '@hed-hog/api';
1
+ import { Role } from '@hed-hog/api';
2
2
  import { Locale } from '@hed-hog/api-locale';
3
3
  import { Pagination } from '@hed-hog/api-pagination';
4
4
  import {
@@ -9,41 +9,44 @@ import {
9
9
  Param,
10
10
  ParseIntPipe,
11
11
  Patch,
12
- Post,
12
+ Post
13
13
  } from '@nestjs/common';
14
14
  import { DashboardService } from './dashboard.service';
15
- import { CreateDTO } from './dto/create.dto';
16
- import { UpdateDTO } from './dto/update.dto';
15
+ import {
16
+ CreateDashboardDTO,
17
+ UpdateDashboardDTO,
18
+ } from './dto';
17
19
  @Role()
18
- @Controller('/dashboard')
20
+ @Controller('dashboard')
19
21
  export class DashboardController {
20
22
  constructor(private readonly dashboardService: DashboardService) {}
21
23
 
22
24
  @Get()
23
- async list(@Locale() locale, @Pagination() paginationParams) {
24
- return this.dashboardService.list(locale, paginationParams);
25
+ getAllDashboards(@Pagination() paginationParams, @Locale() locale: string) {
26
+ return this.dashboardService.getAllDashboards(paginationParams, locale);
25
27
  }
26
-
28
+
27
29
  @Get(':id')
28
- async get(@Param('id', ParseIntPipe) id: number) {
29
- return this.dashboardService.get(id);
30
+ getDashboard(@Param('id', ParseIntPipe) id: number, @Locale() locale: string) {
31
+ return this.dashboardService.getDashboard(id, locale);
30
32
  }
31
-
33
+
32
34
  @Post()
33
- async create(@Body() data: CreateDTO) {
34
- return this.dashboardService.create(data);
35
+ createDashboard(@Body() data: CreateDashboardDTO, @Locale() locale: string) {
36
+ return this.dashboardService.createDashboard(data, locale);
35
37
  }
36
-
38
+
37
39
  @Patch(':id')
38
- async update(@Param('id', ParseIntPipe) id: number, @Body() data: UpdateDTO) {
39
- return this.dashboardService.update({
40
- id,
41
- data,
42
- });
40
+ updateDashboard(
41
+ @Param('id', ParseIntPipe) id: number,
42
+ @Body() data: UpdateDashboardDTO,
43
+ @Locale() locale: string,
44
+ ) {
45
+ return this.dashboardService.updateDashboard(id, data, locale);
43
46
  }
44
-
45
- @Delete()
46
- async delete(@Body() data: DeleteDTO) {
47
- return this.dashboardService.delete(data);
47
+
48
+ @Delete(':id')
49
+ deleteDashboard(@Param('id', ParseIntPipe) id: number, @Locale() locale: string) {
50
+ return this.dashboardService.deleteDashboard(id, locale);
48
51
  }
49
52
  }
@@ -1,13 +1,18 @@
1
1
  import { LocaleModule } from '@hed-hog/api-locale';
2
+ import { PaginationModule } from '@hed-hog/api-pagination';
2
3
  import { PrismaModule } from '@hed-hog/api-prisma';
3
4
  import { forwardRef, Module } from '@nestjs/common';
4
5
  import { DashboardController } from './dashboard.controller';
5
6
  import { DashboardService } from './dashboard.service';
6
7
 
7
8
  @Module({
8
- imports: [forwardRef(() => LocaleModule), forwardRef(() => PrismaModule)],
9
+ imports: [
10
+ forwardRef(() => LocaleModule),
11
+ forwardRef(() => PrismaModule),
12
+ forwardRef(() => PaginationModule),
13
+ ],
9
14
  controllers: [DashboardController],
10
15
  providers: [DashboardService],
11
16
  exports: [forwardRef(() => DashboardService)],
12
17
  })
13
- export class DashboardModule2 {}
18
+ export class DashboardCrudModule {}
@@ -1,71 +1,152 @@
1
- import { DeleteDTO } from '@hed-hog/api';
2
- import { LocaleService } from '@hed-hog/api-locale';
3
- import { PaginationDTO } from '@hed-hog/api-pagination';
1
+ import { getLocaleText, LocaleService } from '@hed-hog/api-locale';
2
+ import { PaginationService } from '@hed-hog/api-pagination';
4
3
  import { PrismaService } from '@hed-hog/api-prisma';
5
- import { Injectable } from '@nestjs/common';
6
- import { BadRequestException } from '@nestjs/common/exceptions';
7
- import { CreateDTO } from './dto/create.dto';
8
- import { UpdateDTO } from './dto/update.dto';
4
+ import { forwardRef, Inject, Injectable, NotFoundException } from '@nestjs/common';
5
+ import { CreateDashboardDTO, UpdateDashboardDTO } from './dto';
9
6
 
10
7
  @Injectable()
11
8
  export class DashboardService {
12
9
  constructor(
13
- private readonly localeService: LocaleService,
10
+ @Inject(forwardRef(() => PrismaService))
14
11
  private readonly prismaService: PrismaService,
12
+ @Inject(forwardRef(() => PaginationService))
13
+ private readonly paginationService: PaginationService,
14
+ @Inject(forwardRef(() => LocaleService))
15
+ private readonly localeService: LocaleService,
15
16
  ) {}
16
- private readonly modelName = 'dashboard';
17
- private readonly foreignKey = 'dashboard_id';
18
-
19
- async list(locale: string, paginationParams: PaginationDTO) {
20
- return this.localeService.listModelWithLocale(
21
- locale,
22
- 'dashboard',
17
+ async getAllDashboards(paginationParams, locale: string) {
18
+ return this.paginationService.paginate(
19
+ this.prismaService.dashboard,
23
20
  paginationParams,
24
- {},
25
21
  {
26
- dashboard_item: {
27
- include: {
28
- dashboard_component: true,
22
+ include: {
23
+ dashboard_locale: {
24
+ include: {
25
+ locale: true,
26
+ },
29
27
  },
30
28
  },
29
+ orderBy: {
30
+ id: 'desc',
31
+ },
31
32
  },
33
+ 'dashboard',
32
34
  );
33
35
  }
36
+
37
+ async getDashboard(id: number, locale: string) {
38
+ const dashboard = await this.prismaService.dashboard.findUnique({
39
+ where: { id },
40
+ include: {
41
+ dashboard_locale: {
42
+ include: {
43
+ locale: true,
44
+ },
45
+ },
46
+ dashboard_item: {
47
+ include: {
48
+ dashboard_component: {
49
+ include: {
50
+ dashboard_component_locale: {
51
+ include: {
52
+ locale: true,
53
+ },
54
+ },
55
+ },
56
+ },
57
+ },
58
+ },
59
+ },
60
+ });
61
+
62
+ if (!dashboard) {
63
+ throw new NotFoundException(
64
+ getLocaleText('dashboardNotFound', locale, 'Dashboard not found'),
65
+ );
66
+ }
34
67
 
35
- async get(id: number) {
36
- return this.localeService.getModelWithLocale(this.modelName, id);
68
+ return dashboard;
37
69
  }
70
+
71
+ async createDashboard(data: CreateDashboardDTO, locale: string) {
72
+ const dashboard = await this.prismaService.dashboard.create({
73
+ data: {
74
+ slug: data.slug,
75
+ },
76
+ });
38
77
 
39
- async create(data: CreateDTO) {
40
- return this.localeService.createModelWithLocale(
41
- this.modelName,
42
- this.foreignKey,
43
- data,
44
- );
78
+ // Criar locales se fornecidos
79
+ if (data.locale) {
80
+ for (const [localeCode, localeData] of Object.entries(data.locale)) {
81
+ const localeRecord = await this.prismaService.locale.findFirst({
82
+ where: { code: localeCode },
83
+ });
84
+
85
+ if (localeRecord) {
86
+ await this.prismaService.dashboard_locale.create({
87
+ data: {
88
+ dashboard_id: dashboard.id,
89
+ locale_id: localeRecord.id,
90
+ name: localeData.name,
91
+ },
92
+ });
93
+ }
94
+ }
95
+ }
96
+
97
+ return this.getDashboard(dashboard.id, locale);
45
98
  }
99
+
100
+ async updateDashboard(id: number, data: UpdateDashboardDTO, locale: string) {
101
+ await this.prismaService.dashboard.update({
102
+ where: { id },
103
+ data: {
104
+ slug: data.slug,
105
+ },
106
+ });
46
107
 
47
- async update({ id, data }: { id: number; data: UpdateDTO }) {
48
- return this.localeService.updateModelWithLocale(
49
- this.modelName,
50
- this.foreignKey,
51
- id,
52
- data,
53
- );
108
+ // Atualizar locales se fornecidos
109
+ if (data.locale) {
110
+ // Remove locales existentes
111
+ await this.prismaService.dashboard_locale.deleteMany({
112
+ where: { dashboard_id: id },
113
+ });
114
+
115
+ // Criar novos locales
116
+ for (const [localeCode, localeData] of Object.entries(data.locale)) {
117
+ const localeRecord = await this.prismaService.locale.findFirst({
118
+ where: { code: localeCode },
119
+ });
120
+
121
+ if (localeRecord) {
122
+ await this.prismaService.dashboard_locale.create({
123
+ data: {
124
+ dashboard_id: id,
125
+ locale_id: localeRecord.id,
126
+ name: localeData.name,
127
+ },
128
+ });
129
+ }
130
+ }
131
+ }
132
+
133
+ return this.getDashboard(id, locale);
54
134
  }
135
+
136
+ async deleteDashboard(id: number, locale: string) {
137
+ const dashboard = await this.prismaService.dashboard.findUnique({
138
+ where: { id },
139
+ });
55
140
 
56
- async delete({ ids }: DeleteDTO): Promise<{count:number}> {
57
- if (ids == undefined || ids == null) {
58
- throw new BadRequestException(
59
- 'You must select at least one item to delete.',
141
+ if (!dashboard) {
142
+ throw new NotFoundException(
143
+ getLocaleText('dashboardNotFound', locale, 'Dashboard not found'),
60
144
  );
61
145
  }
62
146
 
63
- return this.prismaService.dashboard.deleteMany({
64
- where: {
65
- id: {
66
- in: ids,
67
- },
68
- },
147
+ await this.prismaService.dashboard.delete({
148
+ where: { id },
69
149
  });
150
+ return { success: true };
70
151
  }
71
152
  }
@@ -1,8 +1,17 @@
1
- import { getLocaleText, WithLocaleDTO } from '@hed-hog/api-locale';
2
- import { IsNotEmpty, IsString } from 'class-validator';
1
+ import { getLocaleText } from '@hed-hog/api-locale';
2
+ import { IsNotEmpty, IsObject, IsString } from 'class-validator';
3
3
 
4
- export class CreateDTO extends WithLocaleDTO {
4
+ export class CreateDTO {
5
5
  @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
6
6
  @IsNotEmpty({ message: (args) => getLocaleText('validation.fieldRequired', args.value) })
7
7
  slug: string;
8
+
9
+ @IsObject({
10
+ message: (args) =>
11
+ getLocaleText('validation.localeMustBeObject', args.value),
12
+ })
13
+ @IsNotEmpty({
14
+ message: (args) => getLocaleText('validation.localeRequired', args.value),
15
+ })
16
+ locale: Record<string, { name: string }>;
8
17
  }
@@ -0,0 +1,7 @@
1
+ export * from './create.dto';
2
+ export * from './update.dto';
3
+
4
+ // Aliases para compatibilidade
5
+ export { CreateDTO as CreateDashboardDTO } from './create.dto';
6
+ export { UpdateDTO as UpdateDashboardDTO } from './update.dto';
7
+
@@ -1,4 +1,18 @@
1
- import { PartialType } from '@nestjs/mapped-types';
2
- import { CreateDTO } from './create.dto';
1
+ import { getLocaleText } from '@hed-hog/api-locale';
2
+ import { IsNotEmpty, IsObject, IsOptional, IsString } from 'class-validator';
3
3
 
4
- export class UpdateDTO extends PartialType(CreateDTO) {}
4
+ export class UpdateDTO {
5
+ @IsOptional()
6
+ @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
7
+ slug?: string;
8
+
9
+ @IsOptional()
10
+ @IsObject({
11
+ message: (args) =>
12
+ getLocaleText('validation.localeMustBeObject', args.value),
13
+ })
14
+ @IsNotEmpty({
15
+ message: (args) => getLocaleText('validation.localeRequired', args.value),
16
+ })
17
+ locale?: Record<string, { name: string }>;
18
+ }
@@ -1,5 +1,6 @@
1
- import { Pagination } from '@hed-hog/api-pagination';
1
+ import { Role } from '@hed-hog/api';
2
2
  import { Locale } from '@hed-hog/api-locale';
3
+ import { Pagination } from '@hed-hog/api-pagination';
3
4
  import {
4
5
  Body,
5
6
  Controller,
@@ -10,12 +11,13 @@ import {
10
11
  ParseIntPipe,
11
12
  Patch,
12
13
  Post,
13
- forwardRef,
14
+ forwardRef
14
15
  } from '@nestjs/common';
15
- import { CreateDTO } from './dto/create.dto';
16
- import { UpdateDTO } from './dto/update.dto';
17
16
  import { DashboardComponentService } from './dashboard-component.service';
18
- import { Role, DeleteDTO } from '@hed-hog/api';
17
+ import {
18
+ CreateDashboardComponentDTO,
19
+ UpdateDashboardComponentDTO,
20
+ } from './dto';
19
21
 
20
22
  @Role()
21
23
  @Controller('dashboard-component')
@@ -26,30 +28,31 @@ export class DashboardComponentController {
26
28
  ) {}
27
29
 
28
30
  @Get()
29
- async list(@Locale() locale, @Pagination() paginationParams) {
30
- return this.dashboardComponentService.list(locale, paginationParams);
31
+ getAllComponents(@Pagination() paginationParams) {
32
+ return this.dashboardComponentService.getAllComponents(paginationParams);
31
33
  }
32
34
 
33
35
  @Get(':id')
34
- async get(@Param('id', ParseIntPipe) id: number) {
35
- return this.dashboardComponentService.get(id);
36
+ getComponent(@Param('id', ParseIntPipe) id: number, @Locale() locale: string) {
37
+ return this.dashboardComponentService.getComponent(id, locale);
36
38
  }
37
39
 
38
40
  @Post()
39
- async create(@Body() data: CreateDTO) {
40
- return this.dashboardComponentService.create(data);
41
+ createComponent(@Body() data: CreateDashboardComponentDTO, @Locale() locale: string) {
42
+ return this.dashboardComponentService.createComponent(data, locale);
41
43
  }
42
44
 
43
45
  @Patch(':id')
44
- async update(@Param('id', ParseIntPipe) id: number, @Body() data: UpdateDTO) {
45
- return this.dashboardComponentService.update({
46
- id,
47
- data,
48
- });
46
+ updateComponent(
47
+ @Param('id', ParseIntPipe) id: number,
48
+ @Body() data: UpdateDashboardComponentDTO,
49
+ @Locale() locale: string,
50
+ ) {
51
+ return this.dashboardComponentService.updateComponent(id, data, locale);
49
52
  }
50
53
 
51
- @Delete()
52
- async delete(@Body() data: DeleteDTO) {
53
- return this.dashboardComponentService.delete(data);
54
+ @Delete(':id')
55
+ deleteComponent(@Param('id', ParseIntPipe) id: number, @Locale() locale: string) {
56
+ return this.dashboardComponentService.deleteComponent(id, locale);
54
57
  }
55
58
  }
@@ -1,12 +1,12 @@
1
+ import { LocaleModule } from '@hed-hog/api-locale';
1
2
  import { PaginationModule } from '@hed-hog/api-pagination';
2
3
  import { PrismaModule } from '@hed-hog/api-prisma';
3
- import { LocaleModule } from '@hed-hog/api-locale';
4
4
  import { forwardRef, Module } from '@nestjs/common';
5
- import { DashboardComponentService } from './dashboard-component.service';
6
5
  import { DashboardComponentController } from './dashboard-component.controller';
6
+ import { DashboardComponentService } from './dashboard-component.service';
7
7
 
8
8
  @Module({
9
- imports: [forwardRef(() => LocaleModule), forwardRef(() => PrismaModule)],
9
+ imports: [forwardRef(() => LocaleModule), forwardRef(() => PaginationModule), forwardRef(() => PrismaModule)],
10
10
  controllers: [DashboardComponentController],
11
11
  providers: [DashboardComponentService],
12
12
  exports: [DashboardComponentService],
@@ -1,16 +1,16 @@
1
- import { PaginationDTO } from '@hed-hog/api-pagination';
1
+ import { getLocaleText } from '@hed-hog/api-locale';
2
+ import { PaginationService } from '@hed-hog/api-pagination';
2
3
  import { PrismaService } from '@hed-hog/api-prisma';
3
4
  import {
4
- BadRequestException,
5
+ forwardRef,
5
6
  Inject,
6
7
  Injectable,
7
- forwardRef,
8
+ NotFoundException
8
9
  } from '@nestjs/common';
9
- import { CreateDTO } from './dto/create.dto';
10
- import { DeleteDTO } from '@hed-hog/api';
11
- import { UpdateDTO } from './dto/update.dto';
12
- import { LocaleService } from '@hed-hog/api-locale';
13
-
10
+ import {
11
+ CreateDashboardComponentDTO,
12
+ UpdateDashboardComponentDTO,
13
+ } from './dto';
14
14
  @Injectable()
15
15
  export class DashboardComponentService {
16
16
  private readonly modelName = 'dashboard_component';
@@ -19,52 +19,141 @@ export class DashboardComponentService {
19
19
  constructor(
20
20
  @Inject(forwardRef(() => PrismaService))
21
21
  private readonly prismaService: PrismaService,
22
- @Inject(forwardRef(() => LocaleService))
23
- private readonly localeService: LocaleService,
22
+ @Inject(forwardRef(() => PaginationService))
23
+ private readonly paginationService: PaginationService,
24
24
  ) {}
25
25
 
26
- async list(locale: string, paginationParams: PaginationDTO) {
27
- return this.localeService.listModelWithLocale(
28
- locale,
29
- this.modelName,
26
+ async getAllComponents(paginationParams) {
27
+ return this.paginationService.paginate(
28
+ this.prismaService.dashboard_component,
30
29
  paginationParams,
30
+ {
31
+ include: {
32
+ dashboard_component_locale: {
33
+ include: {
34
+ locale: true,
35
+ },
36
+ },
37
+ },
38
+ orderBy: {
39
+ created_at: 'desc',
40
+ },
41
+ },
42
+ 'dashboardComponent',
31
43
  );
32
44
  }
33
45
 
34
- async get(id: number) {
35
- return this.localeService.getModelWithLocale(this.modelName, id);
46
+ async getComponent(id: number, locale: string) {
47
+ const component = await this.prismaService.dashboard_component.findUnique({
48
+ where: { id },
49
+ include: {
50
+ dashboard_component_locale: {
51
+ include: {
52
+ locale: true,
53
+ },
54
+ },
55
+ },
56
+ });
57
+
58
+ if (!component) {
59
+ throw new NotFoundException(
60
+ getLocaleText('dashboardComponentNotFound', locale, 'Dashboard component not found'),
61
+ );
62
+ }
63
+
64
+ return component;
36
65
  }
37
66
 
38
- async create(data: CreateDTO) {
39
- return this.localeService.createModelWithLocale(
40
- this.modelName,
41
- this.foreignKey,
42
- data,
43
- );
67
+ async createComponent(data: CreateDashboardComponentDTO, locale: string) {
68
+ const component = await this.prismaService.dashboard_component.create({
69
+ data: {
70
+ slug: data.slug,
71
+ path: data.path,
72
+ min_width: data.min_width,
73
+ max_width: data.max_width,
74
+ min_height: data.min_height,
75
+ max_height: data.max_height,
76
+ width: data.width,
77
+ height: data.height,
78
+ is_resizable: data.is_resizable ?? true,
79
+ },
80
+ });
81
+
82
+ if (data.locale) {
83
+ for (const [localeCode, localeData] of Object.entries(data.locale)) {
84
+ const localeRecord = await this.prismaService.locale.findFirst({
85
+ where: { code: localeCode },
86
+ });
87
+
88
+ if (localeRecord) {
89
+ await this.prismaService.dashboard_component_locale.create({
90
+ data: {
91
+ dashboard_component_id: component.id,
92
+ locale_id: localeRecord.id,
93
+ name: localeData.name,
94
+ },
95
+ });
96
+ }
97
+ }
98
+ }
99
+
100
+ return this.getComponent(component.id, locale);
44
101
  }
45
102
 
46
- async update({ id, data }: { id: number; data: UpdateDTO }) {
47
- return this.localeService.updateModelWithLocale(
48
- this.modelName,
49
- this.foreignKey,
50
- id,
51
- data,
52
- );
103
+ async updateComponent(id: number, data: UpdateDashboardComponentDTO, locale: string) {
104
+ await this.prismaService.dashboard_component.update({
105
+ where: { id },
106
+ data: {
107
+ slug: data.slug,
108
+ path: data.path,
109
+ min_width: data.min_width,
110
+ max_width: data.max_width,
111
+ min_height: data.min_height,
112
+ max_height: data.max_height,
113
+ width: data.width,
114
+ height: data.height,
115
+ is_resizable: data.is_resizable,
116
+ },
117
+ });
118
+
119
+ if (data.locale) {
120
+ await this.prismaService.dashboard_component_locale.deleteMany({
121
+ where: { dashboard_component_id: id },
122
+ });
123
+
124
+ for (const [localeCode, localeData] of Object.entries(data.locale)) {
125
+ const localeRecord = await this.prismaService.locale.findFirst({
126
+ where: { code: localeCode },
127
+ });
128
+
129
+ if (localeRecord) {
130
+ await this.prismaService.dashboard_component_locale.create({
131
+ data: {
132
+ dashboard_component_id: id,
133
+ locale_id: localeRecord.id,
134
+ name: localeData.name,
135
+ },
136
+ });
137
+ }
138
+ }
139
+ }
140
+
141
+ return this.getComponent(id, locale);
53
142
  }
54
143
 
55
- async delete({ ids }: DeleteDTO): Promise<{count:number}> {
56
- if (ids == undefined || ids == null) {
57
- throw new BadRequestException(
58
- 'You must select at least one item to delete.',
144
+ async deleteComponent(id: number, locale: string) {
145
+ const component = await this.prismaService.dashboard_component.findUnique({
146
+ where: { id },
147
+ });
148
+
149
+ if (!component) {
150
+ throw new NotFoundException(
151
+ getLocaleText('dashboardComponentNotFound', locale, 'Dashboard component not found'),
59
152
  );
60
153
  }
61
154
 
62
- return this.prismaService.dashboard_component.deleteMany({
63
- where: {
64
- id: {
65
- in: ids,
66
- },
67
- },
155
+ return this.prismaService.dashboard_component.delete({
156
+ where: { id },
68
157
  });
69
158
  }
70
159
  }
@@ -1,7 +1,7 @@
1
- import { getLocaleText, WithLocaleDTO } from '@hed-hog/api-locale';
2
- import { IsBoolean, IsNumber, IsOptional, IsString } from 'class-validator';
1
+ import { getLocaleText } from '@hed-hog/api-locale';
2
+ import { IsBoolean, IsNotEmpty, IsNumber, IsObject, IsOptional, IsString } from 'class-validator';
3
3
 
4
- export class CreateDTO extends WithLocaleDTO {
4
+ export class CreateDTO {
5
5
  @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
6
6
  slug: string;
7
7
 
@@ -33,4 +33,13 @@ export class CreateDTO extends WithLocaleDTO {
33
33
  @IsOptional()
34
34
  @IsBoolean({ message: (args) => getLocaleText('validation.booleanRequired', args.value) })
35
35
  is_resizable?: boolean;
36
+
37
+ @IsObject({
38
+ message: (args) =>
39
+ getLocaleText('validation.localeMustBeObject', args.value),
40
+ })
41
+ @IsNotEmpty({
42
+ message: (args) => getLocaleText('validation.localeRequired', args.value),
43
+ })
44
+ locale: Record<string, { name: string }>;
36
45
  }
@@ -0,0 +1,7 @@
1
+ export * from './create.dto';
2
+ export * from './update.dto';
3
+
4
+ // Aliases para compatibilidade
5
+ export { CreateDTO as CreateDashboardComponentDTO } from './create.dto';
6
+ export { UpdateDTO as UpdateDashboardComponentDTO } from './update.dto';
7
+