@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,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
+ }
@@ -1,23 +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
- }
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
+ }
@@ -1,12 +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
- }
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,16 @@
1
+ import { Sequelize, SequelizeOptions } from 'sequelize-typescript';
2
+ import { MediasModel } from './entities/medias.entity';
3
+
4
+ let sequelize: Sequelize;
5
+
6
+ function init(sequelizeOptions: SequelizeOptions) {
7
+ sequelize = new Sequelize(sequelizeOptions);
8
+
9
+ sequelize.addModels([MediasModel]);
10
+ }
11
+
12
+ function getConnection() {
13
+ return sequelize;
14
+ }
15
+
16
+ export { init, getConnection };
@@ -1,125 +1,125 @@
1
- import { ApiProperty } from '@nestjs/swagger';
2
- import { Column, Model, Table, DataType } from 'sequelize-typescript';
3
- import { MediaType } from '../enum';
4
-
5
- @Table({ tableName: 'common_Media', createdAt: false, updatedAt: false })
6
- export class MediasModel extends Model {
7
- @Column({
8
- primaryKey: true,
9
- allowNull: false,
10
- })
11
- @ApiProperty({ type: String, description: 'MediaID' })
12
- MediaId: string;
13
-
14
- @Column({
15
- allowNull: false,
16
- })
17
- @ApiProperty({ type: String, description: 'ObjectID' })
18
- ObjectId: string;
19
-
20
- @Column({
21
- allowNull: false,
22
- })
23
- @ApiProperty({ type: String, description: 'ObjectType' })
24
- ObjectType: string;
25
-
26
- @Column({
27
- allowNull: true,
28
- })
29
- @ApiProperty({ type: String, description: 'title of the media' })
30
- Title: string;
31
-
32
- @Column({
33
- allowNull: true,
34
- })
35
- @ApiProperty({ type: String, description: 'Description of the media' })
36
- Description: string;
37
-
38
- @Column({
39
- allowNull: false,
40
- })
41
- @ApiProperty({
42
- type: String,
43
- description: 'Enum either Photo, Video, Document',
44
- })
45
- Type: MediaType;
46
-
47
- @Column({
48
- allowNull: false,
49
- })
50
- @ApiProperty({ type: String, description: 'isExternal either Y, N' })
51
- IsExternalYN: string;
52
-
53
- @Column({
54
- allowNull: true,
55
- })
56
- @ApiProperty({ type: String, description: 'External surce for the file' })
57
- ExternalSource: string;
58
-
59
- @Column({
60
- allowNull: false,
61
- })
62
- @ApiProperty({ type: String, description: 'isExternal either Y, N' })
63
- IsEncryptedYN: string;
64
-
65
- @Column({
66
- allowNull: true,
67
- })
68
- @ApiProperty({ type: String, description: 'file name without extension' })
69
- FileName: string;
70
-
71
- @Column({
72
- allowNull: true,
73
- })
74
- @ApiProperty({ type: String, description: 'extention of file in jpg etc' })
75
- FileExtension: string;
76
-
77
- @Column({
78
- allowNull: true,
79
- })
80
- @ApiProperty({
81
- type: String,
82
- description: 'location on the media in term of path',
83
- })
84
- FilePath: string;
85
-
86
- @Column({
87
- allowNull: true,
88
- })
89
- @ApiProperty({ type: String, description: 'URl of the media' })
90
- URL: string;
91
-
92
- @ApiProperty({
93
- example: new Date(),
94
- description: 'Timestamp for data creation.',
95
- })
96
- @Column({ type: DataType.DATE, allowNull: false })
97
- CreatedAt: Date;
98
-
99
- @ApiProperty({
100
- example: '138140891dd211b288d34bc7b4312a49',
101
- description: 'The CreatedById for Media.',
102
- })
103
- @Column({ allowNull: false })
104
- CreatedById: string;
105
-
106
- @ApiProperty({
107
- example: new Date(),
108
- description: 'Timestamp for latest data modification',
109
- })
110
- @Column({ type: DataType.DATE, allowNull: true })
111
- UpdatedAt: Date;
112
-
113
- @ApiProperty({
114
- example: '138140891dd211b288d34bc7b4312a49',
115
- description: 'The UpdatedById for Media.',
116
- })
117
- @Column({ allowNull: false })
118
- UpdatedById: string;
119
-
120
- @Column({ allowNull: true })
121
- HiddenYN: string;
122
-
123
- @Column({ allowNull: true })
124
- DefaultYN: string;
125
- }
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+ import { Column, Model, Table, DataType } from 'sequelize-typescript';
3
+ import { MediaType } from '../enum';
4
+
5
+ @Table({ tableName: 'common_Media', createdAt: false, updatedAt: false })
6
+ export class MediasModel extends Model {
7
+ @Column({
8
+ primaryKey: true,
9
+ allowNull: false,
10
+ })
11
+ @ApiProperty({ type: String, description: 'MediaID' })
12
+ MediaId: string;
13
+
14
+ @Column({
15
+ allowNull: false,
16
+ })
17
+ @ApiProperty({ type: String, description: 'ObjectID' })
18
+ ObjectId: string;
19
+
20
+ @Column({
21
+ allowNull: false,
22
+ })
23
+ @ApiProperty({ type: String, description: 'ObjectType' })
24
+ ObjectType: string;
25
+
26
+ @Column({
27
+ allowNull: true,
28
+ })
29
+ @ApiProperty({ type: String, description: 'title of the media' })
30
+ Title: string;
31
+
32
+ @Column({
33
+ allowNull: true,
34
+ })
35
+ @ApiProperty({ type: String, description: 'Description of the media' })
36
+ Description: string;
37
+
38
+ @Column({
39
+ allowNull: false,
40
+ })
41
+ @ApiProperty({
42
+ type: String,
43
+ description: 'Enum either Photo, Video, Document',
44
+ })
45
+ Type: MediaType;
46
+
47
+ @Column({
48
+ allowNull: false,
49
+ })
50
+ @ApiProperty({ type: String, description: 'isExternal either Y, N' })
51
+ IsExternalYN: string;
52
+
53
+ @Column({
54
+ allowNull: true,
55
+ })
56
+ @ApiProperty({ type: String, description: 'External surce for the file' })
57
+ ExternalSource: string;
58
+
59
+ @Column({
60
+ allowNull: false,
61
+ })
62
+ @ApiProperty({ type: String, description: 'isExternal either Y, N' })
63
+ IsEncryptedYN: string;
64
+
65
+ @Column({
66
+ allowNull: true,
67
+ })
68
+ @ApiProperty({ type: String, description: 'file name without extension' })
69
+ FileName: string;
70
+
71
+ @Column({
72
+ allowNull: true,
73
+ })
74
+ @ApiProperty({ type: String, description: 'extention of file in jpg etc' })
75
+ FileExtension: string;
76
+
77
+ @Column({
78
+ allowNull: true,
79
+ })
80
+ @ApiProperty({
81
+ type: String,
82
+ description: 'location on the media in term of path',
83
+ })
84
+ FilePath: string;
85
+
86
+ @Column({
87
+ allowNull: true,
88
+ })
89
+ @ApiProperty({ type: String, description: 'URl of the media' })
90
+ URL: string;
91
+
92
+ @ApiProperty({
93
+ example: new Date(),
94
+ description: 'Timestamp for data creation.',
95
+ })
96
+ @Column({ type: DataType.DATE, allowNull: false })
97
+ CreatedAt: Date;
98
+
99
+ @ApiProperty({
100
+ example: '138140891dd211b288d34bc7b4312a49',
101
+ description: 'The CreatedById for Media.',
102
+ })
103
+ @Column({ allowNull: false })
104
+ CreatedById: string;
105
+
106
+ @ApiProperty({
107
+ example: new Date(),
108
+ description: 'Timestamp for latest data modification',
109
+ })
110
+ @Column({ type: DataType.DATE, allowNull: true })
111
+ UpdatedAt: Date;
112
+
113
+ @ApiProperty({
114
+ example: '138140891dd211b288d34bc7b4312a49',
115
+ description: 'The UpdatedById for Media.',
116
+ })
117
+ @Column({ allowNull: false })
118
+ UpdatedById: string;
119
+
120
+ @Column({ allowNull: true })
121
+ HiddenYN: string;
122
+
123
+ @Column({ allowNull: true })
124
+ DefaultYN: string;
125
+ }
package/src/index.ts CHANGED
@@ -1,23 +1,24 @@
1
- import { MediasRepository } from "./medias.repository";
2
- import { MediasModel } from "./entities/medias.entity";
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";
11
-
1
+ import { MediasRepository } from './medias.repository';
2
+ import { MediasModel } from './entities/medias.entity';
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';
11
+ import * as MediaDb from './database';
12
12
  export {
13
- MediasRepository,
14
- MediasModel,
15
- Medias,
16
- CommonModule,
17
- CommonService,
18
- ExternalMediaDto,
19
- InternalMediaDto,
20
- MediaType,
21
- IBaseMediasAttr,
22
- IMediasRepository,
23
- }
13
+ MediasRepository,
14
+ MediasModel,
15
+ Medias,
16
+ CommonModule,
17
+ CommonService,
18
+ ExternalMediaDto,
19
+ InternalMediaDto,
20
+ MediaType,
21
+ IBaseMediasAttr,
22
+ IMediasRepository,
23
+ MediaDb,
24
+ };