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;
   }
 
+  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 }) {
     const data = await this.model.findById(id);
     if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST);