|
@@ -171,7 +171,15 @@ module.exports = async (dbName='shop-roles') => {
|
|
|
}
|
|
|
|
|
|
get total(){
|
|
|
- return (async() => (await Promise.all(this.orderGoods)).reduce((a,b) => (a.total || a) + b.total, 0))()
|
|
|
+ return (async () =>{
|
|
|
+ let total = 0
|
|
|
+ try {
|
|
|
+ total = (await Promise.all(this.orderGoods)).reduce((a,b) => (a?.total || a) + (b?.total || 0), 0)
|
|
|
+ }
|
|
|
+ catch(e){
|
|
|
+ }
|
|
|
+ return total
|
|
|
+ })()
|
|
|
}
|
|
|
|
|
|
static get relations(){
|
|
@@ -208,8 +216,12 @@ module.exports = async (dbName='shop-roles') => {
|
|
|
}
|
|
|
|
|
|
async save(...params){
|
|
|
+ if (!this.good){
|
|
|
+ throw new Error('Good Required for OrderGood')
|
|
|
+ }
|
|
|
if (!this.price && this.good && this.good.price){
|
|
|
this.price = this.good.price
|
|
|
+ this.goodName = this.good.name
|
|
|
}
|
|
|
return await super.save(...params)
|
|
|
}
|