Skip to content

Commit dd92049

Browse files
committed
feature(crud): added ParsedBody decorator with validation
1 parent a0c78c9 commit dd92049

25 files changed

+273
-49
lines changed

README.md

+34-5
Original file line numberDiff line numberDiff line change
@@ -814,17 +814,17 @@ getOneBase(
814814

815815
createOneBase(
816816
@ParsedParams() params: FilterParamParsed[],
817-
@Body() dto: T,
817+
@ParsedBody() dto: T,
818818
): Promise<T>;
819819

820820
createManyBase(
821821
@ParsedParams() params: FilterParamParsed[],
822-
@Body() dto: EntitiesBulk<T>,
822+
@ParsedBody() dto: EntitiesBulk<T>,
823823
): Promise<T[]>;
824824

825825
updateOneBase(
826826
@ParsedParams() params: FilterParamParsed[]
827-
@Body() dto: T,
827+
@ParsedBody() dto: T,
828828
): Promise<T>;
829829

830830
deleteOneBase(
@@ -876,12 +876,41 @@ export class HeroesCrud {
876876
// do some stuff
877877
}
878878

879-
...
879+
@Override()
880+
createOne(
881+
@ParsedParams() params,
882+
@ParsedBody() body: Hero,
883+
) {
884+
return this.base.createOneBase(params, body);
885+
}
886+
887+
@Override()
888+
createMany(
889+
@ParsedBody() body: EntitiesBulk<Hero>, // validation is working ^_^
890+
@ParsedParams() params,
891+
) {
892+
return this.base.createManyBase(params, body);
893+
}
894+
895+
@Override('updateOneBase')
896+
coolFunction() {
897+
@ParsedParams() params,
898+
@ParsedBody() body: Hero,
899+
} {
900+
return this.base.updateOneBase(params, body);
901+
}
902+
903+
@Override()
904+
async deleteOne(
905+
@ParsedParams() params,
906+
) {
907+
return this.base.deleteOneBase(params);
908+
}
880909

881910
}
882911
```
883912

884-
**_Notice:_** new custom route decorators were created to simplify process: `@ParsedQuery()`, `@ParsedParams`, and `@ParsedOptions()`. But you still can add your param decorators to any of the methods, e.g. `@Param()`, `@Session()`, etc. Or any of your own cutom route decorators.
913+
**_Notice:_** new custom route decorators were created to simplify process: `@ParsedQuery()`, `@ParsedParams`, `@ParsedBody()`, and`@ParsedOptions()`. But you still can add your param decorators to any of the methods, e.g. `@Param()`, `@Session()`, etc. Or any of your own cutom route decorators.
885914

886915
### Additional Decorators
887916

dist/README.md

+34-5
Original file line numberDiff line numberDiff line change
@@ -814,17 +814,17 @@ getOneBase(
814814

815815
createOneBase(
816816
@ParsedParams() params: FilterParamParsed[],
817-
@Body() dto: T,
817+
@ParsedBody() dto: T,
818818
): Promise<T>;
819819

820820
createManyBase(
821821
@ParsedParams() params: FilterParamParsed[],
822-
@Body() dto: EntitiesBulk<T>,
822+
@ParsedBody() dto: EntitiesBulk<T>,
823823
): Promise<T[]>;
824824

825825
updateOneBase(
826826
@ParsedParams() params: FilterParamParsed[]
827-
@Body() dto: T,
827+
@ParsedBody() dto: T,
828828
): Promise<T>;
829829

830830
deleteOneBase(
@@ -876,12 +876,41 @@ export class HeroesCrud {
876876
// do some stuff
877877
}
878878

879-
...
879+
@Override()
880+
createOne(
881+
@ParsedParams() params,
882+
@ParsedBody() body: Hero,
883+
) {
884+
return this.base.createOneBase(params, body);
885+
}
886+
887+
@Override()
888+
createMany(
889+
@ParsedBody() body: EntitiesBulk<Hero>, // validation is working ^_^
890+
@ParsedParams() params,
891+
) {
892+
return this.base.createManyBase(params, body);
893+
}
894+
895+
@Override('updateOneBase')
896+
coolFunction() {
897+
@ParsedParams() params,
898+
@ParsedBody() body: Hero,
899+
} {
900+
return this.base.updateOneBase(params, body);
901+
}
902+
903+
@Override()
904+
async deleteOne(
905+
@ParsedParams() params,
906+
) {
907+
return this.base.deleteOneBase(params);
908+
}
880909

881910
}
882911
```
883912

884-
**_Notice:_** new custom route decorators were created to simplify process: `@ParsedQuery()`, `@ParsedParams`, and `@ParsedOptions()`. But you still can add your param decorators to any of the methods, e.g. `@Param()`, `@Session()`, etc. Or any of your own cutom route decorators.
913+
**_Notice:_** new custom route decorators were created to simplify process: `@ParsedQuery()`, `@ParsedParams`, `@ParsedBody()`, and`@ParsedOptions()`. But you still can add your param decorators to any of the methods, e.g. `@Param()`, `@Session()`, etc. Or any of your own cutom route decorators.
885914

886915
### Additional Decorators
887916

dist/constants.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export declare const OVERRIDE_METHOD_METADATA = "NESTJSX_OVERRIDE_METHOD_METADAT
44
export declare const PARSED_QUERY_REQUEST_KEY = "NESTJSX_PARSED_QUERY_REQUEST_KEY";
55
export declare const PARSED_PARAMS_REQUEST_KEY = "NESTJSX_PARSED_PARAMS_REQUEST_KEY";
66
export declare const PARSED_OPTIONS_METADATA = "NESTJSX_PARSED_OPTIONS_METADATA";
7+
export declare const PARSED_BODY_METADATA = "NESTJSX_PARSED_BODY_METADATA";
78
export declare const CREATE_UPDATE: {
89
groups: string[];
910
};

dist/constants.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/constants.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/decorators/crud.decorator.js

+8-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)