Skip to content

Remove unused fields from API Responses #187

@chavda-bhavik

Description

@chavda-bhavik

Is your feature request related to a problem? Please describe.
It seems obvious that the createdAt, updatedAt, and __v fields are not used anywhere on the front end. so we can remove them from API responses.

Describe the solution you'd like

  1. Add an Exclude decorator to an entity, like,
import { Exclude } from 'class-transformer';
export class MyEntity {
  ...
  @Exclude()
  createdAt: Date;
  @Exclude()
  updatedAt: Date;
  @Exclude()
  __v?: number;
}
  1. Add __v in the SchemaDocument,
interface IMyDocument extends MyEntity, Document {
  _id: never;
  __v: never;
}
  1. In the controller apply the ClassSerializerInterceptor interceptor, like,
import { Body, ClassSerializerInterceptor, UseInterceptors } from '@nestjs/common';
...

@UseInterceptors(ClassSerializerInterceptor)
export class MyController {
  ...
}
  1. Build dal lib by running pnpm build:dal.
  2. Test respective API is sending the correct response.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions