@steroidsjs/nest 1.1.5 → 1.1.6
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/infrastructure/helpers/ModuleHelper.d.ts +3 -0
- package/infrastructure/helpers/ModuleHelper.js +25 -0
- package/infrastructure/helpers/ModuleHelper.js.map +1 -0
- package/infrastructure/repositories/CrudRepository.d.ts +7 -3
- package/infrastructure/repositories/CrudRepository.js +57 -8
- package/infrastructure/repositories/CrudRepository.js.map +1 -1
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/usecases/interfaces/ICrudRepository.d.ts +3 -3
- package/usecases/services/CrudService.d.ts +5 -1
- package/usecases/services/CrudService.js +30 -4
- package/usecases/services/CrudService.js.map +1 -1
|
@@ -9,7 +9,7 @@ export interface ICrudRepository<TModel> {
|
|
|
9
9
|
search: <TItem>(dto: SearchInputDto, searchQuery: SearchQuery) => Promise<SearchResultDto<TModel | Type<TItem>>>;
|
|
10
10
|
findOne: (conditionOrQuery: ICondition | SearchQuery) => Promise<TModel | null>;
|
|
11
11
|
findMany: (conditionOrQuery: ICondition | SearchQuery) => Promise<TModel[]>;
|
|
12
|
-
create: (model: TModel) => Promise<TModel>;
|
|
13
|
-
update: (id: number, model: TModel) => Promise<TModel>;
|
|
14
|
-
remove: (id: number) => Promise<void>;
|
|
12
|
+
create: (model: TModel, transactionHandler?: (callback: any) => Promise<void>) => Promise<TModel>;
|
|
13
|
+
update: (id: number, model: TModel, transactionHandler?: (callback: any) => Promise<void>) => Promise<TModel>;
|
|
14
|
+
remove: (id: number, transactionHandler?: (callback: any) => Promise<void>) => Promise<void>;
|
|
15
15
|
}
|
|
@@ -19,7 +19,11 @@ export declare class CrudService<TModel, TSearchDto = ISearchInputDto, TSaveDto
|
|
|
19
19
|
create<TSchema>(dto: TSaveDto, context?: ContextDto | null, schemaClass?: Type<TSchema>): Promise<Type<TSchema>>;
|
|
20
20
|
update<TSchema>(id: number | string, dto: TSaveDto, context?: ContextDto | null): Promise<TModel>;
|
|
21
21
|
update<TSchema>(id: number | string, dto: TSaveDto, context?: ContextDto | null, schemaClass?: Type<TSchema>): Promise<Type<TSchema>>;
|
|
22
|
-
remove(
|
|
22
|
+
remove(rawId: number | string, context?: ContextDto): Promise<void>;
|
|
23
|
+
protected beforeSave(prevModel: TModel | null, nextModel: TModel): Promise<void>;
|
|
24
|
+
protected afterSave(prevModel: TModel | null, nextModel: TModel): Promise<void>;
|
|
25
|
+
protected beforeDelete(id: number): Promise<void>;
|
|
26
|
+
protected afterDelete(id: number): Promise<void>;
|
|
23
27
|
protected modelToSchema<TSchema>(model: TModel, schemaClass: Type<TSchema>): Type<TSchema>;
|
|
24
28
|
protected dtoToModel(dto: TSaveDto): Promise<TModel>;
|
|
25
29
|
}
|
|
@@ -35,16 +35,42 @@ class CrudService {
|
|
|
35
35
|
}
|
|
36
36
|
async create(dto, context = null, schemaClass = null) {
|
|
37
37
|
await (0, ValidationHelper_1.validateOrReject)(dto);
|
|
38
|
-
const
|
|
38
|
+
const nextModel = await this.dtoToModel(dto);
|
|
39
|
+
let model;
|
|
40
|
+
await this.repository.create(nextModel, async (save) => {
|
|
41
|
+
await this.beforeSave(null, nextModel);
|
|
42
|
+
model = await save();
|
|
43
|
+
await this.afterSave(null, model);
|
|
44
|
+
});
|
|
39
45
|
return schemaClass ? this.findById(model[this.primaryKey], context, schemaClass) : model;
|
|
40
46
|
}
|
|
41
47
|
async update(id, dto, context = null, schemaClass = null) {
|
|
42
48
|
await (0, ValidationHelper_1.validateOrReject)(dto);
|
|
43
|
-
const
|
|
49
|
+
const prevModel = await this.findById(id);
|
|
50
|
+
const nextModel = await this.dtoToModel(dto);
|
|
51
|
+
let model;
|
|
52
|
+
await this.repository.update((0, lodash_1.toInteger)(id), nextModel, async (save) => {
|
|
53
|
+
await this.beforeSave(prevModel, nextModel);
|
|
54
|
+
model = await save();
|
|
55
|
+
await this.afterSave(prevModel, model);
|
|
56
|
+
});
|
|
44
57
|
return schemaClass ? this.findById(id, context, schemaClass) : model;
|
|
45
58
|
}
|
|
46
|
-
async remove(
|
|
47
|
-
|
|
59
|
+
async remove(rawId, context = null) {
|
|
60
|
+
const id = (0, lodash_1.toInteger)(rawId);
|
|
61
|
+
await this.repository.remove(id, async (remove) => {
|
|
62
|
+
await this.beforeDelete(id);
|
|
63
|
+
await remove();
|
|
64
|
+
await this.afterDelete(id);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
async beforeSave(prevModel, nextModel) {
|
|
68
|
+
}
|
|
69
|
+
async afterSave(prevModel, nextModel) {
|
|
70
|
+
}
|
|
71
|
+
async beforeDelete(id) {
|
|
72
|
+
}
|
|
73
|
+
async afterDelete(id) {
|
|
48
74
|
}
|
|
49
75
|
modelToSchema(model, schemaClass) {
|
|
50
76
|
return DataMapperHelper_1.DataMapperHelper.anyToSchema(model, schemaClass);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CrudService.js","sourceRoot":"","sources":["../../../src/usecases/services/CrudService.ts"],"names":[],"mappings":";;;AACA,mCAA+C;AAE/C,kEAA6D;AAG7D,kEAA6D;AAC7D,qDAA8C;AAM9C,MAAa,WAAW;IAAxB;QAMc,eAAU,GAAW,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"CrudService.js","sourceRoot":"","sources":["../../../src/usecases/services/CrudService.ts"],"names":[],"mappings":";;;AACA,mCAA+C;AAE/C,kEAA6D;AAG7D,kEAA6D;AAC7D,qDAA8C;AAM9C,MAAa,WAAW;IAAxB;QAMc,eAAU,GAAW,IAAI,CAAC;IAoOxC,CAAC;IAtNG,IAAI,CAAC,UAAmC,EAAE,UAAU;QAChD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAeD,KAAK,CAAC,MAAM,CACR,GAAe,EACf,UAAsB,IAAI,EAC1B,cAA6B,IAAI;QAEjC,MAAM,IAAA,m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