@flusys/nestjs-localization 4.0.0-lts

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.
Files changed (89) hide show
  1. package/README.md +870 -0
  2. package/cjs/config/index.js +19 -0
  3. package/cjs/config/localization.constants.js +20 -0
  4. package/cjs/config/message-keys.js +77 -0
  5. package/cjs/controllers/index.js +20 -0
  6. package/cjs/controllers/language.controller.js +188 -0
  7. package/cjs/controllers/translation-key.controller.js +174 -0
  8. package/cjs/controllers/translation.controller.js +254 -0
  9. package/cjs/dtos/index.js +20 -0
  10. package/cjs/dtos/language.dto.js +205 -0
  11. package/cjs/dtos/translation-key.dto.js +233 -0
  12. package/cjs/dtos/translation.dto.js +298 -0
  13. package/cjs/entities/index.js +42 -0
  14. package/cjs/entities/language.entity.js +126 -0
  15. package/cjs/entities/translation-key.entity.js +125 -0
  16. package/cjs/entities/translation.entity.js +120 -0
  17. package/cjs/index.js +24 -0
  18. package/cjs/interfaces/index.js +21 -0
  19. package/cjs/interfaces/language.interface.js +4 -0
  20. package/cjs/interfaces/localization-module-options.interface.js +4 -0
  21. package/cjs/interfaces/translation-key.interface.js +4 -0
  22. package/cjs/interfaces/translation.interface.js +4 -0
  23. package/cjs/modules/index.js +18 -0
  24. package/cjs/modules/localization.module.js +115 -0
  25. package/cjs/services/index.js +22 -0
  26. package/cjs/services/language.service.js +108 -0
  27. package/cjs/services/localization-config.service.js +66 -0
  28. package/cjs/services/localization-datasource.provider.js +122 -0
  29. package/cjs/services/translation-key.service.js +184 -0
  30. package/cjs/services/translation.service.js +222 -0
  31. package/config/index.d.ts +2 -0
  32. package/config/localization.constants.d.ts +2 -0
  33. package/config/message-keys.d.ts +96 -0
  34. package/controllers/index.d.ts +3 -0
  35. package/controllers/language.controller.d.ts +25 -0
  36. package/controllers/translation-key.controller.d.ts +22 -0
  37. package/controllers/translation.controller.d.ts +25 -0
  38. package/dtos/index.d.ts +3 -0
  39. package/dtos/language.dto.d.ts +24 -0
  40. package/dtos/translation-key.dto.d.ts +29 -0
  41. package/dtos/translation.dto.d.ts +42 -0
  42. package/entities/index.d.ts +8 -0
  43. package/entities/language.entity.d.ts +13 -0
  44. package/entities/translation-key.entity.d.ts +13 -0
  45. package/entities/translation.entity.d.ts +12 -0
  46. package/fesm/config/index.js +2 -0
  47. package/fesm/config/localization.constants.js +2 -0
  48. package/fesm/config/message-keys.js +54 -0
  49. package/fesm/controllers/index.js +3 -0
  50. package/fesm/controllers/language.controller.js +178 -0
  51. package/fesm/controllers/translation-key.controller.js +164 -0
  52. package/fesm/controllers/translation.controller.js +244 -0
  53. package/fesm/dtos/index.js +3 -0
  54. package/fesm/dtos/language.dto.js +184 -0
  55. package/fesm/dtos/translation-key.dto.js +209 -0
  56. package/fesm/dtos/translation.dto.js +265 -0
  57. package/fesm/entities/index.js +14 -0
  58. package/fesm/entities/language.entity.js +116 -0
  59. package/fesm/entities/translation-key.entity.js +115 -0
  60. package/fesm/entities/translation.entity.js +110 -0
  61. package/fesm/index.js +7 -0
  62. package/fesm/interfaces/index.js +4 -0
  63. package/fesm/interfaces/language.interface.js +1 -0
  64. package/fesm/interfaces/localization-module-options.interface.js +1 -0
  65. package/fesm/interfaces/translation-key.interface.js +1 -0
  66. package/fesm/interfaces/translation.interface.js +1 -0
  67. package/fesm/modules/index.js +1 -0
  68. package/fesm/modules/localization.module.js +105 -0
  69. package/fesm/services/index.js +5 -0
  70. package/fesm/services/language.service.js +98 -0
  71. package/fesm/services/localization-config.service.js +56 -0
  72. package/fesm/services/localization-datasource.provider.js +112 -0
  73. package/fesm/services/translation-key.service.js +174 -0
  74. package/fesm/services/translation.service.js +212 -0
  75. package/index.d.ts +7 -0
  76. package/interfaces/index.d.ts +4 -0
  77. package/interfaces/language.interface.d.ts +10 -0
  78. package/interfaces/localization-module-options.interface.d.ts +21 -0
  79. package/interfaces/translation-key.interface.d.ts +11 -0
  80. package/interfaces/translation.interface.d.ts +13 -0
  81. package/modules/index.d.ts +1 -0
  82. package/modules/localization.module.d.ts +8 -0
  83. package/package.json +81 -0
  84. package/services/index.d.ts +5 -0
  85. package/services/language.service.d.ts +18 -0
  86. package/services/localization-config.service.d.ts +11 -0
  87. package/services/localization-datasource.provider.d.ts +16 -0
  88. package/services/translation-key.service.d.ts +23 -0
  89. package/services/translation.service.d.ts +30 -0
@@ -0,0 +1,22 @@
1
+ import { ListResponseDto, SingleResponseDto } from '@flusys/nestjs-shared/dtos';
2
+ import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
3
+ import { CreateTranslationKeyDto, GetByModuleDto, TranslationKeyResponseDto, UpdateTranslationKeyDto } from '../dtos';
4
+ import { ITranslationKey } from '../interfaces';
5
+ import { TranslationKeyService } from '../services';
6
+ declare const TranslationKeyController_base: abstract new (service: TranslationKeyService) => {
7
+ service: TranslationKeyService;
8
+ insert(addDto: CreateTranslationKeyDto, user: ILoggedUserInfo | null): Promise<SingleResponseDto<TranslationKeyResponseDto>>;
9
+ insertMany(addDto: CreateTranslationKeyDto[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").BulkResponseDto<TranslationKeyResponseDto>>;
10
+ getById(id: string, body: import("@flusys/nestjs-shared/dtos").GetByIdBodyDto, user: ILoggedUserInfo | null): Promise<SingleResponseDto<TranslationKeyResponseDto>>;
11
+ update(updateDto: UpdateTranslationKeyDto, user: ILoggedUserInfo | null): Promise<SingleResponseDto<TranslationKeyResponseDto>>;
12
+ updateMany(updateDtos: UpdateTranslationKeyDto[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").BulkResponseDto<TranslationKeyResponseDto>>;
13
+ getAll(filterAndPaginationDto: import("@flusys/nestjs-shared/dtos").FilterAndPaginationDto, user: ILoggedUserInfo | null, search?: string): Promise<ListResponseDto<TranslationKeyResponseDto>>;
14
+ delete(deleteDto: import("@flusys/nestjs-shared/dtos").DeleteDto, user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").MessageResponseDto>;
15
+ };
16
+ export declare class TranslationKeyController extends TranslationKeyController_base {
17
+ service: TranslationKeyService;
18
+ constructor(service: TranslationKeyService);
19
+ getModules(_user: ILoggedUserInfo): Promise<SingleResponseDto<string[]>>;
20
+ getByModule(body: GetByModuleDto, _user: ILoggedUserInfo): Promise<ListResponseDto<ITranslationKey>>;
21
+ }
22
+ export {};
@@ -0,0 +1,25 @@
1
+ import { BulkResponseDto, ListResponseDto, SingleResponseDto } from '@flusys/nestjs-shared/dtos';
2
+ import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
3
+ import { BulkUpdateTranslationsDto, CreateTranslationDto, GetTranslationsByLanguageDto, GetTranslationsByModuleDto, TranslationResponseDto, UpdateTranslationDto } from '../dtos';
4
+ import { ITranslation, ITranslationKey, ITranslationsMap } from '../interfaces';
5
+ import { TranslationService } from '../services';
6
+ declare const TranslationController_base: abstract new (service: TranslationService) => {
7
+ service: TranslationService;
8
+ insert(addDto: CreateTranslationDto, user: ILoggedUserInfo | null): Promise<SingleResponseDto<TranslationResponseDto>>;
9
+ insertMany(addDto: CreateTranslationDto[], user: ILoggedUserInfo | null): Promise<BulkResponseDto<TranslationResponseDto>>;
10
+ getById(id: string, body: import("@flusys/nestjs-shared/dtos").GetByIdBodyDto, user: ILoggedUserInfo | null): Promise<SingleResponseDto<TranslationResponseDto>>;
11
+ update(updateDto: UpdateTranslationDto, user: ILoggedUserInfo | null): Promise<SingleResponseDto<TranslationResponseDto>>;
12
+ updateMany(updateDtos: UpdateTranslationDto[], user: ILoggedUserInfo | null): Promise<BulkResponseDto<TranslationResponseDto>>;
13
+ getAll(filterAndPaginationDto: import("@flusys/nestjs-shared/dtos").FilterAndPaginationDto, user: ILoggedUserInfo | null, search?: string): Promise<ListResponseDto<TranslationResponseDto>>;
14
+ delete(deleteDto: import("@flusys/nestjs-shared/dtos").DeleteDto, user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").MessageResponseDto>;
15
+ };
16
+ export declare class TranslationController extends TranslationController_base {
17
+ service: TranslationService;
18
+ constructor(service: TranslationService);
19
+ getByLanguage(body: GetTranslationsByLanguageDto): Promise<SingleResponseDto<ITranslationsMap>>;
20
+ getByModule(body: GetTranslationsByModuleDto): Promise<SingleResponseDto<ITranslationsMap>>;
21
+ updateManyValues(body: BulkUpdateTranslationsDto, _user: ILoggedUserInfo): Promise<BulkResponseDto<ITranslation>>;
22
+ getMissing(body: GetTranslationsByLanguageDto, _user: ILoggedUserInfo): Promise<ListResponseDto<ITranslationKey>>;
23
+ getCounts(_user: ILoggedUserInfo): Promise<SingleResponseDto<Record<string, number>>>;
24
+ }
25
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './language.dto';
2
+ export * from './translation-key.dto';
3
+ export * from './translation.dto';
@@ -0,0 +1,24 @@
1
+ import { IdentityResponseDto } from '@flusys/nestjs-shared/dtos';
2
+ export declare class CreateLanguageDto {
3
+ code: string;
4
+ name: string;
5
+ nativeName?: string;
6
+ direction?: 'ltr' | 'rtl';
7
+ isActive?: boolean;
8
+ isDefault?: boolean;
9
+ serial?: number;
10
+ }
11
+ declare const UpdateLanguageDto_base: import("@nestjs/common").Type<Partial<CreateLanguageDto>>;
12
+ export declare class UpdateLanguageDto extends UpdateLanguageDto_base {
13
+ id: string;
14
+ }
15
+ export declare class LanguageResponseDto extends IdentityResponseDto {
16
+ code: string;
17
+ name: string;
18
+ nativeName: string | null;
19
+ direction: 'ltr' | 'rtl' | null;
20
+ isActive: boolean;
21
+ isDefault: boolean;
22
+ serial: number | null;
23
+ }
24
+ export {};
@@ -0,0 +1,29 @@
1
+ import { IdentityResponseDto } from '@flusys/nestjs-shared/dtos';
2
+ export declare class CreateTranslationKeyDto {
3
+ module: string;
4
+ key: string;
5
+ defaultMessage: string;
6
+ description?: string;
7
+ variables?: string[];
8
+ isActive?: boolean;
9
+ isReadonly?: boolean;
10
+ serial?: number;
11
+ }
12
+ declare const UpdateTranslationKeyDto_base: import("@nestjs/common").Type<Partial<Omit<CreateTranslationKeyDto, "isReadonly">>>;
13
+ export declare class UpdateTranslationKeyDto extends UpdateTranslationKeyDto_base {
14
+ id: string;
15
+ }
16
+ export declare class TranslationKeyResponseDto extends IdentityResponseDto {
17
+ module: string;
18
+ key: string;
19
+ defaultMessage: string;
20
+ description: string | null;
21
+ variables: string[] | null;
22
+ isActive: boolean;
23
+ isReadonly: boolean;
24
+ serial: number | null;
25
+ }
26
+ export declare class GetByModuleDto {
27
+ module: string;
28
+ }
29
+ export {};
@@ -0,0 +1,42 @@
1
+ import { IdentityResponseDto } from '@flusys/nestjs-shared/dtos';
2
+ import { LanguageResponseDto } from './language.dto';
3
+ import { TranslationKeyResponseDto } from './translation-key.dto';
4
+ export declare class CreateTranslationDto {
5
+ languageId: string;
6
+ translationKeyId: string;
7
+ value: string;
8
+ isVerified?: boolean;
9
+ isActive?: boolean;
10
+ }
11
+ declare const UpdateTranslationDto_base: import("@nestjs/common").Type<Partial<CreateTranslationDto>>;
12
+ export declare class UpdateTranslationDto extends UpdateTranslationDto_base {
13
+ id: string;
14
+ }
15
+ export declare class BulkUpdateTranslationDto {
16
+ id?: string;
17
+ languageId: string;
18
+ translationKeyId: string;
19
+ value: string;
20
+ isVerified?: boolean;
21
+ }
22
+ export declare class BulkUpdateTranslationsDto {
23
+ translations: BulkUpdateTranslationDto[];
24
+ }
25
+ export declare class TranslationResponseDto extends IdentityResponseDto {
26
+ languageId: string;
27
+ translationKeyId: string;
28
+ value: string;
29
+ isVerified: boolean;
30
+ isActive: boolean;
31
+ language?: LanguageResponseDto;
32
+ translationKey?: TranslationKeyResponseDto;
33
+ }
34
+ export declare class GetTranslationsByLanguageDto {
35
+ languageCode: string;
36
+ modules?: string[];
37
+ }
38
+ export declare class GetTranslationsByModuleDto {
39
+ module: string;
40
+ languageCode: string;
41
+ }
42
+ export {};
@@ -0,0 +1,8 @@
1
+ export * from './language.entity';
2
+ export * from './translation-key.entity';
3
+ export * from './translation.entity';
4
+ import { Language } from './language.entity';
5
+ import { TranslationKey } from './translation-key.entity';
6
+ import { Translation } from './translation.entity';
7
+ export declare const LocalizationEntities: (typeof TranslationKey | typeof Translation | typeof Language)[];
8
+ export declare function getLocalizationEntities(): typeof LocalizationEntities;
@@ -0,0 +1,13 @@
1
+ import { Identity } from '@flusys/nestjs-shared/entities';
2
+ import type { Translation } from './translation.entity';
3
+ export declare class Language extends Identity {
4
+ code: string;
5
+ name: string;
6
+ nativeName: string | null;
7
+ direction: 'ltr' | 'rtl' | null;
8
+ isActive: boolean;
9
+ isDefault: boolean;
10
+ serial: number | null;
11
+ isReadonly: boolean;
12
+ translations?: Translation[];
13
+ }
@@ -0,0 +1,13 @@
1
+ import { Identity } from '@flusys/nestjs-shared/entities';
2
+ import type { Translation } from './translation.entity';
3
+ export declare class TranslationKey extends Identity {
4
+ module: string;
5
+ key: string;
6
+ defaultMessage: string;
7
+ description: string | null;
8
+ variables: string[] | null;
9
+ isActive: boolean;
10
+ isReadonly: boolean;
11
+ serial: number | null;
12
+ translations?: Translation[];
13
+ }
@@ -0,0 +1,12 @@
1
+ import { Identity } from '@flusys/nestjs-shared/entities';
2
+ import { Language } from './language.entity';
3
+ import { TranslationKey } from './translation-key.entity';
4
+ export declare class Translation extends Identity {
5
+ languageId: string;
6
+ translationKeyId: string;
7
+ value: string;
8
+ isVerified: boolean;
9
+ isActive: boolean;
10
+ language?: Language;
11
+ translationKey?: TranslationKey;
12
+ }
@@ -0,0 +1,2 @@
1
+ export * from './localization.constants';
2
+ export * from './message-keys';
@@ -0,0 +1,2 @@
1
+ export const LOCALIZATION_MODULE_OPTIONS = 'LOCALIZATION_MODULE_OPTIONS';
2
+ export const DEFAULT_LANGUAGE_CODE = 'en';
@@ -0,0 +1,54 @@
1
+ // ==================== LOCALIZATION MODULE MESSAGE KEYS ====================
2
+ export const LANGUAGE_MESSAGES = {
3
+ CREATE_SUCCESS: 'language.create.success',
4
+ CREATE_MANY_SUCCESS: 'language.create.many.success',
5
+ GET_SUCCESS: 'language.get.success',
6
+ GET_ALL_SUCCESS: 'language.get.all.success',
7
+ UPDATE_SUCCESS: 'language.update.success',
8
+ UPDATE_MANY_SUCCESS: 'language.update.many.success',
9
+ DELETE_SUCCESS: 'language.delete.success',
10
+ RESTORE_SUCCESS: 'language.restore.success',
11
+ NOT_FOUND: 'language.not.found',
12
+ ACTIVE_SUCCESS: 'language.active.success',
13
+ SET_DEFAULT_SUCCESS: 'language.set.default.success',
14
+ GET_DEFAULT_SUCCESS: 'language.get.default.success'
15
+ };
16
+ export const TRANSLATION_KEY_MESSAGES = {
17
+ CREATE_SUCCESS: 'translation.key.create.success',
18
+ CREATE_MANY_SUCCESS: 'translation.key.create.many.success',
19
+ GET_SUCCESS: 'translation.key.get.success',
20
+ GET_ALL_SUCCESS: 'translation.key.get.all.success',
21
+ UPDATE_SUCCESS: 'translation.key.update.success',
22
+ UPDATE_MANY_SUCCESS: 'translation.key.update.many.success',
23
+ DELETE_SUCCESS: 'translation.key.delete.success',
24
+ RESTORE_SUCCESS: 'translation.key.restore.success',
25
+ NOT_FOUND: 'translation.key.not.found',
26
+ IMPORT_SUCCESS: 'translation.key.import.success',
27
+ EXPORT_SUCCESS: 'translation.key.export.success',
28
+ MODULES_SUCCESS: 'translation.key.modules.success',
29
+ READONLY_DELETE_FORBIDDEN: 'translation.key.readonly.delete.forbidden',
30
+ READONLY_UPDATE_FORBIDDEN: 'translation.key.readonly.update.forbidden',
31
+ DUPLICATE_KEY_IN_MODULE: 'translation.key.duplicate.key.in.module'
32
+ };
33
+ export const TRANSLATION_MESSAGES = {
34
+ CREATE_SUCCESS: 'translation.create.success',
35
+ CREATE_MANY_SUCCESS: 'translation.create.many.success',
36
+ GET_SUCCESS: 'translation.get.success',
37
+ GET_ALL_SUCCESS: 'translation.get.all.success',
38
+ UPDATE_SUCCESS: 'translation.update.success',
39
+ UPDATE_MANY_SUCCESS: 'translation.update.many.success',
40
+ DELETE_SUCCESS: 'translation.delete.success',
41
+ RESTORE_SUCCESS: 'translation.restore.success',
42
+ NOT_FOUND: 'translation.not.found',
43
+ BY_LANGUAGE_SUCCESS: 'translation.by.language.success',
44
+ BY_MODULE_SUCCESS: 'translation.by.module.success',
45
+ MISSING_SUCCESS: 'translation.missing.success',
46
+ SYNC_SUCCESS: 'translation.sync.success',
47
+ UPDATE_VALUES_SUCCESS: 'translation.update.values.success'
48
+ };
49
+ // Aggregated export for backward compatibility
50
+ export const LOCALIZATION_MODULE_MESSAGES = {
51
+ LANGUAGE: LANGUAGE_MESSAGES,
52
+ TRANSLATION_KEY: TRANSLATION_KEY_MESSAGES,
53
+ TRANSLATION: TRANSLATION_MESSAGES
54
+ };
@@ -0,0 +1,3 @@
1
+ export * from './language.controller';
2
+ export * from './translation-key.controller';
3
+ export * from './translation.controller';
@@ -0,0 +1,178 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
14
+ function _ts_decorate(decorators, target, key, desc) {
15
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
19
+ }
20
+ function _ts_metadata(k, v) {
21
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
22
+ }
23
+ function _ts_param(paramIndex, decorator) {
24
+ return function(target, key) {
25
+ decorator(target, key, paramIndex);
26
+ };
27
+ }
28
+ import { createApiController, LANGUAGE_PERMISSIONS } from '@flusys/nestjs-shared/classes';
29
+ import { CurrentUser, RequirePermission } from '@flusys/nestjs-shared/decorators';
30
+ import { LANGUAGE_MESSAGES } from '../config';
31
+ import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
32
+ import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
33
+ import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common';
34
+ import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
35
+ import { CreateLanguageDto, LanguageResponseDto, UpdateLanguageDto } from '../dtos';
36
+ import { LanguageService } from '../services';
37
+ export class LanguageController extends createApiController(CreateLanguageDto, UpdateLanguageDto, LanguageResponseDto, {
38
+ entityName: 'language',
39
+ security: {
40
+ insert: {
41
+ level: 'permission',
42
+ permissions: [
43
+ LANGUAGE_PERMISSIONS.CREATE
44
+ ]
45
+ },
46
+ insertMany: {
47
+ level: 'permission',
48
+ permissions: [
49
+ LANGUAGE_PERMISSIONS.CREATE
50
+ ]
51
+ },
52
+ getById: {
53
+ level: 'permission',
54
+ permissions: [
55
+ LANGUAGE_PERMISSIONS.READ
56
+ ]
57
+ },
58
+ getAll: {
59
+ level: 'permission',
60
+ permissions: [
61
+ LANGUAGE_PERMISSIONS.READ
62
+ ]
63
+ },
64
+ update: {
65
+ level: 'permission',
66
+ permissions: [
67
+ LANGUAGE_PERMISSIONS.UPDATE
68
+ ]
69
+ },
70
+ updateMany: {
71
+ level: 'permission',
72
+ permissions: [
73
+ LANGUAGE_PERMISSIONS.UPDATE
74
+ ]
75
+ },
76
+ delete: {
77
+ level: 'permission',
78
+ permissions: [
79
+ LANGUAGE_PERMISSIONS.DELETE
80
+ ]
81
+ }
82
+ }
83
+ }) {
84
+ async getActive() {
85
+ const data = await this.service.getActiveLanguages();
86
+ return {
87
+ success: true,
88
+ message: 'Active languages retrieved successfully',
89
+ messageKey: LANGUAGE_MESSAGES.ACTIVE_SUCCESS,
90
+ data,
91
+ meta: {
92
+ total: data.length,
93
+ page: 0,
94
+ pageSize: data.length,
95
+ count: data.length
96
+ }
97
+ };
98
+ }
99
+ async getDefault() {
100
+ const data = await this.service.getDefaultLanguage();
101
+ return {
102
+ success: true,
103
+ message: 'Default language retrieved successfully',
104
+ messageKey: LANGUAGE_MESSAGES.GET_DEFAULT_SUCCESS,
105
+ data: data ?? undefined
106
+ };
107
+ }
108
+ async setDefault(body, _user) {
109
+ const data = await this.service.setAsDefault(body.id);
110
+ return {
111
+ success: true,
112
+ message: 'Default language updated successfully',
113
+ messageKey: LANGUAGE_MESSAGES.SET_DEFAULT_SUCCESS,
114
+ data: data ?? undefined
115
+ };
116
+ }
117
+ constructor(service){
118
+ super(service), _define_property(this, "service", void 0), this.service = service;
119
+ }
120
+ }
121
+ _ts_decorate([
122
+ Post('get-active'),
123
+ ApiOperation({
124
+ summary: 'Get all active languages'
125
+ }),
126
+ ApiResponse({
127
+ status: 200,
128
+ type: [
129
+ LanguageResponseDto
130
+ ]
131
+ }),
132
+ _ts_metadata("design:type", Function),
133
+ _ts_metadata("design:paramtypes", []),
134
+ _ts_metadata("design:returntype", Promise)
135
+ ], LanguageController.prototype, "getActive", null);
136
+ _ts_decorate([
137
+ Post('get-default'),
138
+ ApiOperation({
139
+ summary: 'Get default language'
140
+ }),
141
+ ApiResponse({
142
+ status: 200,
143
+ type: LanguageResponseDto
144
+ }),
145
+ _ts_metadata("design:type", Function),
146
+ _ts_metadata("design:paramtypes", []),
147
+ _ts_metadata("design:returntype", Promise)
148
+ ], LanguageController.prototype, "getDefault", null);
149
+ _ts_decorate([
150
+ Post('set-default'),
151
+ UseGuards(JwtAuthGuard),
152
+ ApiBearerAuth(),
153
+ RequirePermission(LANGUAGE_PERMISSIONS.UPDATE),
154
+ ApiOperation({
155
+ summary: 'Set a language as default'
156
+ }),
157
+ ApiResponse({
158
+ status: 200,
159
+ type: LanguageResponseDto
160
+ }),
161
+ _ts_param(0, Body()),
162
+ _ts_param(1, CurrentUser()),
163
+ _ts_metadata("design:type", Function),
164
+ _ts_metadata("design:paramtypes", [
165
+ Object,
166
+ typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
167
+ ]),
168
+ _ts_metadata("design:returntype", Promise)
169
+ ], LanguageController.prototype, "setDefault", null);
170
+ LanguageController = _ts_decorate([
171
+ ApiTags('Localization - Language'),
172
+ Controller('localization/language'),
173
+ _ts_param(0, Inject(LanguageService)),
174
+ _ts_metadata("design:type", Function),
175
+ _ts_metadata("design:paramtypes", [
176
+ typeof LanguageService === "undefined" ? Object : LanguageService
177
+ ])
178
+ ], LanguageController);
@@ -0,0 +1,164 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
14
+ function _ts_decorate(decorators, target, key, desc) {
15
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
19
+ }
20
+ function _ts_metadata(k, v) {
21
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
22
+ }
23
+ function _ts_param(paramIndex, decorator) {
24
+ return function(target, key) {
25
+ decorator(target, key, paramIndex);
26
+ };
27
+ }
28
+ import { createApiController, TRANSLATION_KEY_PERMISSIONS } from '@flusys/nestjs-shared/classes';
29
+ import { CurrentUser, RequirePermission } from '@flusys/nestjs-shared/decorators';
30
+ import { TRANSLATION_KEY_MESSAGES } from '../config';
31
+ import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
32
+ import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
33
+ import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common';
34
+ import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
35
+ import { CreateTranslationKeyDto, GetByModuleDto, TranslationKeyResponseDto, UpdateTranslationKeyDto } from '../dtos';
36
+ import { TranslationKeyService } from '../services';
37
+ export class TranslationKeyController extends createApiController(CreateTranslationKeyDto, UpdateTranslationKeyDto, TranslationKeyResponseDto, {
38
+ entityName: 'translationKey',
39
+ security: {
40
+ insert: {
41
+ level: 'permission',
42
+ permissions: [
43
+ TRANSLATION_KEY_PERMISSIONS.CREATE
44
+ ]
45
+ },
46
+ insertMany: {
47
+ level: 'permission',
48
+ permissions: [
49
+ TRANSLATION_KEY_PERMISSIONS.CREATE
50
+ ]
51
+ },
52
+ getById: {
53
+ level: 'permission',
54
+ permissions: [
55
+ TRANSLATION_KEY_PERMISSIONS.READ
56
+ ]
57
+ },
58
+ getAll: {
59
+ level: 'permission',
60
+ permissions: [
61
+ TRANSLATION_KEY_PERMISSIONS.READ
62
+ ]
63
+ },
64
+ update: {
65
+ level: 'permission',
66
+ permissions: [
67
+ TRANSLATION_KEY_PERMISSIONS.UPDATE
68
+ ]
69
+ },
70
+ updateMany: {
71
+ level: 'permission',
72
+ permissions: [
73
+ TRANSLATION_KEY_PERMISSIONS.UPDATE
74
+ ]
75
+ },
76
+ delete: {
77
+ level: 'permission',
78
+ permissions: [
79
+ TRANSLATION_KEY_PERMISSIONS.DELETE
80
+ ]
81
+ }
82
+ }
83
+ }) {
84
+ async getModules(_user) {
85
+ const data = await this.service.getModules();
86
+ return {
87
+ success: true,
88
+ message: 'Modules retrieved successfully',
89
+ messageKey: TRANSLATION_KEY_MESSAGES.MODULES_SUCCESS,
90
+ data
91
+ };
92
+ }
93
+ async getByModule(body, _user) {
94
+ const data = await this.service.findByModule(body.module);
95
+ return {
96
+ success: true,
97
+ message: 'Translation keys retrieved successfully',
98
+ messageKey: TRANSLATION_KEY_MESSAGES.GET_ALL_SUCCESS,
99
+ data,
100
+ meta: {
101
+ total: data.length,
102
+ page: 0,
103
+ pageSize: data.length,
104
+ count: data.length
105
+ }
106
+ };
107
+ }
108
+ constructor(service){
109
+ super(service), _define_property(this, "service", void 0), this.service = service;
110
+ }
111
+ }
112
+ _ts_decorate([
113
+ Post('get-modules'),
114
+ UseGuards(JwtAuthGuard),
115
+ ApiBearerAuth(),
116
+ RequirePermission(TRANSLATION_KEY_PERMISSIONS.READ),
117
+ ApiOperation({
118
+ summary: 'Get all distinct module names'
119
+ }),
120
+ ApiResponse({
121
+ status: 200,
122
+ type: [
123
+ String
124
+ ]
125
+ }),
126
+ _ts_param(0, CurrentUser()),
127
+ _ts_metadata("design:type", Function),
128
+ _ts_metadata("design:paramtypes", [
129
+ typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
130
+ ]),
131
+ _ts_metadata("design:returntype", Promise)
132
+ ], TranslationKeyController.prototype, "getModules", null);
133
+ _ts_decorate([
134
+ Post('get-by-module'),
135
+ UseGuards(JwtAuthGuard),
136
+ ApiBearerAuth(),
137
+ RequirePermission(TRANSLATION_KEY_PERMISSIONS.READ),
138
+ ApiOperation({
139
+ summary: 'Get translation keys by module'
140
+ }),
141
+ ApiResponse({
142
+ status: 200,
143
+ type: [
144
+ TranslationKeyResponseDto
145
+ ]
146
+ }),
147
+ _ts_param(0, Body()),
148
+ _ts_param(1, CurrentUser()),
149
+ _ts_metadata("design:type", Function),
150
+ _ts_metadata("design:paramtypes", [
151
+ typeof GetByModuleDto === "undefined" ? Object : GetByModuleDto,
152
+ typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
153
+ ]),
154
+ _ts_metadata("design:returntype", Promise)
155
+ ], TranslationKeyController.prototype, "getByModule", null);
156
+ TranslationKeyController = _ts_decorate([
157
+ ApiTags('Localization - Translation Key'),
158
+ Controller('localization/translation-key'),
159
+ _ts_param(0, Inject(TranslationKeyService)),
160
+ _ts_metadata("design:type", Function),
161
+ _ts_metadata("design:paramtypes", [
162
+ typeof TranslationKeyService === "undefined" ? Object : TranslationKeyService
163
+ ])
164
+ ], TranslationKeyController);