lrf преди 2 години
родител
ревизия
e8fd4bfe6b
променени са 1 файла, в които са добавени 7 реда и са изтрити 0 реда
  1. 7 0
      app/service/user/address.js

+ 7 - 0
app/service/user/address.js

@@ -19,6 +19,13 @@ class AddressService extends CrudService {
     return data;
     return data;
   }
   }
 
 
+  async beforeCreate(data) {
+    const { customer } = data;
+    const num = await this.model.count({ customer });
+    if (num <= 0) data.is_default = '1';
+    return data;
+  }
+
   async toDefault({ id }) {
   async toDefault({ id }) {
     const data = await this.model.findById(id);
     const data = await this.model.findById(id);
     if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
     if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST);