@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.
- package/dist/dashboard/dashboard/dashboard.controller.d.ts +214 -9
- package/dist/dashboard/dashboard/dashboard.controller.d.ts.map +1 -1
- package/dist/dashboard/dashboard/dashboard.controller.js +35 -35
- package/dist/dashboard/dashboard/dashboard.controller.js.map +1 -1
- package/dist/dashboard/dashboard/dashboard.module.d.ts +1 -1
- package/dist/dashboard/dashboard/dashboard.module.d.ts.map +1 -1
- package/dist/dashboard/dashboard/dashboard.module.js +11 -6
- package/dist/dashboard/dashboard/dashboard.module.js.map +1 -1
- package/dist/dashboard/dashboard/dashboard.service.d.ts +217 -16
- package/dist/dashboard/dashboard/dashboard.service.d.ts.map +1 -1
- package/dist/dashboard/dashboard/dashboard.service.js +115 -28
- package/dist/dashboard/dashboard/dashboard.service.js.map +1 -1
- package/dist/dashboard/dashboard/dto/create.dto.d.ts +4 -2
- package/dist/dashboard/dashboard/dto/create.dto.d.ts.map +1 -1
- package/dist/dashboard/dashboard/dto/create.dto.js +10 -1
- package/dist/dashboard/dashboard/dto/create.dto.js.map +1 -1
- package/dist/dashboard/dashboard/dto/index.d.ts +5 -0
- package/dist/dashboard/dashboard/dto/index.d.ts.map +1 -0
- package/dist/dashboard/dashboard/dto/index.js +25 -0
- package/dist/dashboard/dashboard/dto/index.js.map +1 -0
- package/dist/dashboard/dashboard/dto/update.dto.d.ts +5 -4
- package/dist/dashboard/dashboard/dto/update.dto.d.ts.map +1 -1
- package/dist/dashboard/dashboard/dto/update.dto.js +27 -3
- package/dist/dashboard/dashboard/dto/update.dto.js.map +1 -1
- package/dist/dashboard/dashboard-component/dashboard-component.controller.d.ts +114 -9
- package/dist/dashboard/dashboard-component/dashboard-component.controller.d.ts.map +1 -1
- package/dist/dashboard/dashboard-component/dashboard-component.controller.js +35 -36
- package/dist/dashboard/dashboard-component/dashboard-component.controller.js.map +1 -1
- package/dist/dashboard/dashboard-component/dashboard-component.module.js +4 -3
- package/dist/dashboard/dashboard-component/dashboard-component.module.js.map +1 -1
- package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts +116 -15
- package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts.map +1 -1
- package/dist/dashboard/dashboard-component/dashboard-component.service.js +109 -22
- package/dist/dashboard/dashboard-component/dashboard-component.service.js.map +1 -1
- package/dist/dashboard/dashboard-component/dto/create.dto.d.ts +4 -2
- package/dist/dashboard/dashboard-component/dto/create.dto.d.ts.map +1 -1
- package/dist/dashboard/dashboard-component/dto/create.dto.js +10 -1
- package/dist/dashboard/dashboard-component/dto/create.dto.js.map +1 -1
- package/dist/dashboard/dashboard-component/dto/index.d.ts +5 -0
- package/dist/dashboard/dashboard-component/dto/index.d.ts.map +1 -0
- package/dist/dashboard/dashboard-component/dto/index.js +25 -0
- package/dist/dashboard/dashboard-component/dto/index.js.map +1 -0
- package/dist/dashboard/dashboard-component/dto/update.dto.d.ts +13 -4
- package/dist/dashboard/dashboard-component/dto/update.dto.d.ts.map +1 -1
- package/dist/dashboard/dashboard-component/dto/update.dto.js +67 -3
- package/dist/dashboard/dashboard-component/dto/update.dto.js.map +1 -1
- package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts +56 -0
- package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts.map +1 -1
- package/dist/dashboard/dashboard-core/dashboard-core.controller.js +65 -0
- package/dist/dashboard/dashboard-core/dashboard-core.controller.js.map +1 -1
- package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts +52 -0
- package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts.map +1 -1
- package/dist/dashboard/dashboard-core/dashboard-core.service.js +221 -0
- package/dist/dashboard/dashboard-core/dashboard-core.service.js.map +1 -1
- package/dist/dashboard/dashboard-item/dashboard-item.controller.d.ts +26 -29
- package/dist/dashboard/dashboard-item/dashboard-item.controller.d.ts.map +1 -1
- package/dist/dashboard/dashboard-item/dashboard-item.controller.js +24 -43
- package/dist/dashboard/dashboard-item/dashboard-item.controller.js.map +1 -1
- package/dist/dashboard/dashboard-item/dashboard-item.service.d.ts +30 -34
- package/dist/dashboard/dashboard-item/dashboard-item.service.d.ts.map +1 -1
- package/dist/dashboard/dashboard-item/dashboard-item.service.js +51 -35
- package/dist/dashboard/dashboard-item/dashboard-item.service.js.map +1 -1
- package/dist/dashboard/dashboard-item/dto/index.d.ts +5 -0
- package/dist/dashboard/dashboard-item/dto/index.d.ts.map +1 -0
- package/dist/dashboard/dashboard-item/dto/index.js +25 -0
- package/dist/dashboard/dashboard-item/dto/index.js.map +1 -0
- package/dist/dashboard/dashboard-item/dto/update.dto.d.ts +7 -4
- package/dist/dashboard/dashboard-item/dto/update.dto.d.ts.map +1 -1
- package/dist/dashboard/dashboard-item/dto/update.dto.js +42 -3
- package/dist/dashboard/dashboard-item/dto/update.dto.js.map +1 -1
- package/dist/dashboard/dashboard.module.js +1 -1
- package/dist/dashboard/dashboard.module.js.map +1 -1
- package/hedhog/data/route.yaml +44 -14
- package/hedhog/query/dashboard-seed.sql +131 -0
- package/package.json +1 -1
- package/src/dashboard/dashboard/dashboard.controller.ts +26 -23
- package/src/dashboard/dashboard/dashboard.module.ts +7 -2
- package/src/dashboard/dashboard/dashboard.service.ts +125 -44
- package/src/dashboard/dashboard/dto/create.dto.ts +12 -3
- package/src/dashboard/dashboard/dto/index.ts +7 -0
- package/src/dashboard/dashboard/dto/update.dto.ts +17 -3
- package/src/dashboard/dashboard-component/dashboard-component.controller.ts +22 -19
- package/src/dashboard/dashboard-component/dashboard-component.module.ts +3 -3
- package/src/dashboard/dashboard-component/dashboard-component.service.ts +128 -39
- package/src/dashboard/dashboard-component/dto/create.dto.ts +12 -3
- package/src/dashboard/dashboard-component/dto/index.ts +7 -0
- package/src/dashboard/dashboard-component/dto/update.dto.ts +49 -3
- package/src/dashboard/dashboard-core/dashboard-core.controller.ts +53 -2
- package/src/dashboard/dashboard-core/dashboard-core.service.ts +271 -0
- package/src/dashboard/dashboard-item/dashboard-item.controller.ts +17 -26
- package/src/dashboard/dashboard-item/dashboard-item.service.ts +55 -47
- package/src/dashboard/dashboard-item/dto/index.ts +7 -0
- package/src/dashboard/dashboard-item/dto/update.dto.ts +27 -3
- package/src/dashboard/dashboard.module.ts +2 -2
- package/src/language/en.json +4 -1
- package/src/language/pt.json +4 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
16
|
-
|
|
15
|
+
import {
|
|
16
|
+
CreateDashboardDTO,
|
|
17
|
+
UpdateDashboardDTO,
|
|
18
|
+
} from './dto';
|
|
17
19
|
@Role()
|
|
18
|
-
@Controller('
|
|
20
|
+
@Controller('dashboard')
|
|
19
21
|
export class DashboardController {
|
|
20
22
|
constructor(private readonly dashboardService: DashboardService) {}
|
|
21
23
|
|
|
22
24
|
@Get()
|
|
23
|
-
|
|
24
|
-
return this.dashboardService.
|
|
25
|
+
getAllDashboards(@Pagination() paginationParams, @Locale() locale: string) {
|
|
26
|
+
return this.dashboardService.getAllDashboards(paginationParams, locale);
|
|
25
27
|
}
|
|
26
|
-
|
|
28
|
+
|
|
27
29
|
@Get(':id')
|
|
28
|
-
|
|
29
|
-
return this.dashboardService.
|
|
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
|
-
|
|
34
|
-
return this.dashboardService.
|
|
35
|
+
createDashboard(@Body() data: CreateDashboardDTO, @Locale() locale: string) {
|
|
36
|
+
return this.dashboardService.createDashboard(data, locale);
|
|
35
37
|
}
|
|
36
|
-
|
|
38
|
+
|
|
37
39
|
@Patch(':id')
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
47
|
-
return this.dashboardService.
|
|
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: [
|
|
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
|
|
18
|
+
export class DashboardCrudModule {}
|
|
@@ -1,71 +1,152 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
17
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
}
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getLocaleText } from '@hed-hog/api-locale';
|
|
2
|
+
import { IsNotEmpty, IsObject, IsOptional, IsString } from 'class-validator';
|
|
3
3
|
|
|
4
|
-
export class UpdateDTO
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
30
|
-
return this.dashboardComponentService.
|
|
31
|
+
getAllComponents(@Pagination() paginationParams) {
|
|
32
|
+
return this.dashboardComponentService.getAllComponents(paginationParams);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
@Get(':id')
|
|
34
|
-
|
|
35
|
-
return this.dashboardComponentService.
|
|
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
|
-
|
|
40
|
-
return this.dashboardComponentService.
|
|
41
|
+
createComponent(@Body() data: CreateDashboardComponentDTO, @Locale() locale: string) {
|
|
42
|
+
return this.dashboardComponentService.createComponent(data, locale);
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
@Patch(':id')
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
53
|
-
return this.dashboardComponentService.
|
|
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 {
|
|
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
|
-
|
|
5
|
+
forwardRef,
|
|
5
6
|
Inject,
|
|
6
7
|
Injectable,
|
|
7
|
-
|
|
8
|
+
NotFoundException
|
|
8
9
|
} from '@nestjs/common';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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(() =>
|
|
23
|
-
private readonly
|
|
22
|
+
@Inject(forwardRef(() => PaginationService))
|
|
23
|
+
private readonly paginationService: PaginationService,
|
|
24
24
|
) {}
|
|
25
25
|
|
|
26
|
-
async
|
|
27
|
-
return this.
|
|
28
|
-
|
|
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
|
|
35
|
-
|
|
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
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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.
|
|
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
|
|
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
|
|
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
|
}
|