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);