@hedhog/admin 0.0.108 → 0.0.110
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/admin.module.d.ts.map +1 -1
- package/dist/admin.module.js +1 -6
- package/dist/admin.module.js.map +1 -1
- package/dist/auth/auth.controller.d.ts.map +1 -1
- package/dist/auth/auth.controller.js +6 -8
- package/dist/auth/auth.controller.js.map +1 -1
- package/dist/auth/guards/auth.guard.js +2 -2
- package/dist/auth/guards/auth.guard.js.map +1 -1
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -11
- package/dist/index.js.map +1 -1
- package/dist/menu/menu.controller.d.ts.map +1 -1
- package/dist/menu/menu.controller.js +4 -5
- package/dist/menu/menu.controller.js.map +1 -1
- package/dist/role/dto/create.dto.d.ts +1 -1
- package/dist/role/dto/create.dto.d.ts.map +1 -1
- package/dist/role/dto/create.dto.js +2 -2
- package/dist/role/dto/create.dto.js.map +1 -1
- package/dist/role/guards/role.guard.d.ts.map +1 -1
- package/dist/role/guards/role.guard.js +3 -4
- package/dist/role/guards/role.guard.js.map +1 -1
- package/dist/role/role.controller.js +3 -3
- package/dist/role/role.controller.js.map +1 -1
- package/dist/role/role.module.js +1 -1
- package/dist/role/role.module.js.map +1 -1
- package/dist/role/role.service.d.ts +1 -1
- package/dist/role/role.service.d.ts.map +1 -1
- package/dist/role/role.service.js +1 -1
- package/dist/role/role.service.js.map +1 -1
- package/dist/route/route.controller.js +3 -3
- package/dist/route/route.controller.js.map +1 -1
- package/dist/screen/screen.controller.js +3 -3
- package/dist/screen/screen.controller.js.map +1 -1
- package/dist/user/user.controller.js +2 -2
- package/dist/user/user.controller.js.map +1 -1
- package/hedhog.yaml +1 -328
- package/package.json +8 -6
- package/src/admin.module.ts +1 -6
- package/src/auth/auth.controller.ts +1 -3
- package/src/auth/guards/auth.guard.ts +1 -1
- package/src/index.ts +0 -14
- package/src/menu/menu.controller.ts +2 -3
- package/src/role/dto/create.dto.ts +1 -1
- package/src/role/guards/role.guard.ts +1 -2
- package/src/role/role.controller.ts +2 -2
- package/src/role/role.module.ts +1 -1
- package/src/role/role.service.ts +1 -1
- package/src/route/route.controller.ts +2 -2
- package/src/screen/screen.controller.ts +2 -2
- package/src/user/user.controller.ts +1 -1
- package/dist/auth/decorators/public.decorator.d.ts +0 -3
- package/dist/auth/decorators/public.decorator.d.ts.map +0 -1
- package/dist/auth/decorators/public.decorator.js +0 -8
- package/dist/auth/decorators/public.decorator.js.map +0 -1
- package/dist/auth/decorators/user.decorator.d.ts +0 -2
- package/dist/auth/decorators/user.decorator.d.ts.map +0 -1
- package/dist/auth/decorators/user.decorator.js +0 -12
- package/dist/auth/decorators/user.decorator.js.map +0 -1
- package/dist/dto/with-locale.dto.d.ts +0 -4
- package/dist/dto/with-locale.dto.d.ts.map +0 -1
- package/dist/dto/with-locale.dto.js +0 -23
- package/dist/dto/with-locale.dto.js.map +0 -1
- package/dist/locale/dto/create.dto.d.ts +0 -6
- package/dist/locale/dto/create.dto.d.ts.map +0 -1
- package/dist/locale/dto/create.dto.js +0 -29
- package/dist/locale/dto/create.dto.js.map +0 -1
- package/dist/locale/dto/delete.dto.d.ts +0 -4
- package/dist/locale/dto/delete.dto.d.ts.map +0 -1
- package/dist/locale/dto/delete.dto.js +0 -23
- package/dist/locale/dto/delete.dto.js.map +0 -1
- package/dist/locale/dto/set-enabled.dto.d.ts +0 -4
- package/dist/locale/dto/set-enabled.dto.d.ts.map +0 -1
- package/dist/locale/dto/set-enabled.dto.js +0 -24
- package/dist/locale/dto/set-enabled.dto.js.map +0 -1
- package/dist/locale/dto/update.dto.d.ts +0 -6
- package/dist/locale/dto/update.dto.d.ts.map +0 -1
- package/dist/locale/dto/update.dto.js +0 -32
- package/dist/locale/dto/update.dto.js.map +0 -1
- package/dist/locale/index.d.ts +0 -5
- package/dist/locale/index.d.ts.map +0 -1
- package/dist/locale/index.js +0 -21
- package/dist/locale/index.js.map +0 -1
- package/dist/locale/locale.controller.d.ts +0 -18
- package/dist/locale/locale.controller.d.ts.map +0 -1
- package/dist/locale/locale.controller.js +0 -127
- package/dist/locale/locale.controller.js.map +0 -1
- package/dist/locale/locale.decorator.d.ts +0 -2
- package/dist/locale/locale.decorator.d.ts.map +0 -1
- package/dist/locale/locale.decorator.js +0 -9
- package/dist/locale/locale.decorator.js.map +0 -1
- package/dist/locale/locale.middleware.d.ts +0 -10
- package/dist/locale/locale.middleware.d.ts.map +0 -1
- package/dist/locale/locale.middleware.js +0 -45
- package/dist/locale/locale.middleware.js.map +0 -1
- package/dist/locale/locale.module.d.ts +0 -5
- package/dist/locale/locale.module.d.ts.map +0 -1
- package/dist/locale/locale.module.js +0 -35
- package/dist/locale/locale.module.js.map +0 -1
- package/dist/locale/locale.service.d.ts +0 -32
- package/dist/locale/locale.service.d.ts.map +0 -1
- package/dist/locale/locale.service.js +0 -290
- package/dist/locale/locale.service.js.map +0 -1
- package/dist/locale/locale.service.spec.d.ts +0 -2
- package/dist/locale/locale.service.spec.d.ts.map +0 -1
- package/dist/locale/locale.service.spec.js +0 -174
- package/dist/locale/locale.service.spec.js.map +0 -1
- package/dist/role/decorators/role.decorator.d.ts +0 -3
- package/dist/role/decorators/role.decorator.d.ts.map +0 -1
- package/dist/role/decorators/role.decorator.js +0 -10
- package/dist/role/decorators/role.decorator.js.map +0 -1
- package/dist/setting/dto/create.dto.d.ts +0 -3
- package/dist/setting/dto/create.dto.d.ts.map +0 -1
- package/dist/setting/dto/create.dto.js +0 -7
- package/dist/setting/dto/create.dto.js.map +0 -1
- package/dist/setting/dto/setting-user.dto.d.ts +0 -4
- package/dist/setting/dto/setting-user.dto.d.ts.map +0 -1
- package/dist/setting/dto/setting-user.dto.js +0 -21
- package/dist/setting/dto/setting-user.dto.js.map +0 -1
- package/dist/setting/dto/setting.dto.d.ts +0 -9
- package/dist/setting/dto/setting.dto.d.ts.map +0 -1
- package/dist/setting/dto/setting.dto.js +0 -34
- package/dist/setting/dto/setting.dto.js.map +0 -1
- package/dist/setting/dto/update.dto.d.ts +0 -4
- package/dist/setting/dto/update.dto.d.ts.map +0 -1
- package/dist/setting/dto/update.dto.js +0 -8
- package/dist/setting/dto/update.dto.js.map +0 -1
- package/dist/setting/setting.controller.d.ts +0 -25
- package/dist/setting/setting.controller.d.ts.map +0 -1
- package/dist/setting/setting.controller.js +0 -150
- package/dist/setting/setting.controller.js.map +0 -1
- package/dist/setting/setting.module.d.ts +0 -3
- package/dist/setting/setting.module.d.ts.map +0 -1
- package/dist/setting/setting.module.js +0 -31
- package/dist/setting/setting.module.js.map +0 -1
- package/dist/setting/setting.service.d.ts +0 -31
- package/dist/setting/setting.service.d.ts.map +0 -1
- package/dist/setting/setting.service.js +0 -314
- package/dist/setting/setting.service.js.map +0 -1
- package/dist/setting/setting.service.spec.d.ts +0 -2
- package/dist/setting/setting.service.spec.d.ts.map +0 -1
- package/dist/setting/setting.service.spec.js +0 -162
- package/dist/setting/setting.service.spec.js.map +0 -1
- package/src/auth/decorators/public.decorator.ts +0 -4
- package/src/auth/decorators/user.decorator.ts +0 -17
- package/src/dto/with-locale.dto.ts +0 -8
- package/src/locale/dto/create.dto.ts +0 -12
- package/src/locale/dto/delete.dto.ts +0 -8
- package/src/locale/dto/set-enabled.dto.ts +0 -9
- package/src/locale/dto/update.dto.ts +0 -15
- package/src/locale/index.ts +0 -4
- package/src/locale/locale.controller.ts +0 -79
- package/src/locale/locale.decorator.ts +0 -8
- package/src/locale/locale.middleware.ts +0 -34
- package/src/locale/locale.module.ts +0 -23
- package/src/locale/locale.service.spec.ts +0 -193
- package/src/locale/locale.service.ts +0 -364
- package/src/role/decorators/role.decorator.ts +0 -7
- package/src/setting/dto/create.dto.ts +0 -1
- package/src/setting/dto/setting-user.dto.ts +0 -6
- package/src/setting/dto/setting.dto.ts +0 -17
- package/src/setting/dto/update.dto.ts +0 -3
- package/src/setting/setting.controller.ts +0 -100
- package/src/setting/setting.module.ts +0 -18
- package/src/setting/setting.service.spec.ts +0 -183
- package/src/setting/setting.service.ts +0 -384
@@ -1,384 +0,0 @@
|
|
1
|
-
import { FileService } from '@hedhog/file';
|
2
|
-
import { PaginationDTO, PaginationService } from '@hedhog/pagination';
|
3
|
-
import { PrismaService } from '@hedhog/prisma';
|
4
|
-
import { itemTranslations } from '@hedhog/utils';
|
5
|
-
import {
|
6
|
-
BadRequestException,
|
7
|
-
Inject,
|
8
|
-
Injectable,
|
9
|
-
forwardRef,
|
10
|
-
} from '@nestjs/common';
|
11
|
-
import { DeleteDTO } from '../dto/delete.dto';
|
12
|
-
import { CreateDTO } from './dto/create.dto';
|
13
|
-
import { SettingDTO } from './dto/setting.dto';
|
14
|
-
import { UpdateDTO } from './dto/update.dto';
|
15
|
-
|
16
|
-
@Injectable()
|
17
|
-
export class SettingService {
|
18
|
-
constructor(
|
19
|
-
@Inject(forwardRef(() => PrismaService))
|
20
|
-
private readonly prismaService: PrismaService,
|
21
|
-
@Inject(forwardRef(() => PaginationService))
|
22
|
-
private readonly paginationService: PaginationService,
|
23
|
-
@Inject(forwardRef(() => FileService))
|
24
|
-
private readonly fileService: FileService,
|
25
|
-
) {}
|
26
|
-
|
27
|
-
async updateAppearanceSettings() {
|
28
|
-
console.log({ updateAppearanceSettings: 'updateAppearanceSettings' });
|
29
|
-
|
30
|
-
const settings = await this.prismaService.setting.findMany({
|
31
|
-
where: {
|
32
|
-
setting_group: {
|
33
|
-
slug: 'appearance',
|
34
|
-
},
|
35
|
-
},
|
36
|
-
});
|
37
|
-
|
38
|
-
console.log({ settings });
|
39
|
-
}
|
40
|
-
|
41
|
-
async setManySettings(data: SettingDTO) {
|
42
|
-
const transaction = [];
|
43
|
-
|
44
|
-
for (const { slug, value } of data.setting) {
|
45
|
-
transaction.push(
|
46
|
-
this.prismaService.setting.updateMany({
|
47
|
-
where: {
|
48
|
-
slug,
|
49
|
-
},
|
50
|
-
data: {
|
51
|
-
value,
|
52
|
-
},
|
53
|
-
}),
|
54
|
-
);
|
55
|
-
}
|
56
|
-
|
57
|
-
await this.prismaService.$transaction(transaction);
|
58
|
-
|
59
|
-
const hasAppearance = await this.prismaService.setting.count({
|
60
|
-
where: {
|
61
|
-
slug: {
|
62
|
-
in: data.setting.map((setting) => setting.slug),
|
63
|
-
},
|
64
|
-
setting_group: {
|
65
|
-
slug: 'appearance',
|
66
|
-
},
|
67
|
-
},
|
68
|
-
});
|
69
|
-
|
70
|
-
if (hasAppearance) {
|
71
|
-
await this.updateAppearanceSettings();
|
72
|
-
}
|
73
|
-
|
74
|
-
return { success: true };
|
75
|
-
}
|
76
|
-
|
77
|
-
async getSettingFromGroup(locale: any, paginationParams: any, slug: string) {
|
78
|
-
const fields = ['slug', 'value'];
|
79
|
-
|
80
|
-
paginationParams.pageSize = 100;
|
81
|
-
|
82
|
-
const OR: any[] = this.prismaService.createInsensitiveSearch(
|
83
|
-
fields,
|
84
|
-
paginationParams,
|
85
|
-
);
|
86
|
-
|
87
|
-
const result = await this.paginationService.paginate(
|
88
|
-
this.prismaService.setting,
|
89
|
-
paginationParams,
|
90
|
-
{
|
91
|
-
where: {
|
92
|
-
AND: {
|
93
|
-
setting_group: {
|
94
|
-
slug,
|
95
|
-
},
|
96
|
-
OR,
|
97
|
-
},
|
98
|
-
},
|
99
|
-
include: {
|
100
|
-
setting_group: {
|
101
|
-
include: {
|
102
|
-
setting_group_locale: {
|
103
|
-
where: {
|
104
|
-
locale: {
|
105
|
-
code: locale,
|
106
|
-
},
|
107
|
-
},
|
108
|
-
select: {
|
109
|
-
name: true,
|
110
|
-
description: true,
|
111
|
-
},
|
112
|
-
},
|
113
|
-
},
|
114
|
-
},
|
115
|
-
setting_locale: {
|
116
|
-
where: {
|
117
|
-
locale: {
|
118
|
-
code: locale,
|
119
|
-
},
|
120
|
-
},
|
121
|
-
select: {
|
122
|
-
name: true,
|
123
|
-
description: true,
|
124
|
-
},
|
125
|
-
},
|
126
|
-
},
|
127
|
-
},
|
128
|
-
'setting_locale',
|
129
|
-
);
|
130
|
-
|
131
|
-
result.data = result.data.map((setting: any) => {
|
132
|
-
setting.setting_group = itemTranslations(
|
133
|
-
'setting_group_locale',
|
134
|
-
setting.setting_group,
|
135
|
-
);
|
136
|
-
return setting;
|
137
|
-
});
|
138
|
-
|
139
|
-
return result;
|
140
|
-
}
|
141
|
-
|
142
|
-
async listSettingGroups(locale: string, paginationParams: PaginationDTO) {
|
143
|
-
const fields = ['slug', 'icon'];
|
144
|
-
|
145
|
-
paginationParams.pageSize = 100;
|
146
|
-
|
147
|
-
const OR: any[] = this.prismaService.createInsensitiveSearch(
|
148
|
-
fields,
|
149
|
-
paginationParams,
|
150
|
-
);
|
151
|
-
|
152
|
-
const result = await this.paginationService.paginate(
|
153
|
-
this.prismaService.setting_group,
|
154
|
-
paginationParams,
|
155
|
-
{
|
156
|
-
where: {
|
157
|
-
OR,
|
158
|
-
},
|
159
|
-
include: {
|
160
|
-
setting_group_locale: {
|
161
|
-
where: {
|
162
|
-
locale: {
|
163
|
-
code: locale,
|
164
|
-
},
|
165
|
-
},
|
166
|
-
select: {
|
167
|
-
name: true,
|
168
|
-
description: true,
|
169
|
-
},
|
170
|
-
},
|
171
|
-
},
|
172
|
-
},
|
173
|
-
'setting_group_locale',
|
174
|
-
);
|
175
|
-
|
176
|
-
return result;
|
177
|
-
}
|
178
|
-
|
179
|
-
async listSettings(locale: string, paginationParams: PaginationDTO) {
|
180
|
-
const fields = ['slug', 'value'];
|
181
|
-
|
182
|
-
const OR: any[] = this.prismaService.createInsensitiveSearch(
|
183
|
-
fields,
|
184
|
-
paginationParams,
|
185
|
-
);
|
186
|
-
|
187
|
-
const result = await this.paginationService.paginate(
|
188
|
-
this.prismaService.setting,
|
189
|
-
paginationParams,
|
190
|
-
{
|
191
|
-
where: {
|
192
|
-
OR,
|
193
|
-
},
|
194
|
-
include: {
|
195
|
-
setting_group: {
|
196
|
-
include: {
|
197
|
-
setting_group_locale: {
|
198
|
-
where: {
|
199
|
-
locale: {
|
200
|
-
code: locale,
|
201
|
-
},
|
202
|
-
},
|
203
|
-
select: {
|
204
|
-
name: true,
|
205
|
-
description: true,
|
206
|
-
},
|
207
|
-
},
|
208
|
-
},
|
209
|
-
},
|
210
|
-
setting_locale: {
|
211
|
-
where: {
|
212
|
-
locale: {
|
213
|
-
code: locale,
|
214
|
-
},
|
215
|
-
},
|
216
|
-
select: {
|
217
|
-
name: true,
|
218
|
-
description: true,
|
219
|
-
},
|
220
|
-
},
|
221
|
-
},
|
222
|
-
},
|
223
|
-
'setting_locale',
|
224
|
-
);
|
225
|
-
|
226
|
-
result.data = result.data.map((setting: any) => {
|
227
|
-
setting.setting_group = itemTranslations(
|
228
|
-
'setting_group_locale',
|
229
|
-
setting.setting_group,
|
230
|
-
);
|
231
|
-
return setting;
|
232
|
-
});
|
233
|
-
|
234
|
-
return result;
|
235
|
-
}
|
236
|
-
|
237
|
-
async get(settingId: number) {
|
238
|
-
return this.prismaService.setting.findUnique({
|
239
|
-
where: { id: settingId },
|
240
|
-
});
|
241
|
-
}
|
242
|
-
|
243
|
-
async create({}: CreateDTO) {
|
244
|
-
return this.prismaService.setting.create({
|
245
|
-
data: {},
|
246
|
-
});
|
247
|
-
}
|
248
|
-
|
249
|
-
async update({ id, data }: { id: number; data: UpdateDTO }) {
|
250
|
-
return this.prismaService.setting.update({
|
251
|
-
where: { id },
|
252
|
-
data,
|
253
|
-
});
|
254
|
-
}
|
255
|
-
|
256
|
-
async updateFromSlug(slug: string, data: UpdateDTO) {
|
257
|
-
const { id } = await this.prismaService.setting.findFirst({
|
258
|
-
where: {
|
259
|
-
slug,
|
260
|
-
},
|
261
|
-
});
|
262
|
-
|
263
|
-
if (!id) {
|
264
|
-
throw new BadRequestException(`Setting with slug ${slug} not found.`);
|
265
|
-
}
|
266
|
-
|
267
|
-
return this.update({
|
268
|
-
id,
|
269
|
-
data,
|
270
|
-
});
|
271
|
-
}
|
272
|
-
|
273
|
-
async delete({ ids }: DeleteDTO) {
|
274
|
-
if (ids == undefined || ids == null) {
|
275
|
-
throw new BadRequestException(
|
276
|
-
`You must select at least one setting to delete.`,
|
277
|
-
);
|
278
|
-
}
|
279
|
-
|
280
|
-
return this.prismaService.setting.deleteMany({
|
281
|
-
where: {
|
282
|
-
id: {
|
283
|
-
in: ids,
|
284
|
-
},
|
285
|
-
},
|
286
|
-
});
|
287
|
-
}
|
288
|
-
|
289
|
-
async setSettingUserValue(user_id: number, slug: string, value: string) {
|
290
|
-
const user = await this.prismaService.user.findUnique({
|
291
|
-
where: {
|
292
|
-
id: user_id,
|
293
|
-
},
|
294
|
-
select: {
|
295
|
-
id: true,
|
296
|
-
},
|
297
|
-
});
|
298
|
-
|
299
|
-
if (!user) {
|
300
|
-
throw new BadRequestException(`User with id ${user_id} not found.`);
|
301
|
-
}
|
302
|
-
|
303
|
-
const setting = await this.prismaService.setting.findFirst({
|
304
|
-
where: {
|
305
|
-
slug,
|
306
|
-
user_override: true,
|
307
|
-
},
|
308
|
-
});
|
309
|
-
|
310
|
-
if (!setting) {
|
311
|
-
throw new BadRequestException(
|
312
|
-
`Setting with slug ${slug} not found or user can not override.`,
|
313
|
-
);
|
314
|
-
}
|
315
|
-
|
316
|
-
return await this.prismaService.setting_user.upsert({
|
317
|
-
where: {
|
318
|
-
user_id_setting_id: {
|
319
|
-
setting_id: setting.id,
|
320
|
-
user_id: user.id,
|
321
|
-
},
|
322
|
-
},
|
323
|
-
create: {
|
324
|
-
setting_id: setting.id,
|
325
|
-
value,
|
326
|
-
user_id: user.id,
|
327
|
-
},
|
328
|
-
update: {
|
329
|
-
value,
|
330
|
-
},
|
331
|
-
select: {
|
332
|
-
setting_id: true,
|
333
|
-
user_id: true,
|
334
|
-
value: true,
|
335
|
-
},
|
336
|
-
});
|
337
|
-
}
|
338
|
-
|
339
|
-
async getSettingValues(slug: string | string[]) {
|
340
|
-
slug = Array.isArray(slug) ? slug : [slug];
|
341
|
-
|
342
|
-
let setting = await this.prismaService.setting.findMany({
|
343
|
-
where: {
|
344
|
-
slug: {
|
345
|
-
in: slug,
|
346
|
-
},
|
347
|
-
},
|
348
|
-
select: {
|
349
|
-
id: true,
|
350
|
-
value: true,
|
351
|
-
slug: true,
|
352
|
-
type: true,
|
353
|
-
user_override: true,
|
354
|
-
},
|
355
|
-
});
|
356
|
-
|
357
|
-
const slugUserOverride = setting.filter((setting) => setting.userOverride);
|
358
|
-
|
359
|
-
const settingUser = await this.prismaService.setting_user.findMany({
|
360
|
-
where: {
|
361
|
-
setting_id: {
|
362
|
-
in: slugUserOverride.map((setting) => setting.id),
|
363
|
-
},
|
364
|
-
},
|
365
|
-
select: {
|
366
|
-
value: true,
|
367
|
-
setting_id: true,
|
368
|
-
},
|
369
|
-
});
|
370
|
-
|
371
|
-
const data: Record<string, any> = {};
|
372
|
-
|
373
|
-
setting.forEach((setting) => {
|
374
|
-
data[setting.slug] = setting.value;
|
375
|
-
});
|
376
|
-
|
377
|
-
settingUser.forEach((setting) => {
|
378
|
-
data[slugUserOverride.find((s) => s.id === setting.setting_id).slug] =
|
379
|
-
setting.value;
|
380
|
-
});
|
381
|
-
|
382
|
-
return data;
|
383
|
-
}
|
384
|
-
}
|