@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.
Files changed (166) hide show
  1. package/dist/admin.module.d.ts.map +1 -1
  2. package/dist/admin.module.js +1 -6
  3. package/dist/admin.module.js.map +1 -1
  4. package/dist/auth/auth.controller.d.ts.map +1 -1
  5. package/dist/auth/auth.controller.js +6 -8
  6. package/dist/auth/auth.controller.js.map +1 -1
  7. package/dist/auth/guards/auth.guard.js +2 -2
  8. package/dist/auth/guards/auth.guard.js.map +1 -1
  9. package/dist/index.d.ts +0 -9
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +0 -11
  12. package/dist/index.js.map +1 -1
  13. package/dist/menu/menu.controller.d.ts.map +1 -1
  14. package/dist/menu/menu.controller.js +4 -5
  15. package/dist/menu/menu.controller.js.map +1 -1
  16. package/dist/role/dto/create.dto.d.ts +1 -1
  17. package/dist/role/dto/create.dto.d.ts.map +1 -1
  18. package/dist/role/dto/create.dto.js +2 -2
  19. package/dist/role/dto/create.dto.js.map +1 -1
  20. package/dist/role/guards/role.guard.d.ts.map +1 -1
  21. package/dist/role/guards/role.guard.js +3 -4
  22. package/dist/role/guards/role.guard.js.map +1 -1
  23. package/dist/role/role.controller.js +3 -3
  24. package/dist/role/role.controller.js.map +1 -1
  25. package/dist/role/role.module.js +1 -1
  26. package/dist/role/role.module.js.map +1 -1
  27. package/dist/role/role.service.d.ts +1 -1
  28. package/dist/role/role.service.d.ts.map +1 -1
  29. package/dist/role/role.service.js +1 -1
  30. package/dist/role/role.service.js.map +1 -1
  31. package/dist/route/route.controller.js +3 -3
  32. package/dist/route/route.controller.js.map +1 -1
  33. package/dist/screen/screen.controller.js +3 -3
  34. package/dist/screen/screen.controller.js.map +1 -1
  35. package/dist/user/user.controller.js +2 -2
  36. package/dist/user/user.controller.js.map +1 -1
  37. package/hedhog.yaml +1 -328
  38. package/package.json +8 -6
  39. package/src/admin.module.ts +1 -6
  40. package/src/auth/auth.controller.ts +1 -3
  41. package/src/auth/guards/auth.guard.ts +1 -1
  42. package/src/index.ts +0 -14
  43. package/src/menu/menu.controller.ts +2 -3
  44. package/src/role/dto/create.dto.ts +1 -1
  45. package/src/role/guards/role.guard.ts +1 -2
  46. package/src/role/role.controller.ts +2 -2
  47. package/src/role/role.module.ts +1 -1
  48. package/src/role/role.service.ts +1 -1
  49. package/src/route/route.controller.ts +2 -2
  50. package/src/screen/screen.controller.ts +2 -2
  51. package/src/user/user.controller.ts +1 -1
  52. package/dist/auth/decorators/public.decorator.d.ts +0 -3
  53. package/dist/auth/decorators/public.decorator.d.ts.map +0 -1
  54. package/dist/auth/decorators/public.decorator.js +0 -8
  55. package/dist/auth/decorators/public.decorator.js.map +0 -1
  56. package/dist/auth/decorators/user.decorator.d.ts +0 -2
  57. package/dist/auth/decorators/user.decorator.d.ts.map +0 -1
  58. package/dist/auth/decorators/user.decorator.js +0 -12
  59. package/dist/auth/decorators/user.decorator.js.map +0 -1
  60. package/dist/dto/with-locale.dto.d.ts +0 -4
  61. package/dist/dto/with-locale.dto.d.ts.map +0 -1
  62. package/dist/dto/with-locale.dto.js +0 -23
  63. package/dist/dto/with-locale.dto.js.map +0 -1
  64. package/dist/locale/dto/create.dto.d.ts +0 -6
  65. package/dist/locale/dto/create.dto.d.ts.map +0 -1
  66. package/dist/locale/dto/create.dto.js +0 -29
  67. package/dist/locale/dto/create.dto.js.map +0 -1
  68. package/dist/locale/dto/delete.dto.d.ts +0 -4
  69. package/dist/locale/dto/delete.dto.d.ts.map +0 -1
  70. package/dist/locale/dto/delete.dto.js +0 -23
  71. package/dist/locale/dto/delete.dto.js.map +0 -1
  72. package/dist/locale/dto/set-enabled.dto.d.ts +0 -4
  73. package/dist/locale/dto/set-enabled.dto.d.ts.map +0 -1
  74. package/dist/locale/dto/set-enabled.dto.js +0 -24
  75. package/dist/locale/dto/set-enabled.dto.js.map +0 -1
  76. package/dist/locale/dto/update.dto.d.ts +0 -6
  77. package/dist/locale/dto/update.dto.d.ts.map +0 -1
  78. package/dist/locale/dto/update.dto.js +0 -32
  79. package/dist/locale/dto/update.dto.js.map +0 -1
  80. package/dist/locale/index.d.ts +0 -5
  81. package/dist/locale/index.d.ts.map +0 -1
  82. package/dist/locale/index.js +0 -21
  83. package/dist/locale/index.js.map +0 -1
  84. package/dist/locale/locale.controller.d.ts +0 -18
  85. package/dist/locale/locale.controller.d.ts.map +0 -1
  86. package/dist/locale/locale.controller.js +0 -127
  87. package/dist/locale/locale.controller.js.map +0 -1
  88. package/dist/locale/locale.decorator.d.ts +0 -2
  89. package/dist/locale/locale.decorator.d.ts.map +0 -1
  90. package/dist/locale/locale.decorator.js +0 -9
  91. package/dist/locale/locale.decorator.js.map +0 -1
  92. package/dist/locale/locale.middleware.d.ts +0 -10
  93. package/dist/locale/locale.middleware.d.ts.map +0 -1
  94. package/dist/locale/locale.middleware.js +0 -45
  95. package/dist/locale/locale.middleware.js.map +0 -1
  96. package/dist/locale/locale.module.d.ts +0 -5
  97. package/dist/locale/locale.module.d.ts.map +0 -1
  98. package/dist/locale/locale.module.js +0 -35
  99. package/dist/locale/locale.module.js.map +0 -1
  100. package/dist/locale/locale.service.d.ts +0 -32
  101. package/dist/locale/locale.service.d.ts.map +0 -1
  102. package/dist/locale/locale.service.js +0 -290
  103. package/dist/locale/locale.service.js.map +0 -1
  104. package/dist/locale/locale.service.spec.d.ts +0 -2
  105. package/dist/locale/locale.service.spec.d.ts.map +0 -1
  106. package/dist/locale/locale.service.spec.js +0 -174
  107. package/dist/locale/locale.service.spec.js.map +0 -1
  108. package/dist/role/decorators/role.decorator.d.ts +0 -3
  109. package/dist/role/decorators/role.decorator.d.ts.map +0 -1
  110. package/dist/role/decorators/role.decorator.js +0 -10
  111. package/dist/role/decorators/role.decorator.js.map +0 -1
  112. package/dist/setting/dto/create.dto.d.ts +0 -3
  113. package/dist/setting/dto/create.dto.d.ts.map +0 -1
  114. package/dist/setting/dto/create.dto.js +0 -7
  115. package/dist/setting/dto/create.dto.js.map +0 -1
  116. package/dist/setting/dto/setting-user.dto.d.ts +0 -4
  117. package/dist/setting/dto/setting-user.dto.d.ts.map +0 -1
  118. package/dist/setting/dto/setting-user.dto.js +0 -21
  119. package/dist/setting/dto/setting-user.dto.js.map +0 -1
  120. package/dist/setting/dto/setting.dto.d.ts +0 -9
  121. package/dist/setting/dto/setting.dto.d.ts.map +0 -1
  122. package/dist/setting/dto/setting.dto.js +0 -34
  123. package/dist/setting/dto/setting.dto.js.map +0 -1
  124. package/dist/setting/dto/update.dto.d.ts +0 -4
  125. package/dist/setting/dto/update.dto.d.ts.map +0 -1
  126. package/dist/setting/dto/update.dto.js +0 -8
  127. package/dist/setting/dto/update.dto.js.map +0 -1
  128. package/dist/setting/setting.controller.d.ts +0 -25
  129. package/dist/setting/setting.controller.d.ts.map +0 -1
  130. package/dist/setting/setting.controller.js +0 -150
  131. package/dist/setting/setting.controller.js.map +0 -1
  132. package/dist/setting/setting.module.d.ts +0 -3
  133. package/dist/setting/setting.module.d.ts.map +0 -1
  134. package/dist/setting/setting.module.js +0 -31
  135. package/dist/setting/setting.module.js.map +0 -1
  136. package/dist/setting/setting.service.d.ts +0 -31
  137. package/dist/setting/setting.service.d.ts.map +0 -1
  138. package/dist/setting/setting.service.js +0 -314
  139. package/dist/setting/setting.service.js.map +0 -1
  140. package/dist/setting/setting.service.spec.d.ts +0 -2
  141. package/dist/setting/setting.service.spec.d.ts.map +0 -1
  142. package/dist/setting/setting.service.spec.js +0 -162
  143. package/dist/setting/setting.service.spec.js.map +0 -1
  144. package/src/auth/decorators/public.decorator.ts +0 -4
  145. package/src/auth/decorators/user.decorator.ts +0 -17
  146. package/src/dto/with-locale.dto.ts +0 -8
  147. package/src/locale/dto/create.dto.ts +0 -12
  148. package/src/locale/dto/delete.dto.ts +0 -8
  149. package/src/locale/dto/set-enabled.dto.ts +0 -9
  150. package/src/locale/dto/update.dto.ts +0 -15
  151. package/src/locale/index.ts +0 -4
  152. package/src/locale/locale.controller.ts +0 -79
  153. package/src/locale/locale.decorator.ts +0 -8
  154. package/src/locale/locale.middleware.ts +0 -34
  155. package/src/locale/locale.module.ts +0 -23
  156. package/src/locale/locale.service.spec.ts +0 -193
  157. package/src/locale/locale.service.ts +0 -364
  158. package/src/role/decorators/role.decorator.ts +0 -7
  159. package/src/setting/dto/create.dto.ts +0 -1
  160. package/src/setting/dto/setting-user.dto.ts +0 -6
  161. package/src/setting/dto/setting.dto.ts +0 -17
  162. package/src/setting/dto/update.dto.ts +0 -3
  163. package/src/setting/setting.controller.ts +0 -100
  164. package/src/setting/setting.module.ts +0 -18
  165. package/src/setting/setting.service.spec.ts +0 -183
  166. package/src/setting/setting.service.ts +0 -384
@@ -1,162 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const pagination_1 = require("@hedhog/pagination");
4
- const prisma_1 = require("@hedhog/prisma");
5
- const common_1 = require("@nestjs/common");
6
- const testing_1 = require("@nestjs/testing");
7
- const setting_service_1 = require("./setting.service");
8
- describe('SettingService', () => {
9
- let service;
10
- let prismaService;
11
- // let paginationService: PaginationService;
12
- beforeEach(async () => {
13
- const module = await testing_1.Test.createTestingModule({
14
- providers: [
15
- setting_service_1.SettingService,
16
- {
17
- provide: prisma_1.PrismaService,
18
- useValue: {
19
- setting: {
20
- findUnique: jest.fn(),
21
- create: jest.fn(),
22
- update: jest.fn(),
23
- deleteMany: jest.fn(),
24
- },
25
- createInsensitiveSearch: jest.fn(),
26
- },
27
- },
28
- {
29
- provide: pagination_1.PaginationService,
30
- useValue: {
31
- paginate: jest.fn(),
32
- },
33
- },
34
- ],
35
- }).compile();
36
- service = module.get(setting_service_1.SettingService);
37
- prismaService = module.get(prisma_1.PrismaService);
38
- // paginationService = module.get<PaginationService>(PaginationService);
39
- });
40
- it('should be defined', () => {
41
- expect(service).toBeDefined();
42
- });
43
- /* describe('getSettings', () => {
44
- it('should return paginated setting', async () => {
45
- const paginationParams: PaginationDTO = {
46
- page: 1,
47
- pageSize: 10,
48
- search: '',
49
- sortField: '',
50
- sortOrder: PageOrderDirection.Asc,
51
- fields: '',
52
- };
53
-
54
- const mockPaginatedData = {
55
- data: [],
56
- total: 10,
57
- lastPage: 1,
58
- page: 1,
59
- prev: 0,
60
- next: 2,
61
- pageSize: 10,
62
- };
63
-
64
- jest.spyOn(prismaService, 'createInsensitiveSearch').mockReturnValue([]);
65
- jest
66
- .spyOn(paginationService, 'paginate')
67
- .mockResolvedValue(mockPaginatedData);
68
-
69
- const result = await service.getSettings(paginationParams);
70
-
71
- expect(prismaService.createInsensitiveSearch).toHaveBeenCalledWith(
72
- ['name'],
73
- paginationParams,
74
- );
75
- expect(paginationService.paginate).toHaveBeenCalledWith(
76
- prismaService.setting,
77
- paginationParams,
78
- { where: { OR: [] } },
79
- );
80
- expect(result).toEqual(mockPaginatedData);
81
- });
82
- });*/
83
- describe('get', () => {
84
- it('should return a specific setting by ID', async () => {
85
- const mockSetting = {
86
- id: 1,
87
- name: 'Test Setting',
88
- created_at: new Date(),
89
- updated_at: new Date(),
90
- };
91
- jest
92
- .spyOn(prismaService.setting, 'findUnique')
93
- .mockResolvedValue(mockSetting);
94
- const result = await service.get(1);
95
- expect(prismaService.setting.findUnique).toHaveBeenCalledWith({
96
- where: { id: 1 },
97
- });
98
- expect(result).toEqual(mockSetting);
99
- });
100
- });
101
- /*
102
- describe('create', () => {
103
- it('should create a new setting', async () => {
104
- const createDTO: CreateDTO = { name: 'New Setting' };
105
- const mockSetting = {
106
- id: 1,
107
- name: 'Test Setting',
108
- created_at: new Date(),
109
- updated_at: new Date(),
110
- };
111
-
112
- jest
113
- .spyOn(prismaService.setting, 'create')
114
- .mockResolvedValue(mockSetting);
115
-
116
- const result = await service.create(createDTO);
117
-
118
- expect(prismaService.setting.create).toHaveBeenCalledWith({
119
- data: { name: createDTO.name },
120
- });
121
- expect(result).toEqual(mockSetting);
122
- });
123
- });*/
124
- describe('update', () => {
125
- it('should update an existing setting', async () => {
126
- const updateDTO = { name: 'Updated Setting' };
127
- const updateInput = { id: 1, data: updateDTO };
128
- const mockSetting = {
129
- id: 1,
130
- name: 'Update Setting',
131
- created_at: new Date(),
132
- updated_at: new Date(),
133
- };
134
- jest
135
- .spyOn(prismaService.setting, 'update')
136
- .mockResolvedValue(mockSetting);
137
- const result = await service.update(updateInput);
138
- expect(prismaService.setting.update).toHaveBeenCalledWith({
139
- where: { id: updateInput.id },
140
- data: updateInput.data,
141
- });
142
- expect(result).toEqual(mockSetting);
143
- });
144
- });
145
- describe('delete', () => {
146
- it('should throw an error if no ids are provided', async () => {
147
- const deleteDTO = { ids: null };
148
- await expect(service.delete(deleteDTO)).rejects.toThrow(new common_1.BadRequestException(`You must select at least one setting to delete.`));
149
- });
150
- it('should delete setting by ids', async () => {
151
- const deleteDTO = { ids: [1, 2] };
152
- jest
153
- .spyOn(prismaService.setting, 'deleteMany')
154
- .mockResolvedValue({ count: 2 });
155
- await service.delete(deleteDTO);
156
- expect(prismaService.setting.deleteMany).toHaveBeenCalledWith({
157
- where: { id: { in: deleteDTO.ids } },
158
- });
159
- });
160
- });
161
- });
162
- //# sourceMappingURL=setting.service.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setting.service.spec.js","sourceRoot":"","sources":["../../src/setting/setting.service.spec.ts"],"names":[],"mappings":";;AAAA,mDAAuD;AACvD,2CAA+C;AAC/C,2CAAqD;AACrD,6CAAsD;AAGtD,uDAAmD;AAEnD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,IAAI,OAAuB,CAAC;IAC5B,IAAI,aAA4B,CAAC;IACjC,4CAA4C;IAE5C,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,MAAM,MAAM,GAAkB,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC3D,SAAS,EAAE;gBACT,gCAAc;gBACd;oBACE,OAAO,EAAE,sBAAa;oBACtB,QAAQ,EAAE;wBACR,OAAO,EAAE;4BACP,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;4BACrB,MAAM,EAAE,IAA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AC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACrD,IAAI,4BAAmB,CACrB,iDAAiD,CAClD,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,8BAA8B,EAAE,KAAK,IAAI,EAAE;YAC5C,MAAM,SAAS,GAAc,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;YAE7C,IAAI;iBACD,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,YAAY,CAAC;iBAC1C,iBAAiB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;YAEnC,MAAM,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YAEhC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,oBAAoB,CAAC;gBAC5D,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,SAAS,CAAC,GAAG,EAAE,EAAE;aACrC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,4 +0,0 @@
1
- import { SetMetadata } from '@nestjs/common';
2
-
3
- export const IS_PUBLIC_KEY = 'isPublic';
4
- export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);
@@ -1,17 +0,0 @@
1
- import {
2
- createParamDecorator,
3
- ExecutionContext,
4
- UnauthorizedException,
5
- } from '@nestjs/common';
6
-
7
- export const User = createParamDecorator(
8
- (field: string | null = null, ctx: ExecutionContext) => {
9
- const request = ctx.switchToHttp().getRequest();
10
-
11
- if (!request.auth || !request.auth.user) {
12
- throw new UnauthorizedException(`User is not authenticated`);
13
- }
14
-
15
- return field ? request.auth.user[field] : request.auth.user;
16
- },
17
- );
@@ -1,8 +0,0 @@
1
- import { IsObject, IsOptional, ValidateNested } from 'class-validator';
2
-
3
- export class WithLocaleDTO {
4
- @IsOptional()
5
- @IsObject()
6
- @ValidateNested({ each: true })
7
- locale: Record<string, Record<string, string>>;
8
- }
@@ -1,12 +0,0 @@
1
- import { IsString } from 'class-validator';
2
-
3
- export class CreateDTO {
4
- @IsString()
5
- name: string;
6
-
7
- @IsString()
8
- code: string;
9
-
10
- @IsString()
11
- region: string;
12
- }
@@ -1,8 +0,0 @@
1
- import { ArrayMinSize, IsArray, IsInt } from 'class-validator';
2
-
3
- export class DeleteDTO {
4
- @IsArray()
5
- @ArrayMinSize(1)
6
- @IsInt({ each: true })
7
- ids: number[];
8
- }
@@ -1,9 +0,0 @@
1
- import { IsString, IsArray } from 'class-validator';
2
-
3
- export class SetEnabledDTO {
4
- @IsArray()
5
- @IsString({
6
- each: true,
7
- })
8
- codes: string[];
9
- }
@@ -1,15 +0,0 @@
1
- import { IsOptional, IsString } from 'class-validator';
2
-
3
- export class UpdateDTO {
4
- @IsString()
5
- @IsOptional()
6
- name?: string;
7
-
8
- @IsString()
9
- @IsOptional()
10
- code?: string;
11
-
12
- @IsString()
13
- @IsOptional()
14
- region?: string;
15
- }
@@ -1,4 +0,0 @@
1
- export * from './locale.module';
2
- export * from './locale.service';
3
- export * from './locale.controller';
4
- export * from './locale.decorator';
@@ -1,79 +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
- } from '@nestjs/common';
15
- import { Public } from '../auth/decorators/public.decorator';
16
- import { Role } from '../role/decorators/role.decorator';
17
- import { CreateDTO } from './dto/create.dto';
18
- import { DeleteDTO } from './dto/delete.dto';
19
- import { SetEnabledDTO } from './dto/set-enabled.dto';
20
- import { UpdateDTO } from './dto/update.dto';
21
- import { Locale } from './locale.decorator';
22
- import { LocaleService } from './locale.service';
23
-
24
- @Role()
25
- @Controller('locale')
26
- export class LocaleController {
27
- constructor(
28
- @Inject(forwardRef(() => LocaleService))
29
- private readonly localeService: LocaleService,
30
- ) {}
31
-
32
- @Public()
33
- @Get('system/enabled')
34
- async listEnabled(@Pagination() paginationParams, @Locale() locale: string) {
35
- return this.localeService.getEnables(locale, paginationParams);
36
- }
37
-
38
- @Public()
39
- @Get(':localeCode/:namespace')
40
- async getTranslations(
41
- @Param('localeCode') localeCode: string,
42
- @Param('namespace') namespace: string,
43
- ) {
44
- return this.localeService.getTranslations(localeCode, namespace);
45
- }
46
-
47
- @Get()
48
- async get(@Pagination() paginationParams, @Locale() locale: string) {
49
- return this.localeService.get(locale, paginationParams);
50
- }
51
-
52
- @Get(':id')
53
- async getById(@Param('id', ParseIntPipe) id: number) {
54
- return this.localeService.getById(id);
55
- }
56
-
57
- @Post()
58
- create(@Body() data: CreateDTO) {
59
- return this.localeService.create(data);
60
- }
61
-
62
- @Put()
63
- async setEnabled(@Body() { codes }: SetEnabledDTO) {
64
- return this.localeService.setEnabled(codes);
65
- }
66
-
67
- @Patch(':id')
68
- async update(@Param('id', ParseIntPipe) id: number, @Body() data: UpdateDTO) {
69
- return this.localeService.update({
70
- id,
71
- data,
72
- });
73
- }
74
-
75
- @Delete()
76
- async delete(@Body() data: DeleteDTO) {
77
- return this.localeService.delete(data);
78
- }
79
- }
@@ -1,8 +0,0 @@
1
- import { createParamDecorator, ExecutionContext } from '@nestjs/common';
2
-
3
- export const Locale = createParamDecorator(
4
- (_data: unknown, ctx: ExecutionContext) => {
5
- const request = ctx.switchToHttp().getRequest();
6
- return request['locale'];
7
- },
8
- );
@@ -1,34 +0,0 @@
1
- import { PrismaService } from '@hedhog/prisma';
2
- import { Injectable, NestMiddleware } from '@nestjs/common';
3
- import { NextFunction, Request, Response } from 'express';
4
-
5
- @Injectable()
6
- export class LocaleMiddleware implements NestMiddleware {
7
- private languages = [];
8
-
9
- constructor(private prisma: PrismaService) {}
10
-
11
- async use(req: Request, _res: Response, next: NextFunction) {
12
- const locale = req.headers['accept-language'] || 'en-US';
13
- let code = locale.split(',')[0].split('-')[0];
14
-
15
- if (!this.languages.length) {
16
- const locale = await this.prisma.locale.findMany({
17
- select: {
18
- code: true,
19
- },
20
- });
21
-
22
- for (const l of locale) {
23
- this.languages.push(l.code);
24
- }
25
- }
26
-
27
- if (!this.languages.includes(code)) {
28
- code = 'en';
29
- }
30
-
31
- req['locale'] = code;
32
- next();
33
- }
34
- }
@@ -1,23 +0,0 @@
1
- import { PaginationModule } from '@hedhog/pagination';
2
- import { PrismaModule } from '@hedhog/prisma';
3
- import { forwardRef, MiddlewareConsumer, Module } from '@nestjs/common';
4
- import { LocaleService } from './locale.service';
5
- import { LocaleController } from './locale.controller';
6
- import { LocaleMiddleware } from './locale.middleware';
7
- import { AuthModule } from '../auth/auth.module';
8
-
9
- @Module({
10
- imports: [
11
- forwardRef(() => AuthModule),
12
- forwardRef(() => PrismaModule),
13
- forwardRef(() => PaginationModule),
14
- ],
15
- controllers: [LocaleController],
16
- providers: [LocaleService],
17
- exports: [LocaleService],
18
- })
19
- export class LocaleModule {
20
- configure(consumer: MiddlewareConsumer) {
21
- consumer.apply(LocaleMiddleware).forRoutes('*');
22
- }
23
- }
@@ -1,193 +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 { CreateDTO } from './dto/create.dto';
6
- import { DeleteDTO } from './dto/delete.dto';
7
- import { UpdateDTO } from './dto/update.dto';
8
- import { LocaleService } from './locale.service';
9
-
10
- describe('LocaleService', () => {
11
- let service: LocaleService;
12
- let prismaService: PrismaService;
13
- let paginationService: PaginationService;
14
-
15
- beforeEach(async () => {
16
- const module: TestingModule = await Test.createTestingModule({
17
- providers: [
18
- LocaleService,
19
- {
20
- provide: PrismaService,
21
- useValue: {
22
- translation: {
23
- findMany: jest.fn(),
24
- },
25
- locale: {
26
- findUnique: jest.fn(),
27
- create: jest.fn(),
28
- update: jest.fn(),
29
- deleteMany: jest.fn(),
30
- },
31
- },
32
- },
33
- {
34
- provide: PaginationService,
35
- useValue: {
36
- paginate: jest.fn(),
37
- },
38
- },
39
- ],
40
- }).compile();
41
-
42
- service = module.get<LocaleService>(LocaleService);
43
- prismaService = module.get<PrismaService>(PrismaService);
44
- paginationService = module.get<PaginationService>(PaginationService);
45
- });
46
-
47
- it('should be defined', () => {
48
- expect(service).toBeDefined();
49
- });
50
-
51
- describe('getTranslations', () => {
52
- it('should throw BadRequestException when localeCode is not provided', async () => {
53
- await expect(service.getTranslations('', 'namespace')).rejects.toThrow(
54
- BadRequestException,
55
- );
56
- });
57
-
58
- it('should return translation for a given localeCode and namespace', async () => {
59
- const mockTranslations = [
60
- {
61
- id: 1,
62
- locale_id: 1,
63
- namespace_id: 1,
64
- name: 'hello',
65
- value: 'Hello',
66
- created_at: new Date(),
67
- updated_at: new Date(),
68
- },
69
- ];
70
- jest
71
- .spyOn(prismaService.translation, 'findMany')
72
- .mockResolvedValue(mockTranslations);
73
-
74
- const result = await service.getTranslations('en-US', 'namespace');
75
- expect(result).toEqual({ hello: 'Hello' });
76
- });
77
- });
78
- /*
79
- describe('get', () => {
80
- it('should paginate locale', async () => {
81
- const mockPaginationResult = {
82
- data: [],
83
- total: 10,
84
- lastPage: 1,
85
- page: 1,
86
- prev: 0,
87
- next: 2,
88
- pageSize: 10,
89
- };
90
- jest
91
- .spyOn(paginationService, 'paginate')
92
- .mockResolvedValue(mockPaginationResult);
93
-
94
- const paginationParams: PaginationDTO = {
95
- page: 1,
96
- pageSize: 20,
97
- sortField: '',
98
- sortOrder: PageOrderDirection.Asc,
99
- fields: '',
100
- search: '',
101
- };
102
- const result = await service.get(paginationParams );
103
-
104
- expect(paginationService.paginate).toHaveBeenCalledWith(
105
- prismaService.locale,
106
- paginationParams,
107
- expect.anything(),
108
- );
109
- expect(result).toBe(mockPaginationResult);
110
- });
111
- });
112
- */
113
- describe('getById', () => {
114
- it('should return a locale by ID', async () => {
115
- const mockLocale = {
116
- id: 1,
117
- name: 'English',
118
- code: 'en',
119
- region: 'us',
120
- created_at: new Date(),
121
- updated_at: new Date(),
122
- };
123
- jest
124
- .spyOn(prismaService.locale, 'findUnique')
125
- .mockResolvedValue(mockLocale);
126
-
127
- const result = await service.getById(1);
128
- expect(result).toBe(mockLocale);
129
- });
130
- });
131
-
132
- describe('create', () => {
133
- it('should create a new locale', async () => {
134
- const mockCreateDTO: CreateDTO = {
135
- name: 'English',
136
- code: 'en',
137
- region: 'us',
138
- };
139
- const mockLocale = {
140
- id: 1,
141
- name: 'English',
142
- code: 'en',
143
- region: 'us',
144
- created_at: new Date(),
145
- updated_at: new Date(),
146
- };
147
- jest.spyOn(prismaService.locale, 'create').mockResolvedValue(mockLocale);
148
-
149
- const result = await service.create(mockCreateDTO);
150
- expect(result).toBe(mockLocale);
151
- });
152
- });
153
-
154
- describe('update', () => {
155
- it('should update a locale', async () => {
156
- const mockUpdateDTO: UpdateDTO = {
157
- name: 'English Updated',
158
- code: 'en',
159
- region: 'us',
160
- };
161
- const mockLocale = {
162
- id: 1,
163
- name: 'English Updated',
164
- code: 'en',
165
- region: 'us',
166
- created_at: new Date(),
167
- updated_at: new Date(),
168
- };
169
- jest.spyOn(prismaService.locale, 'update').mockResolvedValue(mockLocale);
170
-
171
- const result = await service.update({ id: 1, data: mockUpdateDTO });
172
- expect(result).toBe(mockLocale);
173
- });
174
- });
175
-
176
- describe('delete', () => {
177
- it('should throw BadRequestException if no IDs are provided', async () => {
178
- await expect(service.delete({ ids: null })).rejects.toThrow(
179
- BadRequestException,
180
- );
181
- });
182
-
183
- it('should delete locale by IDs', async () => {
184
- const mockDeleteDTO: DeleteDTO = { ids: [1, 2, 3] };
185
- jest
186
- .spyOn(prismaService.locale, 'deleteMany')
187
- .mockResolvedValue({ count: 3 });
188
-
189
- const result = await service.delete(mockDeleteDTO);
190
- expect(result.count).toBe(3);
191
- });
192
- });
193
- });