Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(crud-typeorm): ignore entity decorators when saving #692

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/crud-typeorm/src/typeorm-crud.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ export class TypeOrmCrudService<T> extends CrudService<T> {
const toSave = !allowParamsOverride
? { ...found, ...dto, ...paramsFilters, ...req.parsed.authPersist }
: { ...found, ...dto, ...req.parsed.authPersist };
const updated = await this.repo.save(plainToClass(this.entityType, toSave));
const updated = await this.repo.save(
plainToClass(this.entityType, toSave, { ignoreDecorators: true }),
);

if (returnShallow) {
return updated;
Expand Down Expand Up @@ -221,7 +223,9 @@ export class TypeOrmCrudService<T> extends CrudService<T> {
...dto,
...req.parsed.authPersist,
};
const replaced = await this.repo.save(plainToClass(this.entityType, toSave));
const replaced = await this.repo.save(
plainToClass(this.entityType, toSave, { ignoreDecorators: true }),
);

if (returnShallow) {
return replaced;
Expand Down Expand Up @@ -249,7 +253,7 @@ export class TypeOrmCrudService<T> extends CrudService<T> {
const { returnDeleted } = req.options.routes.deleteOneBase;
const found = await this.getOneOrFail(req, returnDeleted);
const toReturn = returnDeleted
? plainToClass(this.entityType, { ...found })
? plainToClass(this.entityType, { ...found }, { ignoreDecorators: true })
: undefined;
const deleted =
req.options.query.softDelete === true
Expand Down Expand Up @@ -448,7 +452,11 @@ export class TypeOrmCrudService<T> extends CrudService<T> {

return dto instanceof this.entityType
? Object.assign(dto, parsed.authPersist)
: plainToClass(this.entityType, { ...dto, ...parsed.authPersist });
: plainToClass(
this.entityType,
{ ...dto, ...parsed.authPersist },
{ ignoreDecorators: true },
);
}

protected getAllowedColumns(columns: string[], options: QueryOptions): string[] {
Expand Down