@tomei/media 0.1.0

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 (121) hide show
  1. package/.commitlintrc.json +22 -0
  2. package/.eslintrc.js +66 -0
  3. package/.husky/commit-msg +4 -0
  4. package/.husky/pre-commit +4 -0
  5. package/.prettierrc +4 -0
  6. package/.prettierrc copy +4 -0
  7. package/README.md +93 -0
  8. package/dist/base/base.medias.d.ts +37 -0
  9. package/dist/base/base.medias.js +161 -0
  10. package/dist/base/base.medias.js.map +1 -0
  11. package/dist/base/base.repository.abstract.d.ts +12 -0
  12. package/dist/base/base.repository.abstract.js +22 -0
  13. package/dist/base/base.repository.abstract.js.map +1 -0
  14. package/dist/base/base.repository.interface.d.ts +9 -0
  15. package/dist/base/base.repository.interface.js +3 -0
  16. package/dist/base/base.repository.interface.js.map +1 -0
  17. package/dist/common/common.module.d.ts +2 -0
  18. package/dist/common/common.module.js +23 -0
  19. package/dist/common/common.module.js.map +1 -0
  20. package/dist/common/common.service.d.ts +13 -0
  21. package/dist/common/common.service.js +108 -0
  22. package/dist/common/common.service.js.map +1 -0
  23. package/dist/common/dto/add-field-translation.dto.d.ts +7 -0
  24. package/dist/common/dto/add-field-translation.dto.js +42 -0
  25. package/dist/common/dto/add-field-translation.dto.js.map +1 -0
  26. package/dist/common/dto/get-media.dto.d.ts +5 -0
  27. package/dist/common/dto/get-media.dto.js +29 -0
  28. package/dist/common/dto/get-media.dto.js.map +1 -0
  29. package/dist/dto/external-media.dto.d.ts +10 -0
  30. package/dist/dto/external-media.dto.js +70 -0
  31. package/dist/dto/external-media.dto.js.map +1 -0
  32. package/dist/dto/internal-medias.dto.d.ts +12 -0
  33. package/dist/dto/internal-medias.dto.js +87 -0
  34. package/dist/dto/internal-medias.dto.js.map +1 -0
  35. package/dist/entities/medias.entity.d.ts +21 -0
  36. package/dist/entities/medias.entity.js +152 -0
  37. package/dist/entities/medias.entity.js.map +1 -0
  38. package/dist/enum/index.d.ts +2 -0
  39. package/dist/enum/index.js +6 -0
  40. package/dist/enum/index.js.map +1 -0
  41. package/dist/enum/medias.enum.d.ts +5 -0
  42. package/dist/enum/medias.enum.js +10 -0
  43. package/dist/enum/medias.enum.js.map +1 -0
  44. package/dist/helpers/error.d.ts +1 -0
  45. package/dist/helpers/error.js +14 -0
  46. package/dist/helpers/error.js.map +1 -0
  47. package/dist/helpers/index.d.ts +2 -0
  48. package/dist/helpers/index.js +6 -0
  49. package/dist/helpers/index.js.map +1 -0
  50. package/dist/index.d.ts +6 -0
  51. package/dist/index.js +14 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/interfaces/base.medias-attr.interface.d.ts +20 -0
  54. package/dist/interfaces/base.medias-attr.interface.js +3 -0
  55. package/dist/interfaces/base.medias-attr.interface.js.map +1 -0
  56. package/dist/interfaces/medias.repository.interface.d.ts +3 -0
  57. package/dist/interfaces/medias.repository.interface.js +3 -0
  58. package/dist/interfaces/medias.repository.interface.js.map +1 -0
  59. package/dist/medias.controller.d.ts +25 -0
  60. package/dist/medias.controller.js +225 -0
  61. package/dist/medias.controller.js.map +1 -0
  62. package/dist/medias.d.ts +42 -0
  63. package/dist/medias.js +373 -0
  64. package/dist/medias.js.map +1 -0
  65. package/dist/medias.module.d.ts +2 -0
  66. package/dist/medias.module.js +32 -0
  67. package/dist/medias.module.js.map +1 -0
  68. package/dist/medias.repository.d.ts +16 -0
  69. package/dist/medias.repository.js +47 -0
  70. package/dist/medias.repository.js.map +1 -0
  71. package/dist/pipe/append-id.pipe.d.ts +6 -0
  72. package/dist/pipe/append-id.pipe.js +28 -0
  73. package/dist/pipe/append-id.pipe.js.map +1 -0
  74. package/dist/pipe/validate-enum.pipe.d.ts +6 -0
  75. package/dist/pipe/validate-enum.pipe.js +34 -0
  76. package/dist/pipe/validate-enum.pipe.js.map +1 -0
  77. package/dist/pipe/validate-id.pipe.d.ts +6 -0
  78. package/dist/pipe/validate-id.pipe.js +31 -0
  79. package/dist/pipe/validate-id.pipe.js.map +1 -0
  80. package/dist/pipe/validate-search.pipe.d.ts +7 -0
  81. package/dist/pipe/validate-search.pipe.js +46 -0
  82. package/dist/pipe/validate-search.pipe.js.map +1 -0
  83. package/dist/responses/deleted.response.d.ts +3 -0
  84. package/dist/responses/deleted.response.js +21 -0
  85. package/dist/responses/deleted.response.js.map +1 -0
  86. package/dist/responses/pagination.response.d.ts +5 -0
  87. package/dist/responses/pagination.response.js +26 -0
  88. package/dist/responses/pagination.response.js.map +1 -0
  89. package/dist/tsconfig.tsbuildinfo +1 -0
  90. package/nest-cli.json +19 -0
  91. package/package.json +60 -0
  92. package/src/base/base.medias.ts +200 -0
  93. package/src/base/base.repository.abstract.ts +28 -0
  94. package/src/base/base.repository.interface.ts +9 -0
  95. package/src/common/common.module.ts +10 -0
  96. package/src/common/common.service.ts +109 -0
  97. package/src/common/dto/add-field-translation.dto.ts +23 -0
  98. package/src/common/dto/get-media.dto.ts +12 -0
  99. package/src/dto/external-media.dto.ts +49 -0
  100. package/src/dto/internal-medias.dto.ts +64 -0
  101. package/src/entities/medias.entity.ts +125 -0
  102. package/src/enum/index.ts +3 -0
  103. package/src/enum/medias.enum.ts +5 -0
  104. package/src/helpers/error.ts +12 -0
  105. package/src/helpers/index.ts +3 -0
  106. package/src/index.ts +13 -0
  107. package/src/interfaces/base.medias-attr.interface.ts +21 -0
  108. package/src/interfaces/medias.repository.interface.ts +4 -0
  109. package/src/medias.controller.ts +244 -0
  110. package/src/medias.module.ts +19 -0
  111. package/src/medias.repository.ts +44 -0
  112. package/src/medias.ts +494 -0
  113. package/src/pipe/append-id.pipe.ts +15 -0
  114. package/src/pipe/validate-enum.pipe.ts +31 -0
  115. package/src/pipe/validate-id.pipe.ts +18 -0
  116. package/src/pipe/validate-search.pipe.ts +41 -0
  117. package/src/responses/deleted.response.ts +6 -0
  118. package/src/responses/pagination.response.ts +10 -0
  119. package/tsconfig.build.json +4 -0
  120. package/tsconfig.json +30 -0
  121. package/tslint.json +18 -0
@@ -0,0 +1,200 @@
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
+ import { throwException } from '../helpers';
8
+
9
+ export abstract class BaseMedias {
10
+ MediaId: string;
11
+ ObjectId: string;
12
+ ObjectType: string;
13
+ Title: string;
14
+ Description: string;
15
+ Type: MediaType;
16
+ IsExternalYN: string;
17
+ ExternalSource: string;
18
+ IsEncryptedYN: string;
19
+ FileName: string;
20
+ FileExtension: string;
21
+ FilePath: string;
22
+ URL: string;
23
+ CreatedById: string;
24
+ CreatedAt: Date;
25
+ UpdatedById: string;
26
+ UpdatedAt: Date;
27
+ mediasRepository: IMediasRepository;
28
+ container: string;
29
+
30
+ protected constructor(
31
+ mediasRepository: IMediasRepository,
32
+ media?: IBaseMediasAttr,
33
+ ) {
34
+ this.mediasRepository = mediasRepository;
35
+ if (media) {
36
+ this.MediaId = media.MediaId ? media.MediaId : cuid();
37
+ this.ObjectId = media.ObjectId;
38
+ this.ObjectType = media.ObjectType;
39
+ this.Title = media.Title;
40
+ this.Description = media.Description;
41
+ this.Type = media.Type;
42
+ this.IsExternalYN = media.IsExternalYN;
43
+ this.ExternalSource = media.ExternalSource;
44
+ this.IsEncryptedYN = media.IsEncryptedYN;
45
+ this.FileName = media.FileName;
46
+ this.FileExtension = media.FileExtension;
47
+ this.URL = media.URL && media.IsExternalYN == "Y" ? media.URL : this.createSaveLocation();
48
+ this.FilePath = media.FilePath && media.IsExternalYN == "Y" ? media.FilePath : this.createFilePath();
49
+ this.CreatedById = media.CreatedById;
50
+ this.CreatedAt = media.CreatedAt;
51
+ this.UpdatedById = media.UpdatedById;
52
+ this.UpdatedAt = media.UpdatedAt;
53
+ }
54
+ }
55
+
56
+ createSaveLocation(): string {
57
+ try {
58
+ const mediaFileStorageType = process.env.MEDIA_STORAGE_TYPE;
59
+ let basePath: string;
60
+ if (mediaFileStorageType === 'local') {
61
+ basePath = process.env.MEDIA_LOCAL_STORAGE_PATH;
62
+ } else {
63
+ basePath = process.env.MEDIA_AZUREBLOB_CONTAINER_NAME;
64
+ }
65
+
66
+ if (!basePath) {
67
+ throw new BadRequestException(
68
+ 'MEDIA_LOCAL_STORAGE_PATH and or MEDIA_AZUREBLOB_CONTAINER_NAME not found.',
69
+ );
70
+ }
71
+ return basePath + `/${this.ObjectType}/${this.ObjectId}`;
72
+ } catch (error) {
73
+ throw error;
74
+ }
75
+ }
76
+
77
+ createFilePath(): string {
78
+ try {
79
+ const fileLocation = this.createSaveLocation();
80
+ return `${fileLocation}/${this.FileName}.${this.FileExtension}`;
81
+ } catch (error) {
82
+ throw error;
83
+ }
84
+ }
85
+
86
+ async create(options?: any): Promise<MediasModel> {
87
+ try {
88
+ return this.mediasRepository.create(
89
+ {
90
+ MediaId: this.MediaId,
91
+ ObjectId: this.ObjectId,
92
+ ObjectType: this.ObjectType,
93
+ Title: this.Title,
94
+ Description: this.Description,
95
+ Type: this.Type,
96
+ IsExternalYN: this.IsExternalYN,
97
+ ExternalSource: this.ExternalSource,
98
+ IsEncryptedYN: this.IsEncryptedYN,
99
+ FileName: this.FileName,
100
+ FileExtension: this.FileExtension,
101
+ FilePath: this.FilePath,
102
+ URL: this.URL,
103
+ CreatedById: this.CreatedById,
104
+ CreatedAt: this.CreatedAt,
105
+ UpdatedById: this.UpdatedById,
106
+ UpdatedAt: this.UpdatedAt,
107
+ },
108
+ options,
109
+ );
110
+ } catch (error) {
111
+ throw error
112
+ }
113
+ }
114
+
115
+ async update(options?: any): Promise<MediasModel | any> {
116
+ try {
117
+ const media = await this.mediasRepository.findOne({
118
+ where: {
119
+ MediaId: this.MediaId,
120
+ },
121
+ });
122
+
123
+ if (!media) {
124
+ throw new BadRequestException('Media not found.');
125
+ }
126
+ return await media.update(
127
+ {
128
+ MediaId: this.MediaId,
129
+ ObjectId: this.ObjectId,
130
+ ObjectType: this.ObjectType,
131
+ Title: this.Title,
132
+ Description: this.Description,
133
+ Type: this.Type,
134
+ IsExternalYN: this.IsExternalYN,
135
+ ExternalSource: this.ExternalSource,
136
+ IsEncryptedYN: this.IsEncryptedYN,
137
+ FileName: this.FileName,
138
+ FileExtension: this.FileExtension,
139
+ FilePath: this.FilePath,
140
+ URL: this.URL,
141
+ CreatedById: this.CreatedById,
142
+ CreatedAt: this.CreatedAt,
143
+ UpdatedById: this.UpdatedById,
144
+ UpdatedAt: this.UpdatedAt,
145
+ },
146
+ options,
147
+ );
148
+ } catch (error) {
149
+ throw error
150
+ }
151
+ }
152
+
153
+ async delete(options?: any): Promise<MediasModel> {
154
+ try {
155
+ const media = await this.mediasRepository.findOne({
156
+ where: {
157
+ MediaId: this.MediaId,
158
+ },
159
+ });
160
+
161
+ const data = {
162
+ ...media.get({plain: true}),
163
+ }
164
+
165
+ if (!media) {
166
+ throw new BadRequestException('Media not found.');
167
+ }
168
+ await media.destroy(options);
169
+ return data;
170
+ } catch (error) {
171
+ throw error
172
+ }
173
+ }
174
+
175
+ async findAll(options?: any): Promise<MediasModel[]> {
176
+ try {
177
+ return this.mediasRepository.findAll(options);
178
+ } catch (error) {
179
+ throw error
180
+ }
181
+ }
182
+
183
+ async findAllWithPagination(
184
+ options?: any,
185
+ ): Promise<{ count: number; rows: MediasModel[] }> {
186
+ try {
187
+ return this.mediasRepository.findAllWithPagination(options);
188
+ } catch (error) {
189
+ throw error
190
+ }
191
+ }
192
+
193
+ async findOne(options?: any): Promise<MediasModel> {
194
+ try {
195
+ return this.mediasRepository.findOne(options);
196
+ } catch (error) {
197
+ throw error
198
+ }
199
+ }
200
+ }
@@ -0,0 +1,28 @@
1
+ import { IBaseRepository } from './base.repository.interface';
2
+
3
+ export abstract class BaseRepository<T> implements IBaseRepository<T> {
4
+ private model: any;
5
+ // private id: string;
6
+
7
+ protected constructor(model: any) {
8
+ this.model = model;
9
+ }
10
+
11
+ public async create(data: any, options?: any): Promise<void | T> {
12
+ return this.model.create(data, options);
13
+ }
14
+
15
+ public async findAll(options: any): Promise<T[]> {
16
+ return this.model.findAll(options);
17
+ }
18
+
19
+ public async findAllWithPagination(
20
+ options: any,
21
+ ): Promise<{ count: number; rows: T[] }> {
22
+ return this.model.findAndCountAll(options);
23
+ }
24
+
25
+ public async findOne(options: any): Promise<T> {
26
+ return this.model.findOne(options);
27
+ }
28
+ }
@@ -0,0 +1,9 @@
1
+ export interface IBaseRepository<T> {
2
+ create(data: T | any, options?: any): Promise<T> | any;
3
+
4
+ findAll(options: any): Promise<T[]>;
5
+
6
+ findAllWithPagination(options: any): Promise<{ count: number; rows: T[] }>;
7
+
8
+ findOne(options: any): Promise<T>;
9
+ }
@@ -0,0 +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 {}
@@ -0,0 +1,109 @@
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
+ ? {}
58
+ : method === 'update'
59
+ ? filteredRecordBefore
60
+ : record.EntityValueBefore,
61
+ EntityValueAfter: record.EntityId
62
+ ? omitBy(filteredRecord, record.EntityId)
63
+ : filteredRecord,
64
+ PerformedById: record.PerformedById,
65
+ PerformedAt: record.PerformedAt || Date.now(),
66
+ EntityId: record.EntityId ? record.EntityId : cuid(),
67
+ };
68
+
69
+ try {
70
+ const { data } = await axios.post(
71
+ `${this.commonApiUrl}/activity-histories`,
72
+ payload,
73
+ );
74
+ return data.EntityId;
75
+ } catch (err) {
76
+ this.handleAxiosError(err);
77
+ }
78
+ }
79
+
80
+ async getList(listName: string): Promise<[]> {
81
+ try {
82
+ const { data } = await axios.get(`${this.commonApiUrl}/lists/items`, {
83
+ params: { ListName: listName },
84
+ });
85
+ return data?.rows;
86
+ } catch (err) {
87
+ this.handleAxiosError(err);
88
+ }
89
+ }
90
+
91
+ async addFieldTranslation(payload: AddFieldTranslationDto) {
92
+ try {
93
+ await axios.post(`${this.commonApiUrl}/field-translations`, payload);
94
+ } catch (err) {
95
+ this.handleAxiosError(err);
96
+ }
97
+ }
98
+
99
+ async getMedia(query: GetMediaDto) {
100
+ try {
101
+ const { data } = await axios.get(`${this.commonApiUrl}/medias`, {
102
+ params: query,
103
+ });
104
+ return data?.rows;
105
+ } catch (err) {
106
+ this.handleAxiosError(err);
107
+ }
108
+ }
109
+ }
@@ -0,0 +1,23 @@
1
+ import { IsNotEmpty, IsString } from 'class-validator';
2
+
3
+ export class AddFieldTranslationDto {
4
+ @IsNotEmpty()
5
+ @IsString()
6
+ ObjectTable: string;
7
+
8
+ @IsNotEmpty()
9
+ @IsString()
10
+ ObjectField: string;
11
+
12
+ @IsNotEmpty()
13
+ @IsString()
14
+ ObjectId: string;
15
+
16
+ @IsNotEmpty()
17
+ @IsString()
18
+ LanguageCode: string;
19
+
20
+ @IsNotEmpty()
21
+ @IsString()
22
+ Translation: string;
23
+ }
@@ -0,0 +1,12 @@
1
+ import { IsString } from 'class-validator';
2
+
3
+ export class GetMediaDto {
4
+ @IsString()
5
+ ObjectID?: string;
6
+
7
+ @IsString()
8
+ ObjectType?: string;
9
+
10
+ @IsString()
11
+ Title: string;
12
+ }
@@ -0,0 +1,49 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+ import { IsEnum, IsNotEmpty, IsString, MaxLength } from 'class-validator';
3
+ import { MediaType } from '../enum/medias.enum';
4
+
5
+ export class ExternalMediaDto {
6
+ @IsNotEmpty()
7
+ @IsString()
8
+ @MaxLength(30)
9
+ @ApiProperty({ type: String, description: 'ObjectID' })
10
+ ObjectId: string;
11
+
12
+ @IsNotEmpty()
13
+ @IsString()
14
+ @MaxLength(200)
15
+ @ApiProperty({ type: String, description: 'ObjectType' })
16
+ ObjectType: string;
17
+
18
+ @IsNotEmpty()
19
+ @ApiProperty({
20
+ type: String,
21
+ description: 'Enum either Photo, Video, Document',
22
+ })
23
+ @IsEnum(MediaType)
24
+ Type: MediaType;
25
+
26
+ @IsNotEmpty()
27
+ @IsString()
28
+ @MaxLength(200)
29
+ @ApiProperty({ type: String, description: 'URL whre the file stored' })
30
+ URL: string;
31
+
32
+ @IsNotEmpty()
33
+ @IsString()
34
+ @MaxLength(200)
35
+ @ApiProperty({ type: String, description: 'external source of the file' })
36
+ ExternalSource: string;
37
+
38
+ @IsNotEmpty()
39
+ @IsString()
40
+ @MaxLength(100)
41
+ @ApiProperty({ type: String, description: 'title of the media' })
42
+ Title: string;
43
+
44
+ @IsNotEmpty()
45
+ @IsString()
46
+ @MaxLength(1000)
47
+ @ApiProperty({ type: String, description: 'Description of the media' })
48
+ Description: string;
49
+ }
@@ -0,0 +1,64 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+ import { IsEnum, IsNotEmpty, IsString, MaxLength } from 'class-validator';
3
+ import { MediaType } from '../enum/medias.enum';
4
+
5
+ export class InternalMediaDto {
6
+ @IsNotEmpty()
7
+ @IsString()
8
+ @MaxLength(30)
9
+ @ApiProperty({ type: String, description: 'ObjectID' })
10
+ ObjectId: string;
11
+
12
+ @IsNotEmpty()
13
+ @IsString()
14
+ @MaxLength(200)
15
+ @ApiProperty({ type: String, description: 'ObjectType' })
16
+ ObjectType: string;
17
+
18
+ @IsNotEmpty()
19
+ @ApiProperty({
20
+ type: String,
21
+ description: 'Enum either Photo, Video, Document',
22
+ })
23
+ @IsEnum(MediaType)
24
+ Type: MediaType;
25
+
26
+ @IsNotEmpty()
27
+ @IsString()
28
+ @MaxLength(200)
29
+ @ApiProperty({ type: String, description: 'file name without extension' })
30
+ FileName: string;
31
+
32
+ @IsNotEmpty()
33
+ @IsString()
34
+ @MaxLength(10)
35
+ @ApiProperty({ type: String, description: 'extention of file in jpg etc' })
36
+ FileExtension: string;
37
+
38
+ @ApiProperty({
39
+ type: String,
40
+ description: 'File stream buffer',
41
+ format: 'binary',
42
+ })
43
+ FileStream: any;
44
+
45
+ @IsNotEmpty()
46
+ @IsString()
47
+ @MaxLength(100)
48
+ @ApiProperty({ type: String, description: 'title of the media' })
49
+ Title: string;
50
+
51
+ @IsNotEmpty()
52
+ @IsString()
53
+ @MaxLength(1000)
54
+ @ApiProperty({ type: String, description: 'Description of the media' })
55
+ Description: string;
56
+
57
+ @IsNotEmpty()
58
+ @IsEnum(['N', 'Y'])
59
+ @ApiProperty({
60
+ type: String,
61
+ description: 'Option if media needed to be encryped : Y or N',
62
+ })
63
+ IsEncryptedYN: string;
64
+ }
@@ -0,0 +1,125 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+ import {
3
+ Column,
4
+ CreatedAt,
5
+ Model,
6
+ Table,
7
+ UpdatedAt,
8
+ } from 'sequelize-typescript';
9
+ import { MediaType } from '../enum';
10
+
11
+ @Table({ tableName: 'common_Media', createdAt: false, updatedAt: false })
12
+ export class MediasModel extends Model {
13
+ @Column({
14
+ primaryKey: true,
15
+ allowNull: false,
16
+ })
17
+ @ApiProperty({ type: String, description: 'MediaID' })
18
+ MediaId: string;
19
+
20
+ @Column({
21
+ allowNull: false,
22
+ })
23
+ @ApiProperty({ type: String, description: 'ObjectID' })
24
+ ObjectId: string;
25
+
26
+ @Column({
27
+ allowNull: false,
28
+ })
29
+ @ApiProperty({ type: String, description: 'ObjectType' })
30
+ ObjectType: string;
31
+
32
+ @Column({
33
+ allowNull: true,
34
+ })
35
+ @ApiProperty({ type: String, description: 'title of the media' })
36
+ Title: string;
37
+
38
+ @Column({
39
+ allowNull: true,
40
+ })
41
+ @ApiProperty({ type: String, description: 'Description of the media' })
42
+ Description: string;
43
+
44
+ @Column({
45
+ allowNull: false,
46
+ })
47
+ @ApiProperty({
48
+ type: String,
49
+ description: 'Enum either Photo, Video, Document',
50
+ })
51
+ Type: MediaType;
52
+
53
+ @Column({
54
+ allowNull: false,
55
+ })
56
+ @ApiProperty({ type: String, description: 'isExternal either Y, N' })
57
+ IsExternalYN: string;
58
+
59
+ @Column({
60
+ allowNull: true,
61
+ })
62
+ @ApiProperty({ type: String, description: 'External surce for the file' })
63
+ ExternalSource: string;
64
+
65
+ @Column({
66
+ allowNull: false,
67
+ })
68
+ @ApiProperty({ type: String, description: 'isExternal either Y, N' })
69
+ IsEncryptedYN: string;
70
+
71
+ @Column({
72
+ allowNull: true,
73
+ })
74
+ @ApiProperty({ type: String, description: 'file name without extension' })
75
+ FileName: string;
76
+
77
+ @Column({
78
+ allowNull: true,
79
+ })
80
+ @ApiProperty({ type: String, description: 'extention of file in jpg etc' })
81
+ FileExtension: string;
82
+
83
+ @Column({
84
+ allowNull: true,
85
+ })
86
+ @ApiProperty({
87
+ type: String,
88
+ description: 'location on the media in term of path',
89
+ })
90
+ FilePath: string;
91
+
92
+ @Column({
93
+ allowNull: true,
94
+ })
95
+ @ApiProperty({ type: String, description: 'URl of the media' })
96
+ URL: string;
97
+
98
+ @ApiProperty({
99
+ example: new Date(),
100
+ description: 'Timestamp for data creation.',
101
+ })
102
+ @CreatedAt
103
+ CreatedAt: Date;
104
+
105
+ @ApiProperty({
106
+ example: '138140891dd211b288d34bc7b4312a49',
107
+ description: 'The CreatedById for Media.',
108
+ })
109
+ @Column({ allowNull: false })
110
+ CreatedById: string;
111
+
112
+ @ApiProperty({
113
+ example: new Date(),
114
+ description: 'Timestamp for latest data modification',
115
+ })
116
+ @UpdatedAt
117
+ UpdatedAt: Date;
118
+
119
+ @ApiProperty({
120
+ example: '138140891dd211b288d34bc7b4312a49',
121
+ description: 'The UpdatedById for Media.',
122
+ })
123
+ @Column({ allowNull: false })
124
+ UpdatedById: string;
125
+ }
@@ -0,0 +1,3 @@
1
+ import { MediaType } from './medias.enum';
2
+
3
+ export { MediaType };
@@ -0,0 +1,5 @@
1
+ export enum MediaType {
2
+ Photo = 'Photo',
3
+ Video = 'Video',
4
+ Document = 'Document',
5
+ }
@@ -0,0 +1,12 @@
1
+ import { HttpException } from '@nestjs/common';
2
+
3
+ export function throwException(err) {
4
+ if (err.response) {
5
+ throw err;
6
+ } else {
7
+ throw new HttpException(
8
+ 'Something went wrong. Please see application log.',
9
+ err.statusCode,
10
+ );
11
+ }
12
+ }
@@ -0,0 +1,3 @@
1
+ import { throwException } from './error';
2
+
3
+ export { throwException };
package/src/index.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { MediasModule } from "./medias.module";
2
+ import { MediasController } from "./medias.controller";
3
+ import { MediasRepository } from "./medias.repository";
4
+ import { MediasModel } from "./entities/medias.entity";
5
+ import { Medias } from "./medias";
6
+
7
+ export {
8
+ MediasModule,
9
+ MediasController,
10
+ MediasRepository,
11
+ MediasModel,
12
+ Medias,
13
+ }
@@ -0,0 +1,21 @@
1
+ import { MediaType } from '../enum/medias.enum';
2
+
3
+ export interface IBaseMediasAttr {
4
+ MediaId: string;
5
+ ObjectId: string;
6
+ ObjectType: string;
7
+ Title: string;
8
+ Description: string;
9
+ Type: MediaType;
10
+ IsExternalYN: string;
11
+ ExternalSource: string;
12
+ IsEncryptedYN: string;
13
+ FileName: string;
14
+ FileExtension: string;
15
+ FilePath: string;
16
+ URL: string;
17
+ CreatedAt: Date;
18
+ UpdatedAt: Date;
19
+ CreatedById: string;
20
+ UpdatedById: string;
21
+ }