question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CRUD service updateOne doesn't handle serialization groups

See original GitHub issue

Hello, I am having problems trying to PATCH an entity. This entity has fields that are exposed only to some serialization groups.

The problem is that these fields cannot be updated, because this call seems to ignore serialization groups:

const updated = await this.repo.save(plainToClass(this.entityType, toSave)); https://github.com/nestjsx/crud/blob/master/packages/crud-typeorm/src/typeorm-crud.service.ts#L180

The field enabled that I am trying to update is present in the toSave var before the plainToClass call.

This is an excerpt of my entity:

@Entity()
export class User extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number

  @Column({ unique: true })
  username: string

  @Column({
    default: true,
  })
  @Expose({ groups: [ADMIN] })
  enabled: boolean
}

And the relevant part of my controller:

@Crud({
  model: {
    type: User,
  },
  validation: { transform: true },
  query: {
    alwaysPaginate: true,
    limit: 20,
    maxLimit: 100,
  },
  routes: {
    updateOneBase: {
      decorators: [SerializeOptions({ groups: [ADMIN] })],
    },
  },
})
@Controller('users')
@UseInterceptors(ClassSerializerInterceptor)
export class UsersController implements CrudController<User> {

What am I doing wrong? I need the enabled field to be returned only on endpoints that have the ADMIN serialization group, but the serialization call on updateOne seems to ignore groups.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

6reactions
herenicknamecommented, Dec 9, 2020

Up.

3reactions
malchegcommented, Nov 28, 2020

I believe the problem lays in the interceptor implementation: https://github.com/nestjsx/crud/blob/5b02704ac0254fc362bcdff784387959211fc6c2/packages/crud/src/interceptors/crud-response.interceptor.ts#L45

As you may see the interceptor doesn’t apply any options to the classToPlain method. Unfortunately, I didn’t find a way to provide a custom global interceptor via DI. Hope it’s going to be fixed soon. The framework looks really good, but the issue is blocking me from introducing the framework to an existing project where serialization groups are crucial.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CRUD service updateOne doesn't handle serialization groups
Hello, I am having problems trying to PATCH an entity. This entity has fields that are exposed only to some serialization groups. The...
Read more >
Building a CRUD App with FastAPI and MongoDB
This tutorial looks at how to develop an asynchronous API with FastAPI and MongoDB.
Read more >
A Step by Step guide to create Reactive CRUD RESTful APIs ...
A detailed step by step guide to create Reactive CRUD RESTful APIs using Spring Boot + Spring Data R2DBC with H2 in-memory database....
Read more >
Create a RESTful API with .NET Core and MongoDB
This brings us to our final part of the CRUD spectrum. We're going to handle deleting of data. In the "Services/MongoDBService.cs" file, add...
Read more >
Changelog — PyMongo 4.3.3 documentation - Read the Docs
Added support for the let parameter to update_one() , update_many() ... PyMongo 3's new CRUD API does not apply SON manipulators to documents...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found