【发布时间】:2019-11-30 01:11:26
【问题描述】:
我需要访问一个属性,但发送的只是 id。
我的请求正文示例:
{
"items": [
{
"quantity": 3,
"product": "5d33fc0ac8c7a56d62cd6ac6"
}
],
"user": "5d33fdafc8c7a56d62cd6ac9"
}
我需要得到产品的价格并乘以数量
async create(createOrderDto: CreateOrderDto): Promise<IOrder> {
try {
const order = new this.orderSchema(createOrderDto);
order.items.map(item => item.subtotal = item.product.price * item.quantity));
return await this.orderSchema.create(order);
} catch (error) {
throw new InternalServerErrorException(error.message);
}
}
item.product.price 错误消息:“属性 'price' 在类型 'ObjectId'.ts(2339)'上不存在”
如何将 item.product 转换为 Product.Schema 之类的?
【问题讨论】:
标签: javascript node.js mongodb typescript nestjs