I have this DTO:
export class SituationDto {
@IsNumber()
@IsNotEmpty()
public borrower_id: number;
@IsString()
@IsNotEmpty()
public situation_name: string;
@IsString()
@IsNotEmpty()
public created_by: string;
}
I have this route:
@Post()
async postSituation(
@Body() body: SituationDto,
@Request() req: CustomRequestType
): Promise<number> {
return this.situationService.createSituation({
...body,
created_by: req.username
});
}
The problem is, I am getting username from req.username and then I am merging it down in a object which I send to my createSituation function in a service:
async createSituation(@Body() situationDto: SituationDto): Promise<number> {
const situation = this.situationRepository.create(situationDto);
const { situation_id } = await this.situationRepository.save(situation);
return situation_id;
}
So the problem is, in controller I am not going to get createdBy property in situationDto but in service I will, how can I handle this?