@hedhog/admin 0.0.109 → 0.0.111
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 +48 -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,107 +0,0 @@
|
|
1
|
-
import { Pagination } from '@hedhog/pagination';
|
2
|
-
import {
|
3
|
-
Body,
|
4
|
-
Controller,
|
5
|
-
Delete,
|
6
|
-
forwardRef,
|
7
|
-
Get,
|
8
|
-
Inject,
|
9
|
-
Param,
|
10
|
-
ParseIntPipe,
|
11
|
-
Patch,
|
12
|
-
Post,
|
13
|
-
Put,
|
14
|
-
Res,
|
15
|
-
} from '@nestjs/common';
|
16
|
-
import { Locale } from '@hedhog/locale';
|
17
|
-
import { Role, Public } from '@hedhog/utils';
|
18
|
-
import { User } from '../auth/decorators/user.decorator';
|
19
|
-
import { DeleteDTO } from '../dto/delete.dto';
|
20
|
-
import { CreateDTO } from './dto/create.dto';
|
21
|
-
import { SettingUserDTO } from './dto/setting-user.dto';
|
22
|
-
import { SettingDTO } from './dto/setting.dto';
|
23
|
-
import { UpdateDTO } from './dto/update.dto';
|
24
|
-
import { SettingService } from './setting.service';
|
25
|
-
|
26
|
-
@Role()
|
27
|
-
@Controller('setting')
|
28
|
-
export class SettingsController {
|
29
|
-
constructor(
|
30
|
-
@Inject(forwardRef(() => SettingService))
|
31
|
-
private readonly settingService: SettingService,
|
32
|
-
) {}
|
33
|
-
|
34
|
-
@Get('group/:slug')
|
35
|
-
async getSettingFromGroup(
|
36
|
-
@Pagination() paginationParams,
|
37
|
-
@Locale() locale,
|
38
|
-
@Param('slug') slug: string,
|
39
|
-
) {
|
40
|
-
return this.settingService.getSettingFromGroup(
|
41
|
-
locale,
|
42
|
-
paginationParams,
|
43
|
-
slug,
|
44
|
-
);
|
45
|
-
}
|
46
|
-
|
47
|
-
@Public()
|
48
|
-
@Get('appearance.css')
|
49
|
-
async appearanceCSS(@Res() res) {
|
50
|
-
return this.settingService.getAppearanceCSS(res);
|
51
|
-
}
|
52
|
-
|
53
|
-
@Get('group')
|
54
|
-
async listSettingGroups(@Pagination() paginationParams, @Locale() locale) {
|
55
|
-
return this.settingService.listSettingGroups(locale, paginationParams);
|
56
|
-
}
|
57
|
-
|
58
|
-
@Get()
|
59
|
-
async listSettings(@Pagination() paginationParams, @Locale() locale) {
|
60
|
-
return this.settingService.listSettings(locale, paginationParams);
|
61
|
-
}
|
62
|
-
|
63
|
-
@Get(':settingId')
|
64
|
-
async show(@Param('settingId', ParseIntPipe) settingId: number) {
|
65
|
-
return this.settingService.get(settingId);
|
66
|
-
}
|
67
|
-
|
68
|
-
@Post()
|
69
|
-
async create(@Body() data: CreateDTO) {
|
70
|
-
return this.settingService.create(data);
|
71
|
-
}
|
72
|
-
|
73
|
-
@Put('user/:slug')
|
74
|
-
async updateUserFromSlug(
|
75
|
-
@Param('slug') slug: string,
|
76
|
-
@Body() { value }: SettingUserDTO,
|
77
|
-
@User() { id },
|
78
|
-
) {
|
79
|
-
return this.settingService.setSettingUserValue(id, slug, value);
|
80
|
-
}
|
81
|
-
|
82
|
-
@Put(':slug')
|
83
|
-
async updateFromSlug(@Param('slug') slug: string, @Body() data: UpdateDTO) {
|
84
|
-
return this.settingService.updateFromSlug(slug, data);
|
85
|
-
}
|
86
|
-
|
87
|
-
@Put()
|
88
|
-
async setManySettings(@Body() data: SettingDTO) {
|
89
|
-
return this.settingService.setManySettings(data);
|
90
|
-
}
|
91
|
-
|
92
|
-
@Patch(':settingId')
|
93
|
-
async update(
|
94
|
-
@Param('settingId', ParseIntPipe) settingId: number,
|
95
|
-
@Body() data: UpdateDTO,
|
96
|
-
) {
|
97
|
-
return this.settingService.update({
|
98
|
-
id: settingId,
|
99
|
-
data,
|
100
|
-
});
|
101
|
-
}
|
102
|
-
|
103
|
-
@Delete()
|
104
|
-
async delete(@Body() data: DeleteDTO) {
|
105
|
-
return this.settingService.delete(data);
|
106
|
-
}
|
107
|
-
}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import { FileModule } from '@hedhog/file';
|
2
|
-
import { PaginationModule } from '@hedhog/pagination';
|
3
|
-
import { PrismaModule } from '@hedhog/prisma';
|
4
|
-
import { Module, forwardRef } from '@nestjs/common';
|
5
|
-
import { AuthModule } from '../auth/auth.module';
|
6
|
-
import { SettingsController } from './setting.controller';
|
7
|
-
import { SettingService } from './setting.service';
|
8
|
-
|
9
|
-
@Module({
|
10
|
-
providers: [SettingService],
|
11
|
-
exports: [SettingService],
|
12
|
-
controllers: [SettingsController],
|
13
|
-
imports: [
|
14
|
-
forwardRef(() => AuthModule),
|
15
|
-
forwardRef(() => PrismaModule),
|
16
|
-
forwardRef(() => PaginationModule),
|
17
|
-
forwardRef(() => FileModule),
|
18
|
-
],
|
19
|
-
})
|
20
|
-
export class SettingModule {}
|
@@ -1,183 +0,0 @@
|
|
1
|
-
import { PaginationService } from '@hedhog/pagination';
|
2
|
-
import { PrismaService } from '@hedhog/prisma';
|
3
|
-
import { BadRequestException } from '@nestjs/common';
|
4
|
-
import { Test, TestingModule } from '@nestjs/testing';
|
5
|
-
import { DeleteDTO } from '../dto/delete.dto';
|
6
|
-
import { UpdateDTO } from './dto/update.dto';
|
7
|
-
import { SettingService } from './setting.service';
|
8
|
-
|
9
|
-
describe('SettingService', () => {
|
10
|
-
let service: SettingService;
|
11
|
-
let prismaService: PrismaService;
|
12
|
-
// let paginationService: PaginationService;
|
13
|
-
|
14
|
-
beforeEach(async () => {
|
15
|
-
const module: TestingModule = await Test.createTestingModule({
|
16
|
-
providers: [
|
17
|
-
SettingService,
|
18
|
-
{
|
19
|
-
provide: PrismaService,
|
20
|
-
useValue: {
|
21
|
-
setting: {
|
22
|
-
findUnique: jest.fn(),
|
23
|
-
create: jest.fn(),
|
24
|
-
update: jest.fn(),
|
25
|
-
deleteMany: jest.fn(),
|
26
|
-
},
|
27
|
-
createInsensitiveSearch: jest.fn(),
|
28
|
-
},
|
29
|
-
},
|
30
|
-
{
|
31
|
-
provide: PaginationService,
|
32
|
-
useValue: {
|
33
|
-
paginate: jest.fn(),
|
34
|
-
},
|
35
|
-
},
|
36
|
-
],
|
37
|
-
}).compile();
|
38
|
-
|
39
|
-
service = module.get<SettingService>(SettingService);
|
40
|
-
prismaService = module.get<PrismaService>(PrismaService);
|
41
|
-
// paginationService = module.get<PaginationService>(PaginationService);
|
42
|
-
});
|
43
|
-
|
44
|
-
it('should be defined', () => {
|
45
|
-
expect(service).toBeDefined();
|
46
|
-
});
|
47
|
-
|
48
|
-
/* describe('getSettings', () => {
|
49
|
-
it('should return paginated setting', async () => {
|
50
|
-
const paginationParams: PaginationDTO = {
|
51
|
-
page: 1,
|
52
|
-
pageSize: 10,
|
53
|
-
search: '',
|
54
|
-
sortField: '',
|
55
|
-
sortOrder: PageOrderDirection.Asc,
|
56
|
-
fields: '',
|
57
|
-
};
|
58
|
-
|
59
|
-
const mockPaginatedData = {
|
60
|
-
data: [],
|
61
|
-
total: 10,
|
62
|
-
lastPage: 1,
|
63
|
-
page: 1,
|
64
|
-
prev: 0,
|
65
|
-
next: 2,
|
66
|
-
pageSize: 10,
|
67
|
-
};
|
68
|
-
|
69
|
-
jest.spyOn(prismaService, 'createInsensitiveSearch').mockReturnValue([]);
|
70
|
-
jest
|
71
|
-
.spyOn(paginationService, 'paginate')
|
72
|
-
.mockResolvedValue(mockPaginatedData);
|
73
|
-
|
74
|
-
const result = await service.getSettings(paginationParams);
|
75
|
-
|
76
|
-
expect(prismaService.createInsensitiveSearch).toHaveBeenCalledWith(
|
77
|
-
['name'],
|
78
|
-
paginationParams,
|
79
|
-
);
|
80
|
-
expect(paginationService.paginate).toHaveBeenCalledWith(
|
81
|
-
prismaService.setting,
|
82
|
-
paginationParams,
|
83
|
-
{ where: { OR: [] } },
|
84
|
-
);
|
85
|
-
expect(result).toEqual(mockPaginatedData);
|
86
|
-
});
|
87
|
-
});*/
|
88
|
-
|
89
|
-
describe('get', () => {
|
90
|
-
it('should return a specific setting by ID', async () => {
|
91
|
-
const mockSetting = {
|
92
|
-
id: 1,
|
93
|
-
name: 'Test Setting',
|
94
|
-
created_at: new Date(),
|
95
|
-
updated_at: new Date(),
|
96
|
-
};
|
97
|
-
jest
|
98
|
-
.spyOn(prismaService.setting, 'findUnique')
|
99
|
-
.mockResolvedValue(mockSetting);
|
100
|
-
|
101
|
-
const result = await service.get(1);
|
102
|
-
|
103
|
-
expect(prismaService.setting.findUnique).toHaveBeenCalledWith({
|
104
|
-
where: { id: 1 },
|
105
|
-
});
|
106
|
-
expect(result).toEqual(mockSetting);
|
107
|
-
});
|
108
|
-
});
|
109
|
-
/*
|
110
|
-
describe('create', () => {
|
111
|
-
it('should create a new setting', async () => {
|
112
|
-
const createDTO: CreateDTO = { name: 'New Setting' };
|
113
|
-
const mockSetting = {
|
114
|
-
id: 1,
|
115
|
-
name: 'Test Setting',
|
116
|
-
created_at: new Date(),
|
117
|
-
updated_at: new Date(),
|
118
|
-
};
|
119
|
-
|
120
|
-
jest
|
121
|
-
.spyOn(prismaService.setting, 'create')
|
122
|
-
.mockResolvedValue(mockSetting);
|
123
|
-
|
124
|
-
const result = await service.create(createDTO);
|
125
|
-
|
126
|
-
expect(prismaService.setting.create).toHaveBeenCalledWith({
|
127
|
-
data: { name: createDTO.name },
|
128
|
-
});
|
129
|
-
expect(result).toEqual(mockSetting);
|
130
|
-
});
|
131
|
-
});*/
|
132
|
-
|
133
|
-
describe('update', () => {
|
134
|
-
it('should update an existing setting', async () => {
|
135
|
-
const updateDTO: UpdateDTO = { name: 'Updated Setting' };
|
136
|
-
const updateInput = { id: 1, data: updateDTO };
|
137
|
-
const mockSetting = {
|
138
|
-
id: 1,
|
139
|
-
name: 'Update Setting',
|
140
|
-
created_at: new Date(),
|
141
|
-
updated_at: new Date(),
|
142
|
-
};
|
143
|
-
|
144
|
-
jest
|
145
|
-
.spyOn(prismaService.setting, 'update')
|
146
|
-
.mockResolvedValue(mockSetting);
|
147
|
-
|
148
|
-
const result = await service.update(updateInput);
|
149
|
-
|
150
|
-
expect(prismaService.setting.update).toHaveBeenCalledWith({
|
151
|
-
where: { id: updateInput.id },
|
152
|
-
data: updateInput.data,
|
153
|
-
});
|
154
|
-
expect(result).toEqual(mockSetting);
|
155
|
-
});
|
156
|
-
});
|
157
|
-
|
158
|
-
describe('delete', () => {
|
159
|
-
it('should throw an error if no ids are provided', async () => {
|
160
|
-
const deleteDTO: DeleteDTO = { ids: null };
|
161
|
-
|
162
|
-
await expect(service.delete(deleteDTO)).rejects.toThrow(
|
163
|
-
new BadRequestException(
|
164
|
-
`You must select at least one setting to delete.`,
|
165
|
-
),
|
166
|
-
);
|
167
|
-
});
|
168
|
-
|
169
|
-
it('should delete setting by ids', async () => {
|
170
|
-
const deleteDTO: DeleteDTO = { ids: [1, 2] };
|
171
|
-
|
172
|
-
jest
|
173
|
-
.spyOn(prismaService.setting, 'deleteMany')
|
174
|
-
.mockResolvedValue({ count: 2 });
|
175
|
-
|
176
|
-
await service.delete(deleteDTO);
|
177
|
-
|
178
|
-
expect(prismaService.setting.deleteMany).toHaveBeenCalledWith({
|
179
|
-
where: { id: { in: deleteDTO.ids } },
|
180
|
-
});
|
181
|
-
});
|
182
|
-
});
|
183
|
-
});
|