lrf 2 سال پیش
والد
کامیت
df927cc3f6
1فایلهای تغییر یافته به همراه6 افزوده شده و 1 حذف شده
  1. 6 1
      app/service/user/address.js

+ 6 - 1
app/service/user/address.js

@@ -16,7 +16,7 @@ class AddressService extends CrudService {
   async afterCreate(body, data) {
     const { is_default } = data;
     if (is_default !== this.defaultValue) await this.toDefault({ id: data._id });
-    await this.checkDefault();
+    await this.checkDefault({ customer: data.customer });
     return data;
   }
   /**
@@ -29,6 +29,11 @@ class AddressService extends CrudService {
     if (num <= 0) data.is_default = '1';
     return data;
   }
+  async afterUpdate(filter, body, data) {
+    if (data.is_default !== this.defaultValue) await this.toDefault({ id: data._id });
+    await this.checkDefault({ customer: data.customer });
+    return data;
+  }
 
   async toDefault({ id }) {
     const data = await this.model.findById(id);