@hed-hog/core 0.0.169 → 0.0.171
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 +3 -15
- package/dist/dashboard/dashboard/dashboard.controller.d.ts.map +1 -1
- package/dist/dashboard/dashboard/dashboard.service.d.ts +3 -15
- package/dist/dashboard/dashboard/dashboard.service.d.ts.map +1 -1
- package/dist/dashboard/dashboard-component/dashboard-component.controller.d.ts +17 -20
- package/dist/dashboard/dashboard-component/dashboard-component.controller.d.ts.map +1 -1
- package/dist/dashboard/dashboard-component/dashboard-component.controller.js +15 -3
- package/dist/dashboard/dashboard-component/dashboard-component.controller.js.map +1 -1
- package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts +15 -22
- package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts.map +1 -1
- package/dist/dashboard/dashboard-component/dashboard-component.service.js +83 -12
- package/dist/dashboard/dashboard-component/dashboard-component.service.js.map +1 -1
- package/dist/dashboard/dashboard-component/dto/create.dto.d.ts +0 -4
- package/dist/dashboard/dashboard-component/dto/create.dto.d.ts.map +1 -1
- package/dist/dashboard/dashboard-component/dto/create.dto.js +0 -19
- package/dist/dashboard/dashboard-component/dto/create.dto.js.map +1 -1
- package/dist/dashboard/dashboard-component/dto/update.dto.d.ts +0 -4
- package/dist/dashboard/dashboard-component/dto/update.dto.d.ts.map +1 -1
- package/dist/dashboard/dashboard-component/dto/update.dto.js +0 -20
- package/dist/dashboard/dashboard-component/dto/update.dto.js.map +1 -1
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.controller.d.ts +122 -0
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.controller.d.ts.map +1 -0
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.controller.js +83 -0
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.controller.js.map +1 -0
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.module.d.ts +3 -0
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.module.d.ts.map +1 -0
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.module.js +26 -0
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.module.js.map +1 -0
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.service.d.ts +125 -0
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.service.d.ts.map +1 -0
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.service.js +143 -0
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.service.js.map +1 -0
- package/dist/dashboard/dashboard-component-role/dto/create.dto.d.ts +5 -0
- package/dist/dashboard/dashboard-component-role/dto/create.dto.d.ts.map +1 -0
- package/dist/dashboard/dashboard-component-role/dto/create.dto.js +25 -0
- package/dist/dashboard/dashboard-component-role/dto/create.dto.js.map +1 -0
- package/dist/dashboard/dashboard-component-role/dto/index.d.ts +2 -0
- package/dist/dashboard/dashboard-component-role/dto/index.d.ts.map +1 -0
- package/dist/dashboard/dashboard-component-role/dto/index.js +18 -0
- package/dist/dashboard/dashboard-component-role/dto/index.js.map +1 -0
- package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts +36 -22
- package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts.map +1 -1
- package/dist/dashboard/dashboard-core/dashboard-core.controller.js +0 -9
- package/dist/dashboard/dashboard-core/dashboard-core.controller.js.map +1 -1
- package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts +36 -22
- package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts.map +1 -1
- package/dist/dashboard/dashboard-core/dashboard-core.service.js +123 -51
- package/dist/dashboard/dashboard-core/dashboard-core.service.js.map +1 -1
- package/dist/dashboard/dashboard-item/dashboard-item.controller.d.ts +0 -4
- package/dist/dashboard/dashboard-item/dashboard-item.controller.d.ts.map +1 -1
- package/dist/dashboard/dashboard-item/dashboard-item.service.d.ts +0 -4
- package/dist/dashboard/dashboard-item/dashboard-item.service.d.ts.map +1 -1
- package/dist/dashboard/dashboard.module.d.ts.map +1 -1
- package/dist/dashboard/dashboard.module.js +2 -0
- package/dist/dashboard/dashboard.module.js.map +1 -1
- package/hedhog/data/dashboard_component.yaml +16 -16
- package/hedhog/data/dashboard_component_role.yaml +48 -0
- package/hedhog/data/dashboard_item.yaml +28 -28
- package/hedhog/data/menu.yaml +3 -3
- package/hedhog/data/route.yaml +30 -0
- package/hedhog/table/dashboard_component_role.yaml +16 -0
- package/package.json +2 -2
- package/src/dashboard/dashboard-component/dashboard-component.controller.ts +12 -3
- package/src/dashboard/dashboard-component/dashboard-component.service.ts +104 -14
- package/src/dashboard/dashboard-component/dto/create.dto.ts +0 -15
- package/src/dashboard/dashboard-component/dto/update.dto.ts +0 -16
- package/src/dashboard/dashboard-component-role/dashboard-component-role.controller.ts +57 -0
- package/src/dashboard/dashboard-component-role/dashboard-component-role.module.ts +13 -0
- package/src/dashboard/dashboard-component-role/dashboard-component-role.service.ts +170 -0
- package/src/dashboard/dashboard-component-role/dto/create.dto.ts +9 -0
- package/src/dashboard/dashboard-component-role/dto/index.ts +1 -0
- package/src/dashboard/dashboard-core/dashboard-core.controller.ts +0 -5
- package/src/dashboard/dashboard-core/dashboard-core.service.ts +152 -54
- package/src/dashboard/dashboard.module.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hed-hog/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.171",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"sharp": "^0.34.2",
|
|
30
30
|
"speakeasy": "^2.0.0",
|
|
31
31
|
"uuid": "^11.1.0",
|
|
32
|
-
"@hed-hog/api-prisma": "0.0.4",
|
|
33
32
|
"@hed-hog/api-locale": "0.0.11",
|
|
33
|
+
"@hed-hog/api-prisma": "0.0.4",
|
|
34
34
|
"@hed-hog/api-mail": "0.0.7",
|
|
35
35
|
"@hed-hog/api": "0.0.3",
|
|
36
36
|
"@hed-hog/types": "0.0.1",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Role } from '@hed-hog/api';
|
|
1
|
+
import { Role, User } 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 {
|
|
@@ -32,9 +32,18 @@ export class DashboardComponentController {
|
|
|
32
32
|
return this.dashboardComponentService.getAllComponents(paginationParams);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
@Get('user')
|
|
36
|
+
getAllComponentsByUserRole(@Pagination() paginationParams, @User() { id }) {
|
|
37
|
+
return this.dashboardComponentService.getAllComponentsByUserRole(paginationParams, id);
|
|
38
|
+
}
|
|
39
|
+
|
|
35
40
|
@Get(':id')
|
|
36
|
-
getComponent(
|
|
37
|
-
|
|
41
|
+
getComponent(
|
|
42
|
+
@Param('id', ParseIntPipe) id: number,
|
|
43
|
+
@Locale() locale: string,
|
|
44
|
+
@User() { id: userId },
|
|
45
|
+
) {
|
|
46
|
+
return this.dashboardComponentService.getComponent(id, locale, userId);
|
|
38
47
|
}
|
|
39
48
|
|
|
40
49
|
@Post()
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getLocaleText } from '@hed-hog/api-locale';
|
|
2
|
-
import { PaginationService } from '@hed-hog/api-pagination';
|
|
2
|
+
import { PaginationDTO, PaginationService } from '@hed-hog/api-pagination';
|
|
3
3
|
import { PrismaService } from '@hed-hog/api-prisma';
|
|
4
4
|
import {
|
|
5
5
|
forwardRef,
|
|
@@ -20,7 +20,7 @@ export class DashboardComponentService {
|
|
|
20
20
|
private readonly paginationService: PaginationService,
|
|
21
21
|
) {}
|
|
22
22
|
|
|
23
|
-
async getAllComponents(paginationParams) {
|
|
23
|
+
async getAllComponents(paginationParams: PaginationDTO) {
|
|
24
24
|
const fields = ['slug']
|
|
25
25
|
const OR = this.prismaService.createInsensitiveSearch(
|
|
26
26
|
fields,
|
|
@@ -52,7 +52,7 @@ export class DashboardComponentService {
|
|
|
52
52
|
},
|
|
53
53
|
},
|
|
54
54
|
where: {
|
|
55
|
-
OR
|
|
55
|
+
OR,
|
|
56
56
|
},
|
|
57
57
|
orderBy: {
|
|
58
58
|
created_at: 'desc',
|
|
@@ -62,7 +62,105 @@ export class DashboardComponentService {
|
|
|
62
62
|
);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
async
|
|
65
|
+
async getAllComponentsByUserRole(paginationParams: PaginationDTO, userId: number) {
|
|
66
|
+
const userRoles = await this.prismaService.role_user.findMany({
|
|
67
|
+
where: { user_id: userId },
|
|
68
|
+
select: { role_id: true },
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const userRoleIds = userRoles.map((ur) => ur.role_id);
|
|
72
|
+
|
|
73
|
+
const fields = ['slug']
|
|
74
|
+
const OR = this.prismaService.createInsensitiveSearch(
|
|
75
|
+
fields,
|
|
76
|
+
paginationParams,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
if (paginationParams.search) {
|
|
80
|
+
OR.push({
|
|
81
|
+
dashboard_component_locale: {
|
|
82
|
+
some: {
|
|
83
|
+
name: {
|
|
84
|
+
contains: paginationParams.search,
|
|
85
|
+
mode: 'insensitive',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return this.paginationService.paginate(
|
|
93
|
+
this.prismaService.dashboard_component,
|
|
94
|
+
paginationParams,
|
|
95
|
+
{
|
|
96
|
+
include: {
|
|
97
|
+
dashboard_component_locale: {
|
|
98
|
+
include: {
|
|
99
|
+
locale: true,
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
where: {
|
|
104
|
+
AND: [
|
|
105
|
+
{
|
|
106
|
+
dashboard_component_role: {
|
|
107
|
+
some: {
|
|
108
|
+
role_id: {
|
|
109
|
+
in: userRoleIds,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
OR,
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
orderBy: {
|
|
120
|
+
created_at: 'desc',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
'dashboardComponent',
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async getComponent(id: number, locale: string, userId?: number) {
|
|
128
|
+
if (userId) {
|
|
129
|
+
const userRoles = await this.prismaService.user_role.findMany({
|
|
130
|
+
where: { user_id: userId },
|
|
131
|
+
select: { role_id: true },
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const userRoleIds = userRoles.map((ur) => ur.role_id);
|
|
135
|
+
const component = await this.prismaService.dashboard_component.findFirst({
|
|
136
|
+
where: {
|
|
137
|
+
id,
|
|
138
|
+
dashboard_component_role: {
|
|
139
|
+
some: {
|
|
140
|
+
role_id: {
|
|
141
|
+
in: userRoleIds,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
include: {
|
|
147
|
+
dashboard_component_locale: {
|
|
148
|
+
include: {
|
|
149
|
+
locale: true,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
if (!component) {
|
|
156
|
+
throw new NotFoundException(
|
|
157
|
+
getLocaleText('dashboardComponentNotFound', locale, 'Dashboard component not found'),
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return component;
|
|
162
|
+
}
|
|
163
|
+
|
|
66
164
|
const component = await this.prismaService.dashboard_component.findUnique({
|
|
67
165
|
where: { id },
|
|
68
166
|
include: {
|
|
@@ -87,7 +185,6 @@ export class DashboardComponentService {
|
|
|
87
185
|
const component = await this.prismaService.dashboard_component.create({
|
|
88
186
|
data: {
|
|
89
187
|
slug: data.slug,
|
|
90
|
-
path: data.path,
|
|
91
188
|
min_width: data.min_width,
|
|
92
189
|
max_width: data.max_width,
|
|
93
190
|
min_height: data.min_height,
|
|
@@ -95,9 +192,6 @@ export class DashboardComponentService {
|
|
|
95
192
|
width: data.width,
|
|
96
193
|
height: data.height,
|
|
97
194
|
is_resizable: data.is_resizable ?? true,
|
|
98
|
-
stat_key: data.stat_key || null,
|
|
99
|
-
icon: data.icon || null,
|
|
100
|
-
color: data.color || null,
|
|
101
195
|
},
|
|
102
196
|
});
|
|
103
197
|
|
|
@@ -113,7 +207,7 @@ export class DashboardComponentService {
|
|
|
113
207
|
dashboard_component_id: component.id,
|
|
114
208
|
locale_id: localeRecord.id,
|
|
115
209
|
name: localeData.name,
|
|
116
|
-
description: localeData.description ||
|
|
210
|
+
description: localeData.description || '',
|
|
117
211
|
},
|
|
118
212
|
});
|
|
119
213
|
}
|
|
@@ -128,7 +222,6 @@ export class DashboardComponentService {
|
|
|
128
222
|
where: { id },
|
|
129
223
|
data: {
|
|
130
224
|
slug: data.slug,
|
|
131
|
-
path: data.path,
|
|
132
225
|
min_width: data.min_width,
|
|
133
226
|
max_width: data.max_width,
|
|
134
227
|
min_height: data.min_height,
|
|
@@ -136,9 +229,6 @@ export class DashboardComponentService {
|
|
|
136
229
|
width: data.width,
|
|
137
230
|
height: data.height,
|
|
138
231
|
is_resizable: data.is_resizable,
|
|
139
|
-
stat_key: data.stat_key,
|
|
140
|
-
icon: data.icon,
|
|
141
|
-
color: data.color,
|
|
142
232
|
},
|
|
143
233
|
});
|
|
144
234
|
|
|
@@ -158,7 +248,7 @@ export class DashboardComponentService {
|
|
|
158
248
|
dashboard_component_id: id,
|
|
159
249
|
locale_id: localeRecord.id,
|
|
160
250
|
name: localeData.name,
|
|
161
|
-
description: localeData.description ||
|
|
251
|
+
description: localeData.description || '',
|
|
162
252
|
},
|
|
163
253
|
});
|
|
164
254
|
}
|
|
@@ -5,9 +5,6 @@ export class CreateDTO {
|
|
|
5
5
|
@IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
|
|
6
6
|
slug: string;
|
|
7
7
|
|
|
8
|
-
@IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
|
|
9
|
-
path: string;
|
|
10
|
-
|
|
11
8
|
@IsOptional()
|
|
12
9
|
@IsNumber({}, { message: (args) => getLocaleText('validation.numberRequired', args.value) })
|
|
13
10
|
min_width?: number;
|
|
@@ -34,18 +31,6 @@ export class CreateDTO {
|
|
|
34
31
|
@IsBoolean({ message: (args) => getLocaleText('validation.booleanRequired', args.value) })
|
|
35
32
|
is_resizable?: boolean;
|
|
36
33
|
|
|
37
|
-
@IsOptional()
|
|
38
|
-
@IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
|
|
39
|
-
stat_key?: string;
|
|
40
|
-
|
|
41
|
-
@IsOptional()
|
|
42
|
-
@IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
|
|
43
|
-
icon?: string;
|
|
44
|
-
|
|
45
|
-
@IsOptional()
|
|
46
|
-
@IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
|
|
47
|
-
color?: string;
|
|
48
|
-
|
|
49
34
|
@IsObject({
|
|
50
35
|
message: (args) =>
|
|
51
36
|
getLocaleText('validation.localeMustBeObject', args.value),
|
|
@@ -6,10 +6,6 @@ export class UpdateDTO {
|
|
|
6
6
|
@IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
|
|
7
7
|
slug?: string;
|
|
8
8
|
|
|
9
|
-
@IsOptional()
|
|
10
|
-
@IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
|
|
11
|
-
path?: string;
|
|
12
|
-
|
|
13
9
|
@IsOptional()
|
|
14
10
|
@IsNumber({}, { message: (args) => getLocaleText('validation.numberRequired', args.value) })
|
|
15
11
|
min_width?: number;
|
|
@@ -38,18 +34,6 @@ export class UpdateDTO {
|
|
|
38
34
|
@IsBoolean({ message: (args) => getLocaleText('validation.booleanRequired', args.value) })
|
|
39
35
|
is_resizable?: boolean;
|
|
40
36
|
|
|
41
|
-
@IsOptional()
|
|
42
|
-
@IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
|
|
43
|
-
stat_key?: string;
|
|
44
|
-
|
|
45
|
-
@IsOptional()
|
|
46
|
-
@IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
|
|
47
|
-
icon?: string;
|
|
48
|
-
|
|
49
|
-
@IsOptional()
|
|
50
|
-
@IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
|
|
51
|
-
color?: string;
|
|
52
|
-
|
|
53
37
|
@IsOptional()
|
|
54
38
|
@IsObject({
|
|
55
39
|
message: (args) =>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Role } from '@hed-hog/api';
|
|
2
|
+
import { Locale } from '@hed-hog/api-locale';
|
|
3
|
+
import { Pagination } from '@hed-hog/api-pagination';
|
|
4
|
+
import {
|
|
5
|
+
Body,
|
|
6
|
+
Controller,
|
|
7
|
+
Delete,
|
|
8
|
+
Get,
|
|
9
|
+
Inject,
|
|
10
|
+
Param,
|
|
11
|
+
ParseIntPipe,
|
|
12
|
+
Post,
|
|
13
|
+
Query,
|
|
14
|
+
forwardRef,
|
|
15
|
+
} from '@nestjs/common';
|
|
16
|
+
import { DashboardComponentRoleService } from './dashboard-component-role.service';
|
|
17
|
+
import { CreateDashboardComponentRoleDTO } from './dto';
|
|
18
|
+
|
|
19
|
+
@Role()
|
|
20
|
+
@Controller('dashboard-component-role')
|
|
21
|
+
export class DashboardComponentRoleController {
|
|
22
|
+
constructor(
|
|
23
|
+
@Inject(forwardRef(() => DashboardComponentRoleService))
|
|
24
|
+
private readonly service: DashboardComponentRoleService,
|
|
25
|
+
) {}
|
|
26
|
+
|
|
27
|
+
@Get()
|
|
28
|
+
getAll(
|
|
29
|
+
@Pagination() paginationParams,
|
|
30
|
+
@Locale() locale: string,
|
|
31
|
+
@Query('componentId') componentId?: string,
|
|
32
|
+
) {
|
|
33
|
+
if (componentId) {
|
|
34
|
+
return this.service.getAllByComponent(parseInt(componentId), locale);
|
|
35
|
+
}
|
|
36
|
+
return this.service.getAll(paginationParams, locale);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Post()
|
|
40
|
+
create(@Body() data: CreateDashboardComponentRoleDTO, @Locale() locale: string) {
|
|
41
|
+
return this.service.create(data, locale);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Delete(':id')
|
|
45
|
+
delete(@Param('id', ParseIntPipe) id: number, @Locale() locale: string) {
|
|
46
|
+
return this.service.delete(id, locale);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Delete('component/:componentId/role/:roleId')
|
|
50
|
+
deleteByComponentAndRole(
|
|
51
|
+
@Param('componentId', ParseIntPipe) componentId: number,
|
|
52
|
+
@Param('roleId', ParseIntPipe) roleId: number,
|
|
53
|
+
@Locale() locale: string,
|
|
54
|
+
) {
|
|
55
|
+
return this.service.deleteByComponentAndRole(componentId, roleId, locale);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PaginationModule } from '@hed-hog/api-pagination';
|
|
2
|
+
import { PrismaModule } from '@hed-hog/api-prisma';
|
|
3
|
+
import { forwardRef, Module } from '@nestjs/common';
|
|
4
|
+
import { DashboardComponentRoleController } from './dashboard-component-role.controller';
|
|
5
|
+
import { DashboardComponentRoleService } from './dashboard-component-role.service';
|
|
6
|
+
|
|
7
|
+
@Module({
|
|
8
|
+
imports: [forwardRef(() => PrismaModule), forwardRef(() => PaginationModule)],
|
|
9
|
+
controllers: [DashboardComponentRoleController],
|
|
10
|
+
providers: [DashboardComponentRoleService],
|
|
11
|
+
exports: [DashboardComponentRoleService],
|
|
12
|
+
})
|
|
13
|
+
export class DashboardComponentRoleModule {}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { getLocaleText } from '@hed-hog/api-locale';
|
|
2
|
+
import { PaginationService } from '@hed-hog/api-pagination';
|
|
3
|
+
import { PrismaService } from '@hed-hog/api-prisma';
|
|
4
|
+
import {
|
|
5
|
+
forwardRef,
|
|
6
|
+
Inject,
|
|
7
|
+
Injectable,
|
|
8
|
+
NotFoundException,
|
|
9
|
+
} from '@nestjs/common';
|
|
10
|
+
import { CreateDashboardComponentRoleDTO } from './dto';
|
|
11
|
+
|
|
12
|
+
@Injectable()
|
|
13
|
+
export class DashboardComponentRoleService {
|
|
14
|
+
constructor(
|
|
15
|
+
@Inject(forwardRef(() => PrismaService))
|
|
16
|
+
private readonly prismaService: PrismaService,
|
|
17
|
+
@Inject(forwardRef(() => PaginationService))
|
|
18
|
+
private readonly paginationService: PaginationService,
|
|
19
|
+
) {}
|
|
20
|
+
|
|
21
|
+
async getAll(paginationParams, locale: string) {
|
|
22
|
+
return this.paginationService.paginate(
|
|
23
|
+
this.prismaService.dashboard_component_role,
|
|
24
|
+
paginationParams,
|
|
25
|
+
{
|
|
26
|
+
include: {
|
|
27
|
+
dashboard_component: {
|
|
28
|
+
include: {
|
|
29
|
+
dashboard_component_locale: {
|
|
30
|
+
include: {
|
|
31
|
+
locale: true,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
role: {
|
|
37
|
+
include: {
|
|
38
|
+
role_locale: {
|
|
39
|
+
include: {
|
|
40
|
+
locale: true,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
orderBy: {
|
|
47
|
+
id: 'desc',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
'dashboardComponentRole',
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async getAllByComponent(componentId: number, locale: string) {
|
|
55
|
+
const relations = await this.prismaService.dashboard_component_role.findMany({
|
|
56
|
+
where: { component_id: componentId },
|
|
57
|
+
include: {
|
|
58
|
+
role: {
|
|
59
|
+
include: {
|
|
60
|
+
role_locale: {
|
|
61
|
+
include: {
|
|
62
|
+
locale: true,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return relations;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async create(data: CreateDashboardComponentRoleDTO, locale: string) {
|
|
74
|
+
// Verificar se a relação já existe
|
|
75
|
+
const existing = await this.prismaService.dashboard_component_role.findFirst({
|
|
76
|
+
where: {
|
|
77
|
+
component_id: data.component_id,
|
|
78
|
+
role_id: data.role_id,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (existing) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
getLocaleText(
|
|
85
|
+
'dashboardComponentRoleAlreadyExists',
|
|
86
|
+
locale,
|
|
87
|
+
'Dashboard component role already exists',
|
|
88
|
+
),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return this.prismaService.dashboard_component_role.create({
|
|
93
|
+
data: {
|
|
94
|
+
component_id: data.component_id,
|
|
95
|
+
role_id: data.role_id,
|
|
96
|
+
},
|
|
97
|
+
include: {
|
|
98
|
+
dashboard_component: {
|
|
99
|
+
include: {
|
|
100
|
+
dashboard_component_locale: {
|
|
101
|
+
include: {
|
|
102
|
+
locale: true,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
role: {
|
|
108
|
+
include: {
|
|
109
|
+
role_locale: {
|
|
110
|
+
include: {
|
|
111
|
+
locale: true,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async delete(id: number, locale: string) {
|
|
121
|
+
const relation = await this.prismaService.dashboard_component_role.findUnique({
|
|
122
|
+
where: { id },
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (!relation) {
|
|
126
|
+
throw new NotFoundException(
|
|
127
|
+
getLocaleText(
|
|
128
|
+
'dashboardComponentRoleNotFound',
|
|
129
|
+
locale,
|
|
130
|
+
'Dashboard component role not found',
|
|
131
|
+
),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
await this.prismaService.dashboard_component_role.delete({
|
|
136
|
+
where: { id },
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return { success: true };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async deleteByComponentAndRole(
|
|
143
|
+
componentId: number,
|
|
144
|
+
roleId: number,
|
|
145
|
+
locale: string,
|
|
146
|
+
) {
|
|
147
|
+
const relation = await this.prismaService.dashboard_component_role.findFirst({
|
|
148
|
+
where: {
|
|
149
|
+
component_id: componentId,
|
|
150
|
+
role_id: roleId,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
if (!relation) {
|
|
155
|
+
throw new NotFoundException(
|
|
156
|
+
getLocaleText(
|
|
157
|
+
'dashboardComponentRoleNotFound',
|
|
158
|
+
locale,
|
|
159
|
+
'Dashboard component role not found',
|
|
160
|
+
),
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
await this.prismaService.dashboard_component_role.delete({
|
|
165
|
+
where: { id: relation.id },
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return { success: true };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './create.dto';
|
|
@@ -18,11 +18,6 @@ export class DashboardCoreController {
|
|
|
18
18
|
return this.dashboardCoreService.getStatistics();
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
@Get('stats/user-growth')
|
|
22
|
-
getUserGrowth() {
|
|
23
|
-
return this.dashboardCoreService.getUserGrowth();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
21
|
@Get('layout/:slug')
|
|
27
22
|
getUserLayout(@User() user, @Param('slug') slug: string, @Locale() locale: string) {
|
|
28
23
|
return this.dashboardCoreService.getUserLayout(user.id, slug, locale);
|