@tomei/media 0.1.0 → 0.2.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.
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ await queryInterface.createTable('common_Media', {
6
+ MediaId: {
7
+ type: Sequelize.STRING(30),
8
+ primaryKey: true,
9
+ allowNull: false,
10
+ },
11
+ ObjectId: {
12
+ type: Sequelize.STRING(30),
13
+ allowNull: false,
14
+ },
15
+ ObjectType: {
16
+ type: Sequelize.STRING(200),
17
+ allowNull: false,
18
+ },
19
+ Title: {
20
+ type: Sequelize.STRING(200),
21
+ allowNull: false,
22
+ },
23
+ Description: {
24
+ type: Sequelize.TEXT,
25
+ allowNull: true,
26
+ },
27
+ Type: {
28
+ type: Sequelize.ENUM(['Photo', 'Video', 'Document']),
29
+ allowNull: false,
30
+ },
31
+ IsExternalYN: {
32
+ type: Sequelize.ENUM(['Y', 'N']),
33
+ allowNull: false,
34
+ },
35
+ ExternalSource: {
36
+ type: Sequelize.STRING(200),
37
+ allowNull: true,
38
+ },
39
+ IsEncryptedYN: {
40
+ type: Sequelize.ENUM(['Y', 'N']),
41
+ allowNull: false,
42
+ },
43
+ FileName: {
44
+ type: Sequelize.STRING(200),
45
+ allowNull: true,
46
+ },
47
+ FileExtension: {
48
+ type: Sequelize.STRING(10),
49
+ allowNull: true,
50
+ },
51
+ FilePath: {
52
+ type: Sequelize.STRING(200),
53
+ allowNull: true,
54
+ },
55
+ URL: {
56
+ type: Sequelize.STRING(200),
57
+ allowNull: true,
58
+ },
59
+ CreatedAt: {
60
+ allowNull: false,
61
+ defaultValue: new Date(),
62
+ type: Sequelize.DATE,
63
+ },
64
+ CreatedById: {
65
+ allowNull: false,
66
+ type: Sequelize.STRING,
67
+ },
68
+ UpdatedAt: {
69
+ allowNull: false,
70
+ defaultValue: new Date(),
71
+ type: Sequelize.DATE,
72
+ },
73
+ UpdatedById: {
74
+ allowNull: false,
75
+ type: Sequelize.STRING,
76
+ },
77
+ });
78
+ },
79
+
80
+ async down(queryInterface) {
81
+ await queryInterface.dropTable('common_Media');
82
+ },
83
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/media",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "NestJS package for media module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -8,7 +8,8 @@
8
8
  "build": "tsc",
9
9
  "prepare": "npm run build",
10
10
  "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"libs/**/*.ts\"",
11
- "lint": "tslint -p tsconfig.json -c tslint.json"
11
+ "lint": "tslint -p tsconfig.json -c tslint.json",
12
+ "eslint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
12
13
  },
13
14
  "keywords": [
14
15
  "nestjs",
@@ -32,6 +33,10 @@
32
33
  "@types/multer": "^1.4.7",
33
34
  "@types/node": "^18.0.6",
34
35
  "@types/sequelize": "^4.28.14",
36
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
37
+ "eslint": "^8.21.0",
38
+ "eslint-config-prettier": "^8.5.0",
39
+ "eslint-plugin-prettier": "^4.2.1",
35
40
  "husky": "^7.0.2",
36
41
  "lint-staged": "^11.1.2",
37
42
  "prettier": "^2.7.1",
@@ -56,5 +61,14 @@
56
61
  "class-validator": "^0.13.2",
57
62
  "cuid": "^2.1.8",
58
63
  "multer": "^1.4.5-lts.1"
64
+ },
65
+ "lint-staged": {
66
+ "*/**/*.{js,ts,tsx}": [
67
+ "npm run lint",
68
+ "npm run eslint",
69
+ "npm run format",
70
+ "npm run build",
71
+ "git add ."
72
+ ]
59
73
  }
60
74
  }
@@ -4,7 +4,6 @@ import { BadRequestException } from '@nestjs/common';
4
4
  import { IMediasRepository } from '../interfaces/medias.repository.interface';
5
5
  import { MediasModel } from '../entities/medias.entity';
6
6
  import { IBaseMediasAttr } from '../interfaces/base.medias-attr.interface';
7
- import { throwException } from '../helpers';
8
7
 
9
8
  export abstract class BaseMedias {
10
9
  MediaId: string;
@@ -33,7 +32,12 @@ export abstract class BaseMedias {
33
32
  ) {
34
33
  this.mediasRepository = mediasRepository;
35
34
  if (media) {
36
- this.MediaId = media.MediaId ? media.MediaId : cuid();
35
+ this.init(media);
36
+ }
37
+ }
38
+
39
+ init(media: IBaseMediasAttr){
40
+ this.MediaId = media.MediaId ? media.MediaId : cuid();
37
41
  this.ObjectId = media.ObjectId;
38
42
  this.ObjectType = media.ObjectType;
39
43
  this.Title = media.Title;
@@ -44,13 +48,18 @@ export abstract class BaseMedias {
44
48
  this.IsEncryptedYN = media.IsEncryptedYN;
45
49
  this.FileName = media.FileName;
46
50
  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();
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();
49
59
  this.CreatedById = media.CreatedById;
50
60
  this.CreatedAt = media.CreatedAt;
51
61
  this.UpdatedById = media.UpdatedById;
52
62
  this.UpdatedAt = media.UpdatedAt;
53
- }
54
63
  }
55
64
 
56
65
  createSaveLocation(): string {
@@ -108,7 +117,7 @@ export abstract class BaseMedias {
108
117
  options,
109
118
  );
110
119
  } catch (error) {
111
- throw error
120
+ throw error;
112
121
  }
113
122
  }
114
123
 
@@ -146,7 +155,7 @@ export abstract class BaseMedias {
146
155
  options,
147
156
  );
148
157
  } catch (error) {
149
- throw error
158
+ throw error;
150
159
  }
151
160
  }
152
161
 
@@ -159,8 +168,8 @@ export abstract class BaseMedias {
159
168
  });
160
169
 
161
170
  const data = {
162
- ...media.get({plain: true}),
163
- }
171
+ ...media.get({ plain: true }),
172
+ };
164
173
 
165
174
  if (!media) {
166
175
  throw new BadRequestException('Media not found.');
@@ -168,7 +177,7 @@ export abstract class BaseMedias {
168
177
  await media.destroy(options);
169
178
  return data;
170
179
  } catch (error) {
171
- throw error
180
+ throw error;
172
181
  }
173
182
  }
174
183
 
@@ -176,7 +185,7 @@ export abstract class BaseMedias {
176
185
  try {
177
186
  return this.mediasRepository.findAll(options);
178
187
  } catch (error) {
179
- throw error
188
+ throw error;
180
189
  }
181
190
  }
182
191
 
@@ -186,7 +195,7 @@ export abstract class BaseMedias {
186
195
  try {
187
196
  return this.mediasRepository.findAllWithPagination(options);
188
197
  } catch (error) {
189
- throw error
198
+ throw error;
190
199
  }
191
200
  }
192
201
 
@@ -194,7 +203,7 @@ export abstract class BaseMedias {
194
203
  try {
195
204
  return this.mediasRepository.findOne(options);
196
205
  } catch (error) {
197
- throw error
206
+ throw error;
198
207
  }
199
208
  }
200
209
  }
@@ -4,7 +4,7 @@ import { CommonService } from './common.service';
4
4
 
5
5
  @Module({
6
6
  providers: [CommonService],
7
- imports:[ConfigModule],
7
+ imports: [ConfigModule],
8
8
  exports: [CommonService],
9
9
  })
10
10
  export class CommonModule {}
package/src/index.ts CHANGED
@@ -1,13 +1,23 @@
1
- import { MediasModule } from "./medias.module";
2
- import { MediasController } from "./medias.controller";
3
1
  import { MediasRepository } from "./medias.repository";
4
2
  import { MediasModel } from "./entities/medias.entity";
5
3
  import { Medias } from "./medias";
4
+ import { CommonModule } from "./common/common.module";
5
+ import { CommonService } from "./common/common.service";
6
+ import { ExternalMediaDto } from "./dto/external-media.dto";
7
+ import { InternalMediaDto } from "./dto/internal-medias.dto";
8
+ import { MediaType } from "./enum";
9
+ import { IBaseMediasAttr } from "./interfaces/base.medias-attr.interface";
10
+ import { IMediasRepository } from "./interfaces/medias.repository.interface";
6
11
 
7
12
  export {
8
- MediasModule,
9
- MediasController,
10
13
  MediasRepository,
11
14
  MediasModel,
12
15
  Medias,
16
+ CommonModule,
17
+ CommonService,
18
+ ExternalMediaDto,
19
+ InternalMediaDto,
20
+ MediaType,
21
+ IBaseMediasAttr,
22
+ IMediasRepository,
13
23
  }
@@ -11,16 +11,13 @@ export class MediasRepository
11
11
  implements IMediasRepository
12
12
  {
13
13
  constructor(
14
- @InjectModel(MediasModel, 'csmsDB')
14
+ @InjectModel(MediasModel)
15
15
  private readonly mediasModel: typeof MediasModel,
16
16
  ) {
17
17
  super(mediasModel);
18
18
  }
19
19
 
20
- create(
21
- data: IBaseMediasAttr,
22
- options?: any,
23
- ): Promise<MediasModel> | any {
20
+ create(data: IBaseMediasAttr, options?: any): Promise<MediasModel> | any {
24
21
  return this.mediasModel.create({ ...data }, options);
25
22
  }
26
23