hI!
I am trying to handle one POST request and finding the next. problem.
I have a relation between "locations" and "customers". In fact, one user has N locations.
When I sent the request from POSTMAN, in the table DB, customerId is null
Here controller code:
@Post()
create(
@Body() createLocationDto: CreateLocationDto,
@Req() request: Request,
) {
const customerId = request.body['customerId'];
return this.locationsService.create(createLocationDto, customerId);
} ```
service:
async create(createLocationDto: CreateLocationDto, customerId: string) {
try {
const location = this.locationRepository.create(createLocationDto);
location['customerId'] = customerId;
console.log('location', location);
await this.locationRepository.save(location);
return location;
} catch (err) {
console.log(err);
}
}
DTO
@ApiProperty()
@IsUUID()
readonly customerId: string;
Entity
@ManyToOne(() => Customer)
@JoinColumn()
customer: Customer;
I hope your help, I am not being able to find the cause.
Thank you in advance.