@hedhog/admin 0.0.109 → 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 +0 -3
- package/dist/admin.module.js.map +1 -1
- package/dist/auth/auth.controller.d.ts.map +1 -1
- package/dist/auth/auth.controller.js +1 -2
- package/dist/auth/auth.controller.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +1 -1
- package/dist/menu/menu.controller.d.ts.map +1 -1
- package/dist/menu/menu.controller.js +1 -2
- 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/hedhog.yaml +0 -307
- package/package.json +3 -3
- package/src/admin.module.ts +0 -3
- package/src/auth/auth.controller.ts +1 -2
- package/src/index.ts +0 -4
- package/src/menu/menu.controller.ts +1 -2
- package/src/role/dto/create.dto.ts +1 -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/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 -26
- package/dist/setting/setting.controller.d.ts.map +0 -1
- package/dist/setting/setting.controller.js +0 -161
- 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 -33
- package/dist/setting/setting.module.js.map +0 -1
- package/dist/setting/setting.service.d.ts +0 -33
- package/dist/setting/setting.service.d.ts.map +0 -1
- package/dist/setting/setting.service.js +0 -377
- 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/user.decorator.ts +0 -17
- package/src/dto/with-locale.dto.ts +0 -8
- 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 -107
- package/src/setting/setting.module.ts +0 -20
- package/src/setting/setting.service.spec.ts +0 -183
- package/src/setting/setting.service.ts +0 -457
@@ -1,457 +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 { Response } from 'express';
|
12
|
-
import { DeleteDTO } from '../dto/delete.dto';
|
13
|
-
import { CreateDTO } from './dto/create.dto';
|
14
|
-
import { SettingDTO } from './dto/setting.dto';
|
15
|
-
import { UpdateDTO } from './dto/update.dto';
|
16
|
-
|
17
|
-
@Injectable()
|
18
|
-
export class SettingService {
|
19
|
-
constructor(
|
20
|
-
@Inject(forwardRef(() => PrismaService))
|
21
|
-
private readonly prismaService: PrismaService,
|
22
|
-
@Inject(forwardRef(() => PaginationService))
|
23
|
-
private readonly paginationService: PaginationService,
|
24
|
-
@Inject(forwardRef(() => FileService))
|
25
|
-
private readonly fileService: FileService,
|
26
|
-
) {}
|
27
|
-
|
28
|
-
async getAppearanceCSS(res: Response) {
|
29
|
-
const fileCSS = await this.fileService.readStream(`appearance/theme.css`);
|
30
|
-
|
31
|
-
res.setHeader('Content-Type', 'text/css');
|
32
|
-
|
33
|
-
return fileCSS.pipe(res);
|
34
|
-
}
|
35
|
-
|
36
|
-
async updateAppearanceSettings() {
|
37
|
-
console.log({ updateAppearanceSettings: 'updateAppearanceSettings' });
|
38
|
-
|
39
|
-
const settings = await this.prismaService.setting.findMany({
|
40
|
-
where: {
|
41
|
-
setting_group: {
|
42
|
-
slug: 'appearance',
|
43
|
-
},
|
44
|
-
},
|
45
|
-
});
|
46
|
-
|
47
|
-
await this.fileService.uploadFromString(
|
48
|
-
'appearance',
|
49
|
-
'theme.css',
|
50
|
-
`
|
51
|
-
@layer base {
|
52
|
-
:root {
|
53
|
-
--background: 0 0% 100%;
|
54
|
-
--foreground: 20 14.3% 4.1%;
|
55
|
-
--card: 0 0% 100%;
|
56
|
-
--card-foreground: 20 14.3% 4.1%;
|
57
|
-
--popover: 0 0% 100%;
|
58
|
-
--popover-foreground: 20 14.3% 4.1%;
|
59
|
-
--primary: 24.6 95% 53.1%;
|
60
|
-
--primary-foreground: 60 9.1% 97.8%;
|
61
|
-
--secondary: 60 4.8% 95.9%;
|
62
|
-
--secondary-foreground: 24 9.8% 10%;
|
63
|
-
--muted: 60 4.8% 95.9%;
|
64
|
-
--muted-foreground: 25 5.3% 44.7%;
|
65
|
-
--accent: 60 4.8% 95.9%;
|
66
|
-
--accent-foreground: 24 9.8% 10%;
|
67
|
-
--destructive: 0 84.2% 60.2%;
|
68
|
-
--destructive-foreground: 60 9.1% 97.8%;
|
69
|
-
--border: 20 5.9% 90%;
|
70
|
-
--input: 20 5.9% 90%;
|
71
|
-
--ring: 24.6 95% 53.1%;
|
72
|
-
--radius: 0.5rem;
|
73
|
-
--chart-1: 12 76% 61%;
|
74
|
-
--chart-2: 173 58% 39%;
|
75
|
-
--chart-3: 197 37% 24%;
|
76
|
-
--chart-4: 43 74% 66%;
|
77
|
-
--chart-5: 27 87% 67%;
|
78
|
-
}
|
79
|
-
|
80
|
-
.dark {
|
81
|
-
--background: 20 14.3% 4.1%;
|
82
|
-
--foreground: 60 9.1% 97.8%;
|
83
|
-
--card: 20 14.3% 4.1%;
|
84
|
-
--card-foreground: 60 9.1% 97.8%;
|
85
|
-
--popover: 20 14.3% 4.1%;
|
86
|
-
--popover-foreground: 60 9.1% 97.8%;
|
87
|
-
--primary: 20.5 90.2% 48.2%;
|
88
|
-
--primary-foreground: 60 9.1% 97.8%;
|
89
|
-
--secondary: 12 6.5% 15.1%;
|
90
|
-
--secondary-foreground: 60 9.1% 97.8%;
|
91
|
-
--muted: 12 6.5% 15.1%;
|
92
|
-
--muted-foreground: 24 5.4% 63.9%;
|
93
|
-
--accent: 12 6.5% 15.1%;
|
94
|
-
--accent-foreground: 60 9.1% 97.8%;
|
95
|
-
--destructive: 0 72.2% 50.6%;
|
96
|
-
--destructive-foreground: 60 9.1% 97.8%;
|
97
|
-
--border: 12 6.5% 15.1%;
|
98
|
-
--input: 12 6.5% 15.1%;
|
99
|
-
--ring: 20.5 90.2% 48.2%;
|
100
|
-
--chart-1: 220 70% 50%;
|
101
|
-
--chart-2: 160 60% 45%;
|
102
|
-
--chart-3: 30 80% 55%;
|
103
|
-
--chart-4: 280 65% 60%;
|
104
|
-
--chart-5: 340 75% 55%;
|
105
|
-
}
|
106
|
-
}
|
107
|
-
`,
|
108
|
-
'text/css',
|
109
|
-
);
|
110
|
-
|
111
|
-
console.log({ settings });
|
112
|
-
}
|
113
|
-
|
114
|
-
async setManySettings(data: SettingDTO) {
|
115
|
-
const transaction = [];
|
116
|
-
|
117
|
-
for (const { slug, value } of data.setting) {
|
118
|
-
transaction.push(
|
119
|
-
this.prismaService.setting.updateMany({
|
120
|
-
where: {
|
121
|
-
slug,
|
122
|
-
},
|
123
|
-
data: {
|
124
|
-
value,
|
125
|
-
},
|
126
|
-
}),
|
127
|
-
);
|
128
|
-
}
|
129
|
-
|
130
|
-
await this.prismaService.$transaction(transaction);
|
131
|
-
|
132
|
-
const hasAppearance = await this.prismaService.setting.count({
|
133
|
-
where: {
|
134
|
-
slug: {
|
135
|
-
in: data.setting.map((setting) => setting.slug),
|
136
|
-
},
|
137
|
-
setting_group: {
|
138
|
-
slug: 'appearance',
|
139
|
-
},
|
140
|
-
},
|
141
|
-
});
|
142
|
-
|
143
|
-
if (hasAppearance) {
|
144
|
-
await this.updateAppearanceSettings();
|
145
|
-
}
|
146
|
-
|
147
|
-
return { success: true };
|
148
|
-
}
|
149
|
-
|
150
|
-
async getSettingFromGroup(locale: any, paginationParams: any, slug: string) {
|
151
|
-
const fields = ['slug', 'value'];
|
152
|
-
|
153
|
-
paginationParams.pageSize = 100;
|
154
|
-
|
155
|
-
const OR: any[] = this.prismaService.createInsensitiveSearch(
|
156
|
-
fields,
|
157
|
-
paginationParams,
|
158
|
-
);
|
159
|
-
|
160
|
-
const result = await this.paginationService.paginate(
|
161
|
-
this.prismaService.setting,
|
162
|
-
paginationParams,
|
163
|
-
{
|
164
|
-
where: {
|
165
|
-
AND: {
|
166
|
-
setting_group: {
|
167
|
-
slug,
|
168
|
-
},
|
169
|
-
OR,
|
170
|
-
},
|
171
|
-
},
|
172
|
-
include: {
|
173
|
-
setting_group: {
|
174
|
-
include: {
|
175
|
-
setting_group_locale: {
|
176
|
-
where: {
|
177
|
-
locale: {
|
178
|
-
code: locale,
|
179
|
-
},
|
180
|
-
},
|
181
|
-
select: {
|
182
|
-
name: true,
|
183
|
-
description: true,
|
184
|
-
},
|
185
|
-
},
|
186
|
-
},
|
187
|
-
},
|
188
|
-
setting_locale: {
|
189
|
-
where: {
|
190
|
-
locale: {
|
191
|
-
code: locale,
|
192
|
-
},
|
193
|
-
},
|
194
|
-
select: {
|
195
|
-
name: true,
|
196
|
-
description: true,
|
197
|
-
},
|
198
|
-
},
|
199
|
-
},
|
200
|
-
},
|
201
|
-
'setting_locale',
|
202
|
-
);
|
203
|
-
|
204
|
-
result.data = result.data.map((setting: any) => {
|
205
|
-
setting.setting_group = itemTranslations(
|
206
|
-
'setting_group_locale',
|
207
|
-
setting.setting_group,
|
208
|
-
);
|
209
|
-
return setting;
|
210
|
-
});
|
211
|
-
|
212
|
-
return result;
|
213
|
-
}
|
214
|
-
|
215
|
-
async listSettingGroups(locale: string, paginationParams: PaginationDTO) {
|
216
|
-
const fields = ['slug', 'icon'];
|
217
|
-
|
218
|
-
paginationParams.pageSize = 100;
|
219
|
-
|
220
|
-
const OR: any[] = this.prismaService.createInsensitiveSearch(
|
221
|
-
fields,
|
222
|
-
paginationParams,
|
223
|
-
);
|
224
|
-
|
225
|
-
const result = await this.paginationService.paginate(
|
226
|
-
this.prismaService.setting_group,
|
227
|
-
paginationParams,
|
228
|
-
{
|
229
|
-
where: {
|
230
|
-
OR,
|
231
|
-
},
|
232
|
-
include: {
|
233
|
-
setting_group_locale: {
|
234
|
-
where: {
|
235
|
-
locale: {
|
236
|
-
code: locale,
|
237
|
-
},
|
238
|
-
},
|
239
|
-
select: {
|
240
|
-
name: true,
|
241
|
-
description: true,
|
242
|
-
},
|
243
|
-
},
|
244
|
-
},
|
245
|
-
},
|
246
|
-
'setting_group_locale',
|
247
|
-
);
|
248
|
-
|
249
|
-
return result;
|
250
|
-
}
|
251
|
-
|
252
|
-
async listSettings(locale: string, paginationParams: PaginationDTO) {
|
253
|
-
const fields = ['slug', 'value'];
|
254
|
-
|
255
|
-
const OR: any[] = this.prismaService.createInsensitiveSearch(
|
256
|
-
fields,
|
257
|
-
paginationParams,
|
258
|
-
);
|
259
|
-
|
260
|
-
const result = await this.paginationService.paginate(
|
261
|
-
this.prismaService.setting,
|
262
|
-
paginationParams,
|
263
|
-
{
|
264
|
-
where: {
|
265
|
-
OR,
|
266
|
-
},
|
267
|
-
include: {
|
268
|
-
setting_group: {
|
269
|
-
include: {
|
270
|
-
setting_group_locale: {
|
271
|
-
where: {
|
272
|
-
locale: {
|
273
|
-
code: locale,
|
274
|
-
},
|
275
|
-
},
|
276
|
-
select: {
|
277
|
-
name: true,
|
278
|
-
description: true,
|
279
|
-
},
|
280
|
-
},
|
281
|
-
},
|
282
|
-
},
|
283
|
-
setting_locale: {
|
284
|
-
where: {
|
285
|
-
locale: {
|
286
|
-
code: locale,
|
287
|
-
},
|
288
|
-
},
|
289
|
-
select: {
|
290
|
-
name: true,
|
291
|
-
description: true,
|
292
|
-
},
|
293
|
-
},
|
294
|
-
},
|
295
|
-
},
|
296
|
-
'setting_locale',
|
297
|
-
);
|
298
|
-
|
299
|
-
result.data = result.data.map((setting: any) => {
|
300
|
-
setting.setting_group = itemTranslations(
|
301
|
-
'setting_group_locale',
|
302
|
-
setting.setting_group,
|
303
|
-
);
|
304
|
-
return setting;
|
305
|
-
});
|
306
|
-
|
307
|
-
return result;
|
308
|
-
}
|
309
|
-
|
310
|
-
async get(settingId: number) {
|
311
|
-
return this.prismaService.setting.findUnique({
|
312
|
-
where: { id: settingId },
|
313
|
-
});
|
314
|
-
}
|
315
|
-
|
316
|
-
async create({}: CreateDTO) {
|
317
|
-
return this.prismaService.setting.create({
|
318
|
-
data: {},
|
319
|
-
});
|
320
|
-
}
|
321
|
-
|
322
|
-
async update({ id, data }: { id: number; data: UpdateDTO }) {
|
323
|
-
return this.prismaService.setting.update({
|
324
|
-
where: { id },
|
325
|
-
data,
|
326
|
-
});
|
327
|
-
}
|
328
|
-
|
329
|
-
async updateFromSlug(slug: string, data: UpdateDTO) {
|
330
|
-
const { id } = await this.prismaService.setting.findFirst({
|
331
|
-
where: {
|
332
|
-
slug,
|
333
|
-
},
|
334
|
-
});
|
335
|
-
|
336
|
-
if (!id) {
|
337
|
-
throw new BadRequestException(`Setting with slug ${slug} not found.`);
|
338
|
-
}
|
339
|
-
|
340
|
-
return this.update({
|
341
|
-
id,
|
342
|
-
data,
|
343
|
-
});
|
344
|
-
}
|
345
|
-
|
346
|
-
async delete({ ids }: DeleteDTO) {
|
347
|
-
if (ids == undefined || ids == null) {
|
348
|
-
throw new BadRequestException(
|
349
|
-
`You must select at least one setting to delete.`,
|
350
|
-
);
|
351
|
-
}
|
352
|
-
|
353
|
-
return this.prismaService.setting.deleteMany({
|
354
|
-
where: {
|
355
|
-
id: {
|
356
|
-
in: ids,
|
357
|
-
},
|
358
|
-
},
|
359
|
-
});
|
360
|
-
}
|
361
|
-
|
362
|
-
async setSettingUserValue(user_id: number, slug: string, value: string) {
|
363
|
-
const user = await this.prismaService.user.findUnique({
|
364
|
-
where: {
|
365
|
-
id: user_id,
|
366
|
-
},
|
367
|
-
select: {
|
368
|
-
id: true,
|
369
|
-
},
|
370
|
-
});
|
371
|
-
|
372
|
-
if (!user) {
|
373
|
-
throw new BadRequestException(`User with id ${user_id} not found.`);
|
374
|
-
}
|
375
|
-
|
376
|
-
const setting = await this.prismaService.setting.findFirst({
|
377
|
-
where: {
|
378
|
-
slug,
|
379
|
-
user_override: true,
|
380
|
-
},
|
381
|
-
});
|
382
|
-
|
383
|
-
if (!setting) {
|
384
|
-
throw new BadRequestException(
|
385
|
-
`Setting with slug ${slug} not found or user can not override.`,
|
386
|
-
);
|
387
|
-
}
|
388
|
-
|
389
|
-
return await this.prismaService.setting_user.upsert({
|
390
|
-
where: {
|
391
|
-
user_id_setting_id: {
|
392
|
-
setting_id: setting.id,
|
393
|
-
user_id: user.id,
|
394
|
-
},
|
395
|
-
},
|
396
|
-
create: {
|
397
|
-
setting_id: setting.id,
|
398
|
-
value,
|
399
|
-
user_id: user.id,
|
400
|
-
},
|
401
|
-
update: {
|
402
|
-
value,
|
403
|
-
},
|
404
|
-
select: {
|
405
|
-
setting_id: true,
|
406
|
-
user_id: true,
|
407
|
-
value: true,
|
408
|
-
},
|
409
|
-
});
|
410
|
-
}
|
411
|
-
|
412
|
-
async getSettingValues(slug: string | string[]) {
|
413
|
-
slug = Array.isArray(slug) ? slug : [slug];
|
414
|
-
|
415
|
-
let setting = await this.prismaService.setting.findMany({
|
416
|
-
where: {
|
417
|
-
slug: {
|
418
|
-
in: slug,
|
419
|
-
},
|
420
|
-
},
|
421
|
-
select: {
|
422
|
-
id: true,
|
423
|
-
value: true,
|
424
|
-
slug: true,
|
425
|
-
type: true,
|
426
|
-
user_override: true,
|
427
|
-
},
|
428
|
-
});
|
429
|
-
|
430
|
-
const slugUserOverride = setting.filter((setting) => setting.userOverride);
|
431
|
-
|
432
|
-
const settingUser = await this.prismaService.setting_user.findMany({
|
433
|
-
where: {
|
434
|
-
setting_id: {
|
435
|
-
in: slugUserOverride.map((setting) => setting.id),
|
436
|
-
},
|
437
|
-
},
|
438
|
-
select: {
|
439
|
-
value: true,
|
440
|
-
setting_id: true,
|
441
|
-
},
|
442
|
-
});
|
443
|
-
|
444
|
-
const data: Record<string, any> = {};
|
445
|
-
|
446
|
-
setting.forEach((setting) => {
|
447
|
-
data[setting.slug] = setting.value;
|
448
|
-
});
|
449
|
-
|
450
|
-
settingUser.forEach((setting) => {
|
451
|
-
data[slugUserOverride.find((s) => s.id === setting.setting_id).slug] =
|
452
|
-
setting.value;
|
453
|
-
});
|
454
|
-
|
455
|
-
return data;
|
456
|
-
}
|
457
|
-
}
|