@tomei/media 0.4.9 → 0.5.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 (78) 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/base/base.medias.d.ts +2 -3
  9. package/dist/base/base.medias.js +9 -8
  10. package/dist/base/base.medias.js.map +1 -1
  11. package/dist/base/index.d.ts +2 -0
  12. package/dist/base/index.js +6 -0
  13. package/dist/base/index.js.map +1 -0
  14. package/dist/common/common.service.spec.d.ts +0 -0
  15. package/dist/common/common.service.spec.js +5 -0
  16. package/dist/common/common.service.spec.js.map +1 -0
  17. package/dist/database.d.ts +4 -0
  18. package/dist/database.js +16 -0
  19. package/dist/database.js.map +1 -0
  20. package/dist/dto/medias.dto.d.ts +12 -0
  21. package/dist/dto/medias.dto.js +88 -0
  22. package/dist/dto/medias.dto.js.map +1 -0
  23. package/dist/entities/index.d.ts +2 -0
  24. package/dist/entities/index.js +6 -0
  25. package/dist/entities/index.js.map +1 -0
  26. package/dist/entities/media.entity.d.ts +21 -0
  27. package/dist/entities/media.entity.js +152 -0
  28. package/dist/entities/media.entity.js.map +1 -0
  29. package/dist/index.d.ts +12 -11
  30. package/dist/index.js +3 -1
  31. package/dist/index.js.map +1 -1
  32. package/dist/interfaces/commonService.interface.d.ts +17 -0
  33. package/dist/interfaces/commonService.interface.js +3 -0
  34. package/dist/interfaces/commonService.interface.js.map +1 -0
  35. package/dist/interfaces/index.d.ts +3 -0
  36. package/dist/interfaces/index.js +3 -0
  37. package/dist/interfaces/index.js.map +1 -0
  38. package/dist/interfaces/media.repository.interface.d.ts +10 -0
  39. package/dist/interfaces/media.repository.interface.js +3 -0
  40. package/dist/interfaces/media.repository.interface.js.map +1 -0
  41. package/dist/interfaces/medias-attr.interface.d.ts +22 -0
  42. package/dist/interfaces/medias-attr.interface.js +3 -0
  43. package/dist/interfaces/medias-attr.interface.js.map +1 -0
  44. package/dist/medias.controller copy.d.ts +25 -0
  45. package/dist/medias.controller copy.js +225 -0
  46. package/dist/medias.controller copy.js.map +1 -0
  47. package/dist/medias.controller.d.ts +29 -0
  48. package/dist/medias.controller.js +120 -0
  49. package/dist/medias.controller.js.map +1 -0
  50. package/dist/medias.controller.old.d.ts +25 -0
  51. package/dist/medias.controller.old.js +225 -0
  52. package/dist/medias.controller.old.js.map +1 -0
  53. package/dist/medias.d.ts +3 -3
  54. package/dist/medias.js +4 -2
  55. package/dist/medias.js.map +1 -1
  56. package/dist/medias.module.d.ts +2 -0
  57. package/dist/medias.module.js +32 -0
  58. package/dist/medias.module.js.map +1 -0
  59. package/dist/medias.repository.d.ts +6 -14
  60. package/dist/medias.repository.js +46 -37
  61. package/dist/medias.repository.js.map +1 -1
  62. package/dist/tsconfig.tsbuildinfo +1 -1
  63. package/migration/0001-add-defaultyn-hiddenyn-to-media-table.js +36 -36
  64. package/migration/media-migration.js +82 -82
  65. package/package.json +75 -74
  66. package/src/base/base.medias.ts +33 -36
  67. package/src/common/common.module.ts +10 -10
  68. package/src/common/common.service.ts +107 -107
  69. package/src/common/dto/add-field-translation.dto.ts +23 -23
  70. package/src/common/dto/get-media.dto.ts +12 -12
  71. package/src/database.ts +16 -0
  72. package/src/entities/medias.entity.ts +125 -125
  73. package/src/index.ts +23 -22
  74. package/src/medias.repository.ts +43 -29
  75. package/src/medias.ts +4 -7
  76. package/src/pipe/validate-search.pipe.ts +44 -44
  77. package/tsconfig.build.json +4 -4
  78. package/tslint.json +18 -18
@@ -1,36 +1,36 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- async up(queryInterface, Sequelize) {
5
- const table = await queryInterface.describeTable('common_Media');
6
-
7
- if (!table.hasOwnProperty('DefaultYN')) {
8
- queryInterface.addColumn('common_Media', 'DefaultYN', {
9
- type: Sequelize.ENUM(['Y', 'N']),
10
- allowNull: true,
11
- defaultValue: 'N',
12
- });
13
- }
14
-
15
- if (!table.hasOwnProperty('HiddenYN')) {
16
- queryInterface.addColumn('common_Media', 'HiddenYN', {
17
- type: Sequelize.ENUM(['Y', 'N']),
18
- allowNull: true,
19
- defaultValue: 'N',
20
- });
21
- }
22
- },
23
-
24
- down(queryInterface) {
25
- return queryInterface.sequelize.transaction((t) => {
26
- return Promise.all([
27
- queryInterface.removeColumn('common_Media', 'DefaultYN', {
28
- transaction: t,
29
- }),
30
- queryInterface.removeColumn('common_Media', 'HiddenYN', {
31
- transaction: t,
32
- }),
33
- ]);
34
- });
35
- },
36
- };
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ const table = await queryInterface.describeTable('common_Media');
6
+
7
+ if (!table.hasOwnProperty('DefaultYN')) {
8
+ queryInterface.addColumn('common_Media', 'DefaultYN', {
9
+ type: Sequelize.ENUM(['Y', 'N']),
10
+ allowNull: true,
11
+ defaultValue: 'N',
12
+ });
13
+ }
14
+
15
+ if (!table.hasOwnProperty('HiddenYN')) {
16
+ queryInterface.addColumn('common_Media', 'HiddenYN', {
17
+ type: Sequelize.ENUM(['Y', 'N']),
18
+ allowNull: true,
19
+ defaultValue: 'N',
20
+ });
21
+ }
22
+ },
23
+
24
+ down(queryInterface) {
25
+ return queryInterface.sequelize.transaction((t) => {
26
+ return Promise.all([
27
+ queryInterface.removeColumn('common_Media', 'DefaultYN', {
28
+ transaction: t,
29
+ }),
30
+ queryInterface.removeColumn('common_Media', 'HiddenYN', {
31
+ transaction: t,
32
+ }),
33
+ ]);
34
+ });
35
+ },
36
+ };
@@ -1,83 +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
- },
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
83
  };
package/package.json CHANGED
@@ -1,74 +1,75 @@
1
- {
2
- "name": "@tomei/media",
3
- "version": "0.4.9",
4
- "description": "NestJS package for media module",
5
- "main": "dist/index.js",
6
- "scripts": {
7
- "start:dev": "tsc -w",
8
- "build": "tsc",
9
- "prepare": "npm run build",
10
- "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"libs/**/*.ts\"",
11
- "lint": "tslint -p tsconfig.json -c tslint.json",
12
- "eslint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
13
- },
14
- "keywords": [
15
- "nestjs",
16
- "tomei",
17
- "media"
18
- ],
19
- "author": "Faiz Shahudin <faiz@tomei.com.my>",
20
- "license": "ISC",
21
- "repository": {
22
- "type": "git",
23
- "url": "https://gitlab.com/tomei-package/media.git"
24
- },
25
- "peerDependencies": {
26
- "@nestjs/common": "^9.0.5",
27
- "@nestjs/core": "^9.0.8",
28
- "sequelize-typescript": "^2.1.3"
29
- },
30
- "devDependencies": {
31
- "@nestjs/swagger": "^6.0.4",
32
- "@types/multer": "^1.4.7",
33
- "@types/node": "^18.0.6",
34
- "@types/sequelize": "^4.28.14",
35
- "@typescript-eslint/eslint-plugin": "^5.33.0",
36
- "eslint": "^8.21.0",
37
- "eslint-config-prettier": "^8.5.0",
38
- "eslint-plugin-prettier": "^4.2.1",
39
- "husky": "^8.0.3",
40
- "lint-staged": "^11.1.2",
41
- "prettier": "^2.7.1",
42
- "ts-node": "^10.9.1",
43
- "tsc-watch": "^5.0.3",
44
- "tsconfig-paths": "^4.0.0",
45
- "tslint": "^6.1.3",
46
- "typescript": "^4.7.4"
47
- },
48
- "publishConfig": {
49
- "access": "public"
50
- },
51
- "dependencies": {
52
- "@azure/storage-blob": "^12.11.0",
53
- "@nestjs/config": "^2.2.0",
54
- "@nestjs/platform-express": "^9.0.8",
55
- "@nestjs/sequelize": "^9.0.0",
56
- "@tomei/activity-history": "^0.1.9",
57
- "@tomei/sso": "^0.11.3",
58
- "@types/express": "^4.17.13",
59
- "axios": "^0.27.2",
60
- "class-transformer": "^0.5.1",
61
- "class-validator": "^0.14.0",
62
- "cuid": "^2.1.8",
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
- ]
73
- }
74
- }
1
+ {
2
+ "name": "@tomei/media",
3
+ "version": "0.5.0",
4
+ "description": "NestJS package for media module",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "start:dev": "tsc -w",
8
+ "build": "tsc",
9
+ "prepare": "npm run build",
10
+ "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"libs/**/*.ts\"",
11
+ "lint": "tslint -p tsconfig.json -c tslint.json",
12
+ "eslint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
13
+ },
14
+ "keywords": [
15
+ "nestjs",
16
+ "tomei",
17
+ "media"
18
+ ],
19
+ "author": "Faiz Shahudin <faiz@tomei.com.my>",
20
+ "license": "ISC",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://gitlab.com/tomei-package/media.git"
24
+ },
25
+ "peerDependencies": {
26
+ "@nestjs/common": "^9.0.5",
27
+ "@nestjs/core": "^9.0.8",
28
+ "sequelize-typescript": "^2.1.3"
29
+ },
30
+ "devDependencies": {
31
+ "@nestjs/swagger": "^6.0.4",
32
+ "@types/multer": "^1.4.7",
33
+ "@types/node": "^18.0.6",
34
+ "@types/sequelize": "^4.28.14",
35
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
36
+ "eslint": "^8.21.0",
37
+ "eslint-config-prettier": "^8.5.0",
38
+ "eslint-plugin-prettier": "^4.2.1",
39
+ "husky": "^8.0.3",
40
+ "lint-staged": "^11.1.2",
41
+ "prettier": "^2.7.1",
42
+ "ts-node": "^10.9.1",
43
+ "tsc-watch": "^5.0.3",
44
+ "tsconfig-paths": "^4.0.0",
45
+ "tslint": "^6.1.3",
46
+ "typescript": "^4.7.4"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "dependencies": {
52
+ "@azure/storage-blob": "^12.11.0",
53
+ "@nestjs/config": "^2.2.0",
54
+ "@nestjs/platform-express": "^9.0.8",
55
+ "@nestjs/sequelize": "^9.0.0",
56
+ "@tomei/activity-history": "^0.1.9",
57
+ "@tomei/general": "^0.4.12",
58
+ "@tomei/sso": "^0.11.3",
59
+ "@types/express": "^4.17.13",
60
+ "axios": "^0.27.2",
61
+ "class-transformer": "^0.5.1",
62
+ "class-validator": "^0.14.0",
63
+ "cuid": "^2.1.8",
64
+ "multer": "^1.4.5-lts.1"
65
+ },
66
+ "lint-staged": {
67
+ "*/**/*.{js,ts,tsx}": [
68
+ "npm run lint",
69
+ "npm run eslint",
70
+ "npm run format",
71
+ "npm run build",
72
+ "git add ."
73
+ ]
74
+ }
75
+ }
@@ -1,9 +1,9 @@
1
1
  import { MediaType } from '../enum/medias.enum';
2
2
  import * as cuid from 'cuid';
3
3
  import { BadRequestException } from '@nestjs/common';
4
- import { IMediasRepository } from '../interfaces/medias.repository.interface';
5
4
  import { MediasModel } from '../entities/medias.entity';
6
5
  import { IBaseMediasAttr } from '../interfaces/base.medias-attr.interface';
6
+ import { MediasRepository } from '../medias.repository';
7
7
 
8
8
  export abstract class BaseMedias {
9
9
  MediaId: string;
@@ -23,43 +23,40 @@ export abstract class BaseMedias {
23
23
  CreatedAt: Date;
24
24
  UpdatedById: string;
25
25
  UpdatedAt: Date;
26
- mediasRepository: IMediasRepository;
27
26
  container: string;
28
27
 
29
- protected constructor(
30
- mediasRepository: IMediasRepository,
31
- media?: IBaseMediasAttr,
32
- ) {
33
- this.mediasRepository = mediasRepository;
28
+ private static mediasRepository = new MediasRepository();
29
+
30
+ protected constructor(media?: IBaseMediasAttr) {
34
31
  if (media) {
35
32
  this.init(media);
36
33
  }
37
34
  }
38
35
 
39
- init(media: IBaseMediasAttr){
36
+ init(media: IBaseMediasAttr) {
40
37
  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;
38
+ this.ObjectId = media.ObjectId;
39
+ this.ObjectType = media.ObjectType;
40
+ this.Title = media.Title;
41
+ this.Description = media.Description;
42
+ this.Type = media.Type;
43
+ this.IsExternalYN = media.IsExternalYN;
44
+ this.ExternalSource = media.ExternalSource;
45
+ this.IsEncryptedYN = media.IsEncryptedYN;
46
+ this.FileName = media.FileName;
47
+ this.FileExtension = media.FileExtension;
48
+ this.URL =
49
+ media.URL && media.IsExternalYN === 'Y'
50
+ ? media.URL
51
+ : this.createSaveLocation();
52
+ this.FilePath =
53
+ media.FilePath && media.IsExternalYN === 'Y'
54
+ ? media.FilePath
55
+ : this.createFilePath();
56
+ this.CreatedById = media.CreatedById;
57
+ this.CreatedAt = media.CreatedAt;
58
+ this.UpdatedById = media.UpdatedById;
59
+ this.UpdatedAt = media.UpdatedAt;
63
60
  }
64
61
 
65
62
  createSaveLocation(): string {
@@ -94,7 +91,7 @@ export abstract class BaseMedias {
94
91
 
95
92
  async create(options?: any): Promise<MediasModel> {
96
93
  try {
97
- return this.mediasRepository.create(
94
+ return BaseMedias.mediasRepository.create(
98
95
  {
99
96
  MediaId: this.MediaId,
100
97
  ObjectId: this.ObjectId,
@@ -123,7 +120,7 @@ export abstract class BaseMedias {
123
120
 
124
121
  async update(options?: any): Promise<MediasModel | any> {
125
122
  try {
126
- const media = await this.mediasRepository.findOne({
123
+ const media = await BaseMedias.mediasRepository.findOne({
127
124
  where: {
128
125
  MediaId: this.MediaId,
129
126
  },
@@ -161,7 +158,7 @@ export abstract class BaseMedias {
161
158
 
162
159
  async delete(options?: any): Promise<MediasModel> {
163
160
  try {
164
- const media = await this.mediasRepository.findOne({
161
+ const media = await BaseMedias.mediasRepository.findOne({
165
162
  where: {
166
163
  MediaId: this.MediaId,
167
164
  },
@@ -183,7 +180,7 @@ export abstract class BaseMedias {
183
180
 
184
181
  async findAll(options?: any): Promise<MediasModel[]> {
185
182
  try {
186
- return this.mediasRepository.findAll(options);
183
+ return BaseMedias.mediasRepository.findAll(options);
187
184
  } catch (error) {
188
185
  throw error;
189
186
  }
@@ -193,7 +190,7 @@ export abstract class BaseMedias {
193
190
  options?: any,
194
191
  ): Promise<{ count: number; rows: MediasModel[] }> {
195
192
  try {
196
- return this.mediasRepository.findAllWithPagination(options);
193
+ return BaseMedias.mediasRepository.findAndCountAll(options);
197
194
  } catch (error) {
198
195
  throw error;
199
196
  }
@@ -201,7 +198,7 @@ export abstract class BaseMedias {
201
198
 
202
199
  async findOne(options?: any): Promise<MediasModel> {
203
200
  try {
204
- return this.mediasRepository.findOne(options);
201
+ return BaseMedias.mediasRepository.findOne(options);
205
202
  } catch (error) {
206
203
  throw error;
207
204
  }
@@ -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 {}