@tomei/media 0.8.8 → 0.8.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.
- package/package.json +1 -1
- package/src/base/base.medias.ts +210 -210
- package/src/base/base.repository.abstract.ts +28 -28
- package/src/base/base.repository.interface.ts +9 -9
- package/src/common/common.module.ts +10 -10
- package/src/common/common.service.ts +107 -107
- package/src/common/dto/add-field-translation.dto.ts +23 -23
- package/src/common/dto/get-media.dto.ts +12 -12
- package/src/database.ts +16 -16
- package/src/dto/external-media.dto.ts +49 -49
- package/src/dto/internal-medias.dto.ts +64 -64
- package/src/entities/medias.entity.ts +125 -125
- package/src/enum/index.ts +3 -3
- package/src/enum/medias.enum.ts +5 -5
- package/src/helpers/error.ts +12 -12
- package/src/helpers/index.ts +3 -3
- package/src/index.ts +24 -24
- package/src/interfaces/base.medias-attr.interface.ts +21 -21
- package/src/interfaces/medias.repository.interface.ts +4 -4
- package/src/medias.repository.ts +55 -55
- package/src/medias.ts +769 -769
- package/src/pipe/append-id.pipe.ts +15 -15
- package/src/pipe/validate-enum.pipe.ts +31 -31
- package/src/pipe/validate-id.pipe.ts +18 -18
- package/src/pipe/validate-search.pipe.ts +44 -44
- package/src/responses/deleted.response.ts +6 -6
- package/src/responses/pagination.response.ts +10 -10
- package/dist/base/base.medias.d.ts +0 -38
- package/dist/base/base.medias.js +0 -175
- package/dist/base/base.medias.js.map +0 -1
- package/dist/base/base.repository.abstract.d.ts +0 -12
- package/dist/base/base.repository.abstract.js +0 -22
- package/dist/base/base.repository.abstract.js.map +0 -1
- package/dist/base/base.repository.interface.d.ts +0 -9
- package/dist/base/base.repository.interface.js +0 -3
- package/dist/base/base.repository.interface.js.map +0 -1
- package/dist/common/common.module.d.ts +0 -2
- package/dist/common/common.module.js +0 -23
- package/dist/common/common.module.js.map +0 -1
- package/dist/common/common.service.d.ts +0 -13
- package/dist/common/common.service.js +0 -106
- package/dist/common/common.service.js.map +0 -1
- package/dist/common/dto/add-field-translation.dto.d.ts +0 -7
- package/dist/common/dto/add-field-translation.dto.js +0 -42
- package/dist/common/dto/add-field-translation.dto.js.map +0 -1
- package/dist/common/dto/get-media.dto.d.ts +0 -5
- package/dist/common/dto/get-media.dto.js +0 -29
- package/dist/common/dto/get-media.dto.js.map +0 -1
- package/dist/database.d.ts +0 -4
- package/dist/database.js +0 -16
- package/dist/database.js.map +0 -1
- package/dist/dto/external-media.dto.d.ts +0 -10
- package/dist/dto/external-media.dto.js +0 -70
- package/dist/dto/external-media.dto.js.map +0 -1
- package/dist/dto/internal-medias.dto.d.ts +0 -12
- package/dist/dto/internal-medias.dto.js +0 -87
- package/dist/dto/internal-medias.dto.js.map +0 -1
- package/dist/entities/medias.entity.d.ts +0 -23
- package/dist/entities/medias.entity.js +0 -160
- package/dist/entities/medias.entity.js.map +0 -1
- package/dist/enum/index.d.ts +0 -2
- package/dist/enum/index.js +0 -6
- package/dist/enum/index.js.map +0 -1
- package/dist/enum/medias.enum.d.ts +0 -5
- package/dist/enum/medias.enum.js +0 -10
- package/dist/enum/medias.enum.js.map +0 -1
- package/dist/helpers/error.d.ts +0 -1
- package/dist/helpers/error.js +0 -13
- package/dist/helpers/error.js.map +0 -1
- package/dist/helpers/index.d.ts +0 -2
- package/dist/helpers/index.js +0 -6
- package/dist/helpers/index.js.map +0 -1
- package/dist/index.d.ts +0 -12
- package/dist/index.js +0 -22
- package/dist/index.js.map +0 -1
- package/dist/interfaces/base.medias-attr.interface.d.ts +0 -20
- package/dist/interfaces/base.medias-attr.interface.js +0 -3
- package/dist/interfaces/base.medias-attr.interface.js.map +0 -1
- package/dist/interfaces/medias.repository.interface.d.ts +0 -3
- package/dist/interfaces/medias.repository.interface.js +0 -3
- package/dist/interfaces/medias.repository.interface.js.map +0 -1
- package/dist/medias.d.ts +0 -65
- package/dist/medias.js +0 -564
- package/dist/medias.js.map +0 -1
- package/dist/medias.repository.d.ts +0 -8
- package/dist/medias.repository.js +0 -56
- package/dist/medias.repository.js.map +0 -1
- package/dist/pipe/append-id.pipe.d.ts +0 -6
- package/dist/pipe/append-id.pipe.js +0 -28
- package/dist/pipe/append-id.pipe.js.map +0 -1
- package/dist/pipe/validate-enum.pipe.d.ts +0 -6
- package/dist/pipe/validate-enum.pipe.js +0 -34
- package/dist/pipe/validate-enum.pipe.js.map +0 -1
- package/dist/pipe/validate-id.pipe.d.ts +0 -6
- package/dist/pipe/validate-id.pipe.js +0 -31
- package/dist/pipe/validate-id.pipe.js.map +0 -1
- package/dist/pipe/validate-search.pipe.d.ts +0 -7
- package/dist/pipe/validate-search.pipe.js +0 -46
- package/dist/pipe/validate-search.pipe.js.map +0 -1
- package/dist/responses/deleted.response.d.ts +0 -3
- package/dist/responses/deleted.response.js +0 -21
- package/dist/responses/deleted.response.js.map +0 -1
- package/dist/responses/pagination.response.d.ts +0 -5
- package/dist/responses/pagination.response.js +0 -26
- package/dist/responses/pagination.response.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/package.json
CHANGED
package/src/base/base.medias.ts
CHANGED
|
@@ -1,210 +1,210 @@
|
|
|
1
|
-
import { MediaType } from '../enum/medias.enum';
|
|
2
|
-
import * as cuid from 'cuid';
|
|
3
|
-
import { BadRequestException } from '@nestjs/common';
|
|
4
|
-
import { MediasModel } from '../entities/medias.entity';
|
|
5
|
-
import { IBaseMediasAttr } from '../interfaces/base.medias-attr.interface';
|
|
6
|
-
import { MediasRepository } from '../medias.repository';
|
|
7
|
-
import { ObjectBase } from '@tomei/general';
|
|
8
|
-
|
|
9
|
-
export abstract class BaseMedias extends ObjectBase {
|
|
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
|
-
container: string;
|
|
28
|
-
|
|
29
|
-
private static mediasRepository = new MediasRepository();
|
|
30
|
-
|
|
31
|
-
protected constructor(media?: IBaseMediasAttr) {
|
|
32
|
-
super();
|
|
33
|
-
if (media) {
|
|
34
|
-
this.init(media);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
init(media: IBaseMediasAttr) {
|
|
39
|
-
this.MediaId = media.MediaId ? media.MediaId : cuid();
|
|
40
|
-
this.ObjectId = media.ObjectId;
|
|
41
|
-
this.ObjectType = media.ObjectType;
|
|
42
|
-
this.Title = media.Title;
|
|
43
|
-
this.Description = media.Description;
|
|
44
|
-
this.Type = media.Type;
|
|
45
|
-
this.IsExternalYN = media.IsExternalYN;
|
|
46
|
-
this.ExternalSource = media.ExternalSource;
|
|
47
|
-
this.IsEncryptedYN = media.IsEncryptedYN;
|
|
48
|
-
this.FileName = media.FileName;
|
|
49
|
-
this.FileExtension = media.FileExtension;
|
|
50
|
-
this.URL =
|
|
51
|
-
media.URL && media.URL.includes('media')
|
|
52
|
-
? media.URL
|
|
53
|
-
: this.createSaveLocation();
|
|
54
|
-
this.FilePath =
|
|
55
|
-
media.FilePath && media.IsExternalYN === 'Y'
|
|
56
|
-
? media.FilePath
|
|
57
|
-
: this.createFilePath();
|
|
58
|
-
this.CreatedById = media.CreatedById;
|
|
59
|
-
this.CreatedAt = media.CreatedAt;
|
|
60
|
-
this.UpdatedById = media.UpdatedById;
|
|
61
|
-
this.UpdatedAt = media.UpdatedAt;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
createSaveLocation(): string {
|
|
65
|
-
try {
|
|
66
|
-
const mediaFileStorageType = process.env.MEDIA_STORAGE_TYPE;
|
|
67
|
-
let basePath: string;
|
|
68
|
-
if (mediaFileStorageType === 'local') {
|
|
69
|
-
basePath = process.env.MEDIA_LOCAL_STORAGE_PATH;
|
|
70
|
-
} else {
|
|
71
|
-
basePath = process.env.MEDIA_AZUREBLOB_CONTAINER_NAME;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (!basePath) {
|
|
75
|
-
throw new BadRequestException(
|
|
76
|
-
'MEDIA_LOCAL_STORAGE_PATH and or MEDIA_AZUREBLOB_CONTAINER_NAME not found.',
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
return basePath + `/${this.ObjectType}/${this.ObjectId}`;
|
|
80
|
-
} catch (error) {
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
createFilePath(): string {
|
|
86
|
-
try {
|
|
87
|
-
const fileLocation = this.createSaveLocation();
|
|
88
|
-
return `${fileLocation}/${this.FileName}.${this.FileExtension}`;
|
|
89
|
-
} catch (error) {
|
|
90
|
-
throw error;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async create(options?: any): Promise<MediasModel> {
|
|
95
|
-
try {
|
|
96
|
-
return BaseMedias.mediasRepository.create(
|
|
97
|
-
{
|
|
98
|
-
MediaId: this.MediaId,
|
|
99
|
-
ObjectId: this.ObjectId,
|
|
100
|
-
ObjectType: this.ObjectType,
|
|
101
|
-
Title: this.Title,
|
|
102
|
-
Description: this.Description,
|
|
103
|
-
Type: this.Type,
|
|
104
|
-
IsExternalYN: this.IsExternalYN,
|
|
105
|
-
ExternalSource: this.ExternalSource,
|
|
106
|
-
IsEncryptedYN: this.IsEncryptedYN,
|
|
107
|
-
FileName: this.FileName,
|
|
108
|
-
FileExtension: this.FileExtension,
|
|
109
|
-
FilePath: this.FilePath,
|
|
110
|
-
URL: this.URL,
|
|
111
|
-
CreatedById: this.CreatedById,
|
|
112
|
-
CreatedAt: this.CreatedAt,
|
|
113
|
-
UpdatedById: this.UpdatedById,
|
|
114
|
-
UpdatedAt: this.UpdatedAt,
|
|
115
|
-
},
|
|
116
|
-
options,
|
|
117
|
-
);
|
|
118
|
-
} catch (error) {
|
|
119
|
-
throw error;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async update(options?: any): Promise<MediasModel | any> {
|
|
124
|
-
try {
|
|
125
|
-
const media = await BaseMedias.mediasRepository.findOne({
|
|
126
|
-
where: {
|
|
127
|
-
MediaId: this.MediaId,
|
|
128
|
-
},
|
|
129
|
-
options,
|
|
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 BaseMedias.mediasRepository.findOne({
|
|
165
|
-
where: {
|
|
166
|
-
MediaId: this.MediaId,
|
|
167
|
-
},
|
|
168
|
-
options,
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
const data = {
|
|
172
|
-
...media.get({ plain: true }),
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
if (!media) {
|
|
176
|
-
throw new BadRequestException('Media not found.');
|
|
177
|
-
}
|
|
178
|
-
await media.destroy(options);
|
|
179
|
-
return data;
|
|
180
|
-
} catch (error) {
|
|
181
|
-
throw error;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
async findAll(options?: any): Promise<MediasModel[]> {
|
|
186
|
-
try {
|
|
187
|
-
return BaseMedias.mediasRepository.findAll(options);
|
|
188
|
-
} catch (error) {
|
|
189
|
-
throw error;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async findAllWithPagination(
|
|
194
|
-
options?: any,
|
|
195
|
-
): Promise<{ count: number; rows: MediasModel[] }> {
|
|
196
|
-
try {
|
|
197
|
-
return BaseMedias.mediasRepository.findAndCountAll(options);
|
|
198
|
-
} catch (error) {
|
|
199
|
-
throw error;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
async findOne(options?: any): Promise<MediasModel> {
|
|
204
|
-
try {
|
|
205
|
-
return BaseMedias.mediasRepository.findOne(options);
|
|
206
|
-
} catch (error) {
|
|
207
|
-
throw error;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
1
|
+
import { MediaType } from '../enum/medias.enum';
|
|
2
|
+
import * as cuid from 'cuid';
|
|
3
|
+
import { BadRequestException } from '@nestjs/common';
|
|
4
|
+
import { MediasModel } from '../entities/medias.entity';
|
|
5
|
+
import { IBaseMediasAttr } from '../interfaces/base.medias-attr.interface';
|
|
6
|
+
import { MediasRepository } from '../medias.repository';
|
|
7
|
+
import { ObjectBase } from '@tomei/general';
|
|
8
|
+
|
|
9
|
+
export abstract class BaseMedias extends ObjectBase {
|
|
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
|
+
container: string;
|
|
28
|
+
|
|
29
|
+
private static mediasRepository = new MediasRepository();
|
|
30
|
+
|
|
31
|
+
protected constructor(media?: IBaseMediasAttr) {
|
|
32
|
+
super();
|
|
33
|
+
if (media) {
|
|
34
|
+
this.init(media);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
init(media: IBaseMediasAttr) {
|
|
39
|
+
this.MediaId = media.MediaId ? media.MediaId : cuid();
|
|
40
|
+
this.ObjectId = media.ObjectId;
|
|
41
|
+
this.ObjectType = media.ObjectType;
|
|
42
|
+
this.Title = media.Title;
|
|
43
|
+
this.Description = media.Description;
|
|
44
|
+
this.Type = media.Type;
|
|
45
|
+
this.IsExternalYN = media.IsExternalYN;
|
|
46
|
+
this.ExternalSource = media.ExternalSource;
|
|
47
|
+
this.IsEncryptedYN = media.IsEncryptedYN;
|
|
48
|
+
this.FileName = media.FileName;
|
|
49
|
+
this.FileExtension = media.FileExtension;
|
|
50
|
+
this.URL =
|
|
51
|
+
media.URL && media.URL.includes('media')
|
|
52
|
+
? media.URL
|
|
53
|
+
: this.createSaveLocation();
|
|
54
|
+
this.FilePath =
|
|
55
|
+
media.FilePath && media.IsExternalYN === 'Y'
|
|
56
|
+
? media.FilePath
|
|
57
|
+
: this.createFilePath();
|
|
58
|
+
this.CreatedById = media.CreatedById;
|
|
59
|
+
this.CreatedAt = media.CreatedAt;
|
|
60
|
+
this.UpdatedById = media.UpdatedById;
|
|
61
|
+
this.UpdatedAt = media.UpdatedAt;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
createSaveLocation(): string {
|
|
65
|
+
try {
|
|
66
|
+
const mediaFileStorageType = process.env.MEDIA_STORAGE_TYPE;
|
|
67
|
+
let basePath: string;
|
|
68
|
+
if (mediaFileStorageType === 'local') {
|
|
69
|
+
basePath = process.env.MEDIA_LOCAL_STORAGE_PATH;
|
|
70
|
+
} else {
|
|
71
|
+
basePath = process.env.MEDIA_AZUREBLOB_CONTAINER_NAME;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!basePath) {
|
|
75
|
+
throw new BadRequestException(
|
|
76
|
+
'MEDIA_LOCAL_STORAGE_PATH and or MEDIA_AZUREBLOB_CONTAINER_NAME not found.',
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return basePath + `/${this.ObjectType}/${this.ObjectId}`;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
createFilePath(): string {
|
|
86
|
+
try {
|
|
87
|
+
const fileLocation = this.createSaveLocation();
|
|
88
|
+
return `${fileLocation}/${this.FileName}.${this.FileExtension}`;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async create(options?: any): Promise<MediasModel> {
|
|
95
|
+
try {
|
|
96
|
+
return BaseMedias.mediasRepository.create(
|
|
97
|
+
{
|
|
98
|
+
MediaId: this.MediaId,
|
|
99
|
+
ObjectId: this.ObjectId,
|
|
100
|
+
ObjectType: this.ObjectType,
|
|
101
|
+
Title: this.Title,
|
|
102
|
+
Description: this.Description,
|
|
103
|
+
Type: this.Type,
|
|
104
|
+
IsExternalYN: this.IsExternalYN,
|
|
105
|
+
ExternalSource: this.ExternalSource,
|
|
106
|
+
IsEncryptedYN: this.IsEncryptedYN,
|
|
107
|
+
FileName: this.FileName,
|
|
108
|
+
FileExtension: this.FileExtension,
|
|
109
|
+
FilePath: this.FilePath,
|
|
110
|
+
URL: this.URL,
|
|
111
|
+
CreatedById: this.CreatedById,
|
|
112
|
+
CreatedAt: this.CreatedAt,
|
|
113
|
+
UpdatedById: this.UpdatedById,
|
|
114
|
+
UpdatedAt: this.UpdatedAt,
|
|
115
|
+
},
|
|
116
|
+
options,
|
|
117
|
+
);
|
|
118
|
+
} catch (error) {
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async update(options?: any): Promise<MediasModel | any> {
|
|
124
|
+
try {
|
|
125
|
+
const media = await BaseMedias.mediasRepository.findOne({
|
|
126
|
+
where: {
|
|
127
|
+
MediaId: this.MediaId,
|
|
128
|
+
},
|
|
129
|
+
options,
|
|
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 BaseMedias.mediasRepository.findOne({
|
|
165
|
+
where: {
|
|
166
|
+
MediaId: this.MediaId,
|
|
167
|
+
},
|
|
168
|
+
options,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const data = {
|
|
172
|
+
...media.get({ plain: true }),
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
if (!media) {
|
|
176
|
+
throw new BadRequestException('Media not found.');
|
|
177
|
+
}
|
|
178
|
+
await media.destroy(options);
|
|
179
|
+
return data;
|
|
180
|
+
} catch (error) {
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async findAll(options?: any): Promise<MediasModel[]> {
|
|
186
|
+
try {
|
|
187
|
+
return BaseMedias.mediasRepository.findAll(options);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async findAllWithPagination(
|
|
194
|
+
options?: any,
|
|
195
|
+
): Promise<{ count: number; rows: MediasModel[] }> {
|
|
196
|
+
try {
|
|
197
|
+
return BaseMedias.mediasRepository.findAndCountAll(options);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async findOne(options?: any): Promise<MediasModel> {
|
|
204
|
+
try {
|
|
205
|
+
return BaseMedias.mediasRepository.findOne(options);
|
|
206
|
+
} catch (error) {
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -1,28 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,9 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -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 {}
|