@tomei/media 0.4.7 → 0.4.9

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 (81) hide show
  1. package/.commitlintrc.json +22 -22
  2. package/.eslintrc.js +66 -66
  3. package/.husky/commit-msg +4 -4
  4. package/.husky/pre-commit +4 -4
  5. package/.prettierrc +4 -4
  6. package/.prettierrc copy +3 -3
  7. package/README.md +93 -93
  8. package/dist/common/common.module.js.map +1 -1
  9. package/dist/common/common.service.js.map +1 -1
  10. package/dist/common/dto/add-field-translation.dto.js.map +1 -1
  11. package/dist/common/dto/get-media.dto.js.map +1 -1
  12. package/dist/dto/external-media.dto.js.map +1 -1
  13. package/dist/dto/internal-medias.dto.js.map +1 -1
  14. package/dist/entities/medias.entity.d.ts +2 -0
  15. package/dist/entities/medias.entity.js +8 -0
  16. package/dist/entities/medias.entity.js.map +1 -1
  17. package/dist/interfaces/medias.repository.interface.d.ts +1 -1
  18. package/dist/medias.d.ts +1 -1
  19. package/dist/medias.js +41 -38
  20. package/dist/medias.js.map +1 -1
  21. package/dist/medias.repository.js.map +1 -1
  22. package/dist/pipe/append-id.pipe.js.map +1 -1
  23. package/dist/pipe/validate-id.pipe.js.map +1 -1
  24. package/dist/pipe/validate-search.pipe.js.map +1 -1
  25. package/dist/responses/deleted.response.js.map +1 -1
  26. package/dist/responses/pagination.response.js.map +1 -1
  27. package/dist/tsconfig.tsbuildinfo +1 -1
  28. package/migration/0001-add-defaultyn-hiddenyn-to-media-table.js +36 -0
  29. package/migration/media-migration.js +82 -82
  30. package/package.json +74 -72
  31. package/src/base/base.medias.ts +209 -209
  32. package/src/common/common.module.ts +10 -10
  33. package/src/common/common.service.ts +107 -107
  34. package/src/common/dto/add-field-translation.dto.ts +23 -23
  35. package/src/common/dto/get-media.dto.ts +12 -12
  36. package/src/entities/medias.entity.ts +125 -124
  37. package/src/index.ts +22 -22
  38. package/src/medias.repository.ts +41 -41
  39. package/src/medias.ts +763 -701
  40. package/src/pipe/validate-search.pipe.ts +44 -44
  41. package/tsconfig.build.json +4 -4
  42. package/tslint.json +18 -18
  43. package/dist/base/index.d.ts +0 -2
  44. package/dist/base/index.js +0 -6
  45. package/dist/base/index.js.map +0 -1
  46. package/dist/common/common.service.spec.d.ts +0 -0
  47. package/dist/common/common.service.spec.js +0 -5
  48. package/dist/common/common.service.spec.js.map +0 -1
  49. package/dist/dto/medias.dto.d.ts +0 -12
  50. package/dist/dto/medias.dto.js +0 -88
  51. package/dist/dto/medias.dto.js.map +0 -1
  52. package/dist/entities/index.d.ts +0 -2
  53. package/dist/entities/index.js +0 -6
  54. package/dist/entities/index.js.map +0 -1
  55. package/dist/entities/media.entity.d.ts +0 -21
  56. package/dist/entities/media.entity.js +0 -152
  57. package/dist/entities/media.entity.js.map +0 -1
  58. package/dist/interfaces/commonService.interface.d.ts +0 -17
  59. package/dist/interfaces/commonService.interface.js +0 -3
  60. package/dist/interfaces/commonService.interface.js.map +0 -1
  61. package/dist/interfaces/index.d.ts +0 -3
  62. package/dist/interfaces/index.js +0 -3
  63. package/dist/interfaces/index.js.map +0 -1
  64. package/dist/interfaces/media.repository.interface.d.ts +0 -10
  65. package/dist/interfaces/media.repository.interface.js +0 -3
  66. package/dist/interfaces/media.repository.interface.js.map +0 -1
  67. package/dist/interfaces/medias-attr.interface.d.ts +0 -22
  68. package/dist/interfaces/medias-attr.interface.js +0 -3
  69. package/dist/interfaces/medias-attr.interface.js.map +0 -1
  70. package/dist/medias.controller copy.d.ts +0 -25
  71. package/dist/medias.controller copy.js +0 -225
  72. package/dist/medias.controller copy.js.map +0 -1
  73. package/dist/medias.controller.d.ts +0 -29
  74. package/dist/medias.controller.js +0 -120
  75. package/dist/medias.controller.js.map +0 -1
  76. package/dist/medias.controller.old.d.ts +0 -25
  77. package/dist/medias.controller.old.js +0 -225
  78. package/dist/medias.controller.old.js.map +0 -1
  79. package/dist/medias.module.d.ts +0 -2
  80. package/dist/medias.module.js +0 -32
  81. package/dist/medias.module.js.map +0 -1
@@ -1,209 +1,209 @@
1
- import { MediaType } from '../enum/medias.enum';
2
- import * as cuid from 'cuid';
3
- import { BadRequestException } from '@nestjs/common';
4
- import { IMediasRepository } from '../interfaces/medias.repository.interface';
5
- import { MediasModel } from '../entities/medias.entity';
6
- import { IBaseMediasAttr } from '../interfaces/base.medias-attr.interface';
7
-
8
- export abstract class BaseMedias {
9
- MediaId: string;
10
- ObjectId: string;
11
- ObjectType: string;
12
- Title: string;
13
- Description: string;
14
- Type: MediaType;
15
- IsExternalYN: string;
16
- ExternalSource: string;
17
- IsEncryptedYN: string;
18
- FileName: string;
19
- FileExtension: string;
20
- FilePath: string;
21
- URL: string;
22
- CreatedById: string;
23
- CreatedAt: Date;
24
- UpdatedById: string;
25
- UpdatedAt: Date;
26
- mediasRepository: IMediasRepository;
27
- container: string;
28
-
29
- protected constructor(
30
- mediasRepository: IMediasRepository,
31
- media?: IBaseMediasAttr,
32
- ) {
33
- this.mediasRepository = mediasRepository;
34
- if (media) {
35
- this.init(media);
36
- }
37
- }
38
-
39
- init(media: IBaseMediasAttr){
40
- this.MediaId = media.MediaId ? media.MediaId : cuid();
41
- this.ObjectId = media.ObjectId;
42
- this.ObjectType = media.ObjectType;
43
- this.Title = media.Title;
44
- this.Description = media.Description;
45
- this.Type = media.Type;
46
- this.IsExternalYN = media.IsExternalYN;
47
- this.ExternalSource = media.ExternalSource;
48
- this.IsEncryptedYN = media.IsEncryptedYN;
49
- this.FileName = media.FileName;
50
- this.FileExtension = media.FileExtension;
51
- this.URL =
52
- media.URL && media.IsExternalYN === 'Y'
53
- ? media.URL
54
- : this.createSaveLocation();
55
- this.FilePath =
56
- media.FilePath && media.IsExternalYN === 'Y'
57
- ? media.FilePath
58
- : this.createFilePath();
59
- this.CreatedById = media.CreatedById;
60
- this.CreatedAt = media.CreatedAt;
61
- this.UpdatedById = media.UpdatedById;
62
- this.UpdatedAt = media.UpdatedAt;
63
- }
64
-
65
- createSaveLocation(): string {
66
- try {
67
- const mediaFileStorageType = process.env.MEDIA_STORAGE_TYPE;
68
- let basePath: string;
69
- if (mediaFileStorageType === 'local') {
70
- basePath = process.env.MEDIA_LOCAL_STORAGE_PATH;
71
- } else {
72
- basePath = process.env.MEDIA_AZUREBLOB_CONTAINER_NAME;
73
- }
74
-
75
- if (!basePath) {
76
- throw new BadRequestException(
77
- 'MEDIA_LOCAL_STORAGE_PATH and or MEDIA_AZUREBLOB_CONTAINER_NAME not found.',
78
- );
79
- }
80
- return basePath + `/${this.ObjectType}/${this.ObjectId}`;
81
- } catch (error) {
82
- throw error;
83
- }
84
- }
85
-
86
- createFilePath(): string {
87
- try {
88
- const fileLocation = this.createSaveLocation();
89
- return `${fileLocation}/${this.FileName}.${this.FileExtension}`;
90
- } catch (error) {
91
- throw error;
92
- }
93
- }
94
-
95
- async create(options?: any): Promise<MediasModel> {
96
- try {
97
- return this.mediasRepository.create(
98
- {
99
- MediaId: this.MediaId,
100
- ObjectId: this.ObjectId,
101
- ObjectType: this.ObjectType,
102
- Title: this.Title,
103
- Description: this.Description,
104
- Type: this.Type,
105
- IsExternalYN: this.IsExternalYN,
106
- ExternalSource: this.ExternalSource,
107
- IsEncryptedYN: this.IsEncryptedYN,
108
- FileName: this.FileName,
109
- FileExtension: this.FileExtension,
110
- FilePath: this.FilePath,
111
- URL: this.URL,
112
- CreatedById: this.CreatedById,
113
- CreatedAt: this.CreatedAt,
114
- UpdatedById: this.UpdatedById,
115
- UpdatedAt: this.UpdatedAt,
116
- },
117
- options,
118
- );
119
- } catch (error) {
120
- throw error;
121
- }
122
- }
123
-
124
- async update(options?: any): Promise<MediasModel | any> {
125
- try {
126
- const media = await this.mediasRepository.findOne({
127
- where: {
128
- MediaId: this.MediaId,
129
- },
130
- });
131
-
132
- if (!media) {
133
- throw new BadRequestException('Media not found.');
134
- }
135
- return await media.update(
136
- {
137
- MediaId: this.MediaId,
138
- ObjectId: this.ObjectId,
139
- ObjectType: this.ObjectType,
140
- Title: this.Title,
141
- Description: this.Description,
142
- Type: this.Type,
143
- IsExternalYN: this.IsExternalYN,
144
- ExternalSource: this.ExternalSource,
145
- IsEncryptedYN: this.IsEncryptedYN,
146
- FileName: this.FileName,
147
- FileExtension: this.FileExtension,
148
- FilePath: this.FilePath,
149
- URL: this.URL,
150
- CreatedById: this.CreatedById,
151
- CreatedAt: this.CreatedAt,
152
- UpdatedById: this.UpdatedById,
153
- UpdatedAt: this.UpdatedAt,
154
- },
155
- options,
156
- );
157
- } catch (error) {
158
- throw error;
159
- }
160
- }
161
-
162
- async delete(options?: any): Promise<MediasModel> {
163
- try {
164
- const media = await this.mediasRepository.findOne({
165
- where: {
166
- MediaId: this.MediaId,
167
- },
168
- });
169
-
170
- const data = {
171
- ...media.get({ plain: true }),
172
- };
173
-
174
- if (!media) {
175
- throw new BadRequestException('Media not found.');
176
- }
177
- await media.destroy(options);
178
- return data;
179
- } catch (error) {
180
- throw error;
181
- }
182
- }
183
-
184
- async findAll(options?: any): Promise<MediasModel[]> {
185
- try {
186
- return this.mediasRepository.findAll(options);
187
- } catch (error) {
188
- throw error;
189
- }
190
- }
191
-
192
- async findAllWithPagination(
193
- options?: any,
194
- ): Promise<{ count: number; rows: MediasModel[] }> {
195
- try {
196
- return this.mediasRepository.findAllWithPagination(options);
197
- } catch (error) {
198
- throw error;
199
- }
200
- }
201
-
202
- async findOne(options?: any): Promise<MediasModel> {
203
- try {
204
- return this.mediasRepository.findOne(options);
205
- } catch (error) {
206
- throw error;
207
- }
208
- }
209
- }
1
+ import { MediaType } from '../enum/medias.enum';
2
+ import * as cuid from 'cuid';
3
+ import { BadRequestException } from '@nestjs/common';
4
+ import { IMediasRepository } from '../interfaces/medias.repository.interface';
5
+ import { MediasModel } from '../entities/medias.entity';
6
+ import { IBaseMediasAttr } from '../interfaces/base.medias-attr.interface';
7
+
8
+ export abstract class BaseMedias {
9
+ MediaId: string;
10
+ ObjectId: string;
11
+ ObjectType: string;
12
+ Title: string;
13
+ Description: string;
14
+ Type: MediaType;
15
+ IsExternalYN: string;
16
+ ExternalSource: string;
17
+ IsEncryptedYN: string;
18
+ FileName: string;
19
+ FileExtension: string;
20
+ FilePath: string;
21
+ URL: string;
22
+ CreatedById: string;
23
+ CreatedAt: Date;
24
+ UpdatedById: string;
25
+ UpdatedAt: Date;
26
+ mediasRepository: IMediasRepository;
27
+ container: string;
28
+
29
+ protected constructor(
30
+ mediasRepository: IMediasRepository,
31
+ media?: IBaseMediasAttr,
32
+ ) {
33
+ this.mediasRepository = mediasRepository;
34
+ if (media) {
35
+ this.init(media);
36
+ }
37
+ }
38
+
39
+ init(media: IBaseMediasAttr){
40
+ this.MediaId = media.MediaId ? media.MediaId : cuid();
41
+ this.ObjectId = media.ObjectId;
42
+ this.ObjectType = media.ObjectType;
43
+ this.Title = media.Title;
44
+ this.Description = media.Description;
45
+ this.Type = media.Type;
46
+ this.IsExternalYN = media.IsExternalYN;
47
+ this.ExternalSource = media.ExternalSource;
48
+ this.IsEncryptedYN = media.IsEncryptedYN;
49
+ this.FileName = media.FileName;
50
+ this.FileExtension = media.FileExtension;
51
+ this.URL =
52
+ media.URL && media.IsExternalYN === 'Y'
53
+ ? media.URL
54
+ : this.createSaveLocation();
55
+ this.FilePath =
56
+ media.FilePath && media.IsExternalYN === 'Y'
57
+ ? media.FilePath
58
+ : this.createFilePath();
59
+ this.CreatedById = media.CreatedById;
60
+ this.CreatedAt = media.CreatedAt;
61
+ this.UpdatedById = media.UpdatedById;
62
+ this.UpdatedAt = media.UpdatedAt;
63
+ }
64
+
65
+ createSaveLocation(): string {
66
+ try {
67
+ const mediaFileStorageType = process.env.MEDIA_STORAGE_TYPE;
68
+ let basePath: string;
69
+ if (mediaFileStorageType === 'local') {
70
+ basePath = process.env.MEDIA_LOCAL_STORAGE_PATH;
71
+ } else {
72
+ basePath = process.env.MEDIA_AZUREBLOB_CONTAINER_NAME;
73
+ }
74
+
75
+ if (!basePath) {
76
+ throw new BadRequestException(
77
+ 'MEDIA_LOCAL_STORAGE_PATH and or MEDIA_AZUREBLOB_CONTAINER_NAME not found.',
78
+ );
79
+ }
80
+ return basePath + `/${this.ObjectType}/${this.ObjectId}`;
81
+ } catch (error) {
82
+ throw error;
83
+ }
84
+ }
85
+
86
+ createFilePath(): string {
87
+ try {
88
+ const fileLocation = this.createSaveLocation();
89
+ return `${fileLocation}/${this.FileName}.${this.FileExtension}`;
90
+ } catch (error) {
91
+ throw error;
92
+ }
93
+ }
94
+
95
+ async create(options?: any): Promise<MediasModel> {
96
+ try {
97
+ return this.mediasRepository.create(
98
+ {
99
+ MediaId: this.MediaId,
100
+ ObjectId: this.ObjectId,
101
+ ObjectType: this.ObjectType,
102
+ Title: this.Title,
103
+ Description: this.Description,
104
+ Type: this.Type,
105
+ IsExternalYN: this.IsExternalYN,
106
+ ExternalSource: this.ExternalSource,
107
+ IsEncryptedYN: this.IsEncryptedYN,
108
+ FileName: this.FileName,
109
+ FileExtension: this.FileExtension,
110
+ FilePath: this.FilePath,
111
+ URL: this.URL,
112
+ CreatedById: this.CreatedById,
113
+ CreatedAt: this.CreatedAt,
114
+ UpdatedById: this.UpdatedById,
115
+ UpdatedAt: this.UpdatedAt,
116
+ },
117
+ options,
118
+ );
119
+ } catch (error) {
120
+ throw error;
121
+ }
122
+ }
123
+
124
+ async update(options?: any): Promise<MediasModel | any> {
125
+ try {
126
+ const media = await this.mediasRepository.findOne({
127
+ where: {
128
+ MediaId: this.MediaId,
129
+ },
130
+ });
131
+
132
+ if (!media) {
133
+ throw new BadRequestException('Media not found.');
134
+ }
135
+ return await media.update(
136
+ {
137
+ MediaId: this.MediaId,
138
+ ObjectId: this.ObjectId,
139
+ ObjectType: this.ObjectType,
140
+ Title: this.Title,
141
+ Description: this.Description,
142
+ Type: this.Type,
143
+ IsExternalYN: this.IsExternalYN,
144
+ ExternalSource: this.ExternalSource,
145
+ IsEncryptedYN: this.IsEncryptedYN,
146
+ FileName: this.FileName,
147
+ FileExtension: this.FileExtension,
148
+ FilePath: this.FilePath,
149
+ URL: this.URL,
150
+ CreatedById: this.CreatedById,
151
+ CreatedAt: this.CreatedAt,
152
+ UpdatedById: this.UpdatedById,
153
+ UpdatedAt: this.UpdatedAt,
154
+ },
155
+ options,
156
+ );
157
+ } catch (error) {
158
+ throw error;
159
+ }
160
+ }
161
+
162
+ async delete(options?: any): Promise<MediasModel> {
163
+ try {
164
+ const media = await this.mediasRepository.findOne({
165
+ where: {
166
+ MediaId: this.MediaId,
167
+ },
168
+ });
169
+
170
+ const data = {
171
+ ...media.get({ plain: true }),
172
+ };
173
+
174
+ if (!media) {
175
+ throw new BadRequestException('Media not found.');
176
+ }
177
+ await media.destroy(options);
178
+ return data;
179
+ } catch (error) {
180
+ throw error;
181
+ }
182
+ }
183
+
184
+ async findAll(options?: any): Promise<MediasModel[]> {
185
+ try {
186
+ return this.mediasRepository.findAll(options);
187
+ } catch (error) {
188
+ throw error;
189
+ }
190
+ }
191
+
192
+ async findAllWithPagination(
193
+ options?: any,
194
+ ): Promise<{ count: number; rows: MediasModel[] }> {
195
+ try {
196
+ return this.mediasRepository.findAllWithPagination(options);
197
+ } catch (error) {
198
+ throw error;
199
+ }
200
+ }
201
+
202
+ async findOne(options?: any): Promise<MediasModel> {
203
+ try {
204
+ return this.mediasRepository.findOne(options);
205
+ } catch (error) {
206
+ throw error;
207
+ }
208
+ }
209
+ }
@@ -1,10 +1,10 @@
1
- import { Module } from '@nestjs/common';
2
- import { ConfigModule } from '@nestjs/config';
3
- import { CommonService } from './common.service';
4
-
5
- @Module({
6
- providers: [CommonService],
7
- imports: [ConfigModule],
8
- exports: [CommonService],
9
- })
10
- export class CommonModule {}
1
+ import { Module } from '@nestjs/common';
2
+ import { ConfigModule } from '@nestjs/config';
3
+ import { CommonService } from './common.service';
4
+
5
+ @Module({
6
+ providers: [CommonService],
7
+ imports: [ConfigModule],
8
+ exports: [CommonService],
9
+ })
10
+ export class CommonModule {}
@@ -1,107 +1,107 @@
1
- import {
2
- HttpException,
3
- Injectable,
4
- InternalServerErrorException,
5
- } from '@nestjs/common';
6
- import { ConfigService } from '@nestjs/config';
7
- import axios from 'axios';
8
- import * as cuid from 'cuid';
9
- import { omit, omitBy, keys, pick } from 'lodash';
10
- import { AddFieldTranslationDto } from './dto/add-field-translation.dto';
11
- import { GetMediaDto } from './dto/get-media.dto';
12
- @Injectable()
13
- export class CommonService {
14
- private readonly commonApiUrl: string;
15
-
16
- constructor(private configService: ConfigService) {
17
- this.commonApiUrl = this.configService.get('COMMON_API_URL');
18
- }
19
-
20
- handleAxiosError(err) {
21
- if (err.response) {
22
- throw new HttpException(err.response.data, err.response.status);
23
- } else if (err.request) {
24
- throw new HttpException(err.request, 500);
25
- } else {
26
- throw new InternalServerErrorException(err.message);
27
- }
28
- }
29
-
30
- async addActivityHistory(record, entity, method) {
31
- const activity =
32
- method === 'create'
33
- ? 'Insert new'
34
- : method === 'update'
35
- ? 'Update'
36
- : 'Delete';
37
-
38
- const filteredRecord = omit(record.EntityValueAfter, [
39
- 'CreatedById',
40
- 'CreatedAt',
41
- 'UpdatedById',
42
- 'UpdatedAt',
43
- ]);
44
-
45
- const filteredRecordBefore = pick(
46
- record.EntityValueBefore,
47
- keys(filteredRecord),
48
- );
49
-
50
- const payload = {
51
- Action: record.Action || (method === 'create' ? 'Insert' : activity),
52
- Activity: record.Activity || `${activity} ${entity}`,
53
- Description: record.Description || `${activity} details of ${entity}`,
54
- EntityType: record?.EntityType || entity,
55
- EntityValueBefore:
56
- method === 'create'
57
- ? JSON.stringify({})
58
- : method === 'update'
59
- ? filteredRecordBefore
60
- : record.EntityValueBefore,
61
- EntityValueAfter: JSON.stringify(filteredRecord),
62
- PerformedById: record.PerformedById,
63
- PerformedAt: record.PerformedAt || Date.now(),
64
- EntityId: record.EntityId ? record.EntityId : cuid(),
65
- };
66
-
67
- try {
68
- const { data } = await axios.post(
69
- `${this.commonApiUrl}/activity-histories`,
70
- payload,
71
- );
72
- return data.EntityId;
73
- } catch (err) {
74
- this.handleAxiosError(err);
75
- }
76
- }
77
-
78
- async getList(listName: string): Promise<[]> {
79
- try {
80
- const { data } = await axios.get(`${this.commonApiUrl}/lists/items`, {
81
- params: { ListName: listName },
82
- });
83
- return data?.rows;
84
- } catch (err) {
85
- this.handleAxiosError(err);
86
- }
87
- }
88
-
89
- async addFieldTranslation(payload: AddFieldTranslationDto) {
90
- try {
91
- await axios.post(`${this.commonApiUrl}/field-translations`, payload);
92
- } catch (err) {
93
- this.handleAxiosError(err);
94
- }
95
- }
96
-
97
- async getMedia(query: GetMediaDto) {
98
- try {
99
- const { data } = await axios.get(`${this.commonApiUrl}/medias`, {
100
- params: query,
101
- });
102
- return data?.rows;
103
- } catch (err) {
104
- this.handleAxiosError(err);
105
- }
106
- }
107
- }
1
+ import {
2
+ HttpException,
3
+ Injectable,
4
+ InternalServerErrorException,
5
+ } from '@nestjs/common';
6
+ import { ConfigService } from '@nestjs/config';
7
+ import axios from 'axios';
8
+ import * as cuid from 'cuid';
9
+ import { omit, omitBy, keys, pick } from 'lodash';
10
+ import { AddFieldTranslationDto } from './dto/add-field-translation.dto';
11
+ import { GetMediaDto } from './dto/get-media.dto';
12
+ @Injectable()
13
+ export class CommonService {
14
+ private readonly commonApiUrl: string;
15
+
16
+ constructor(private configService: ConfigService) {
17
+ this.commonApiUrl = this.configService.get('COMMON_API_URL');
18
+ }
19
+
20
+ handleAxiosError(err) {
21
+ if (err.response) {
22
+ throw new HttpException(err.response.data, err.response.status);
23
+ } else if (err.request) {
24
+ throw new HttpException(err.request, 500);
25
+ } else {
26
+ throw new InternalServerErrorException(err.message);
27
+ }
28
+ }
29
+
30
+ async addActivityHistory(record, entity, method) {
31
+ const activity =
32
+ method === 'create'
33
+ ? 'Insert new'
34
+ : method === 'update'
35
+ ? 'Update'
36
+ : 'Delete';
37
+
38
+ const filteredRecord = omit(record.EntityValueAfter, [
39
+ 'CreatedById',
40
+ 'CreatedAt',
41
+ 'UpdatedById',
42
+ 'UpdatedAt',
43
+ ]);
44
+
45
+ const filteredRecordBefore = pick(
46
+ record.EntityValueBefore,
47
+ keys(filteredRecord),
48
+ );
49
+
50
+ const payload = {
51
+ Action: record.Action || (method === 'create' ? 'Insert' : activity),
52
+ Activity: record.Activity || `${activity} ${entity}`,
53
+ Description: record.Description || `${activity} details of ${entity}`,
54
+ EntityType: record?.EntityType || entity,
55
+ EntityValueBefore:
56
+ method === 'create'
57
+ ? JSON.stringify({})
58
+ : method === 'update'
59
+ ? filteredRecordBefore
60
+ : record.EntityValueBefore,
61
+ EntityValueAfter: JSON.stringify(filteredRecord),
62
+ PerformedById: record.PerformedById,
63
+ PerformedAt: record.PerformedAt || Date.now(),
64
+ EntityId: record.EntityId ? record.EntityId : cuid(),
65
+ };
66
+
67
+ try {
68
+ const { data } = await axios.post(
69
+ `${this.commonApiUrl}/activity-histories`,
70
+ payload,
71
+ );
72
+ return data.EntityId;
73
+ } catch (err) {
74
+ this.handleAxiosError(err);
75
+ }
76
+ }
77
+
78
+ async getList(listName: string): Promise<[]> {
79
+ try {
80
+ const { data } = await axios.get(`${this.commonApiUrl}/lists/items`, {
81
+ params: { ListName: listName },
82
+ });
83
+ return data?.rows;
84
+ } catch (err) {
85
+ this.handleAxiosError(err);
86
+ }
87
+ }
88
+
89
+ async addFieldTranslation(payload: AddFieldTranslationDto) {
90
+ try {
91
+ await axios.post(`${this.commonApiUrl}/field-translations`, payload);
92
+ } catch (err) {
93
+ this.handleAxiosError(err);
94
+ }
95
+ }
96
+
97
+ async getMedia(query: GetMediaDto) {
98
+ try {
99
+ const { data } = await axios.get(`${this.commonApiUrl}/medias`, {
100
+ params: query,
101
+ });
102
+ return data?.rows;
103
+ } catch (err) {
104
+ this.handleAxiosError(err);
105
+ }
106
+ }
107
+ }