import { ClassConstructor, Exclude, plainToInstance, Transform } from 'class-transformer';

export class BasicDTO {
  @Exclude()
  createdAt: Date;

  @Exclude()
  updatedAt: Date;

  @Exclude()
  __v: number;

  @Transform(({ value }) => value.toString())
  _id: string;
}

export const rawDataToDTO = <T, V>(DTOModel: ClassConstructor<T>, rawData: V[]) => {
  return rawData.map((item) => plainToInstance<T, V>(DTOModel, item));
};
