- bounty将在6天后过期**。回答此问题可获得+50声望奖励。Fahad Subzwari希望引起更多人关注此问题。
我有2个实体,即客户,订单与一对多的关系。一个客户可以有多个订单,一个订单可以只拥有一个客户。我正在创建一个API来创建订单,这是一个POST
API。order.controller.ts
@Post()
async createOrder(@Body() order: CreateOrderDto) {
const newOrder = await this.orderService.createOrder(order);
return newOrder;
}
order.service.ts
constructor(
@InjectRepository(Order)
private orderRepository: Repository<Order>,
) {}
async createOrder(order: IOrder) {
const newOrder = this.orderRepository.create(order);
await this.orderRepository.save(newOrder);
return newOrder;
}
create-order.dto.ts
export class CreateOrderDto {
@IsString()
@IsNotEmpty()
@Length(5, 400)
public description: string;
@IsNotEmpty()
@IsNumber()
@IsPositive()
public amount: number;
@IsNotEmpty()
@IsString()
public paymentMethod: string;
@IsOptional()
@IsString()
public customizeName: string;
@IsOptional()
@IsString()
public weight: string;
@IsNotEmpty()
public customer: ICustomer;
@IsNotEmpty()
@IsArray()
public products: Array<IProduct>;
}
我从 Postman 那里寄了这封信
{
"description": "Customized waullet",
"quantity": 1,
"amount": 1500,
"paymentMethod": "cashOnDelivery",
"customizeName": "Faizan",
"weight": "2.5g",
"customer": {
"fullName": "Anas Subzwari",
"age": 20,
"country": "Pakistan",
"city": "Karachi",
"address": "B-17/519, Indus Mehran Society",
"contactNumber": "+923132953154"
},
"products": [
{
"name": "test10 product",
"description": "Customize blue color vaaulid with picture printing",
"cost": 700,
"price": 1200,
"weight": "2.3g"
},
{
"name": "Customize vaulid",
"description": "Customize blue color vaaulid with picture printing",
"cost": 700,
"price": 1200,
"weight": "2.3g"
}
]
}
我收到此错误
UpdateValuesMissingError: Cannot perform update query because update values are not defined. Call "qb.set(...)" method to specify updated values.
{"statusCode":500,"timestamp":"2023-02-25T18:06:43.623Z","path":"/orders","method":"POST","errorName":"UpdateValuesMissingError","message":"Cannot perform update query because update values are not defined. Call \"qb.set(...)\" method to specify updated values."}
我如何修复此错误?
2条答案
按热度按时间tvmytwxo1#
您需要先创建客户,然后再保存或获取客户(如果已保存),产品是同一问题
x4shl7ld2#
您需要像这样定义表顺序和客户之间的关系。
希望对你有帮助。