Skip to content

Commit

Permalink
feature(crud): added ParsedBody decorator with validation
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelyali committed Mar 23, 2019
1 parent a0c78c9 commit dd92049
Show file tree
Hide file tree
Showing 25 changed files with 273 additions and 49 deletions.
39 changes: 34 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -814,17 +814,17 @@ getOneBase(

createOneBase(
@ParsedParams() params: FilterParamParsed[],
@Body() dto: T,
@ParsedBody() dto: T,
): Promise<T>;

createManyBase(
@ParsedParams() params: FilterParamParsed[],
@Body() dto: EntitiesBulk<T>,
@ParsedBody() dto: EntitiesBulk<T>,
): Promise<T[]>;

updateOneBase(
@ParsedParams() params: FilterParamParsed[]
@Body() dto: T,
@ParsedBody() dto: T,
): Promise<T>;

deleteOneBase(
Expand Down Expand Up @@ -876,12 +876,41 @@ export class HeroesCrud {
// do some stuff
}

...
@Override()
createOne(
@ParsedParams() params,
@ParsedBody() body: Hero,
) {
return this.base.createOneBase(params, body);
}

@Override()
createMany(
@ParsedBody() body: EntitiesBulk<Hero>, // validation is working ^_^
@ParsedParams() params,
) {
return this.base.createManyBase(params, body);
}

@Override('updateOneBase')
coolFunction() {
@ParsedParams() params,
@ParsedBody() body: Hero,
} {
return this.base.updateOneBase(params, body);
}

@Override()
async deleteOne(
@ParsedParams() params,
) {
return this.base.deleteOneBase(params);
}

}
```

**_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.
**_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.

### Additional Decorators

Expand Down
39 changes: 34 additions & 5 deletions dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -814,17 +814,17 @@ getOneBase(

createOneBase(
@ParsedParams() params: FilterParamParsed[],
@Body() dto: T,
@ParsedBody() dto: T,
): Promise<T>;

createManyBase(
@ParsedParams() params: FilterParamParsed[],
@Body() dto: EntitiesBulk<T>,
@ParsedBody() dto: EntitiesBulk<T>,
): Promise<T[]>;

updateOneBase(
@ParsedParams() params: FilterParamParsed[]
@Body() dto: T,
@ParsedBody() dto: T,
): Promise<T>;

deleteOneBase(
Expand Down Expand Up @@ -876,12 +876,41 @@ export class HeroesCrud {
// do some stuff
}

...
@Override()
createOne(
@ParsedParams() params,
@ParsedBody() body: Hero,
) {
return this.base.createOneBase(params, body);
}

@Override()
createMany(
@ParsedBody() body: EntitiesBulk<Hero>, // validation is working ^_^
@ParsedParams() params,
) {
return this.base.createManyBase(params, body);
}

@Override('updateOneBase')
coolFunction() {
@ParsedParams() params,
@ParsedBody() body: Hero,
} {
return this.base.updateOneBase(params, body);
}

@Override()
async deleteOne(
@ParsedParams() params,
) {
return this.base.deleteOneBase(params);
}

}
```

**_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.
**_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.

### Additional Decorators

Expand Down
1 change: 1 addition & 0 deletions dist/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export declare const OVERRIDE_METHOD_METADATA = "NESTJSX_OVERRIDE_METHOD_METADAT
export declare const PARSED_QUERY_REQUEST_KEY = "NESTJSX_PARSED_QUERY_REQUEST_KEY";
export declare const PARSED_PARAMS_REQUEST_KEY = "NESTJSX_PARSED_PARAMS_REQUEST_KEY";
export declare const PARSED_OPTIONS_METADATA = "NESTJSX_PARSED_OPTIONS_METADATA";
export declare const PARSED_BODY_METADATA = "NESTJSX_PARSED_BODY_METADATA";
export declare const CREATE_UPDATE: {
groups: string[];
};
Expand Down
1 change: 1 addition & 0 deletions dist/constants.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/constants.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions dist/decorators/crud.decorator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dd92049

Please sign in to comment.