瀏覽代碼

修改接口

zs 1 年之前
父節點
當前提交
3ae9d3589c

+ 2 - 2
src/controller/User.controller.ts

@@ -85,7 +85,7 @@ export class UserController extends BaseController {
   @Validate()
   @ApiResponse({ type: CVO_User })
   async create(@Body() data: CDTO_User) {
-    // 检查手机号
+    // 检查手机号和姓名
     await this.userUtil.checkPhoneAndPid(data);
     const dbData = await this.service.create(data);
     const result = new CVO_User(dbData);
@@ -121,7 +121,7 @@ export class UserController extends BaseController {
   @Validate()
   @ApiResponse({ type: UVAO_User })
   async update(@Param('id') id: string, @Body() body: UDTO_User) {
-    // 检查手机号
+    // 检查手机号和姓名
     await this.userUtil.checkUpdateCardAndPid(id, body);
     const result = await this.service.updateOne(id, body);
     return result;

+ 17 - 3
src/entity/Office.entity.ts

@@ -6,7 +6,7 @@ import { BaseModel } from 'free-midway-component';
 export class Office extends BaseModel {
   @prop({
     required: false,
-    index: false,
+    index: true,
     zh: '办公处名',
     remark: '街道社区通用',
   })
@@ -15,10 +15,24 @@ export class Office extends BaseModel {
   address: string;
   @prop({
     required: false,
-    index: false,
+    index: true,
     zh: '所属',
-    ref: 'Office',
+    // ref: 'Office',
     remark: '社区填写,街道不写',
   })
   belong: string;
+  @prop({
+    required: false,
+    index: true,
+    zh: '类型',
+    remark: '字典表 office_type',
+  })
+  type: string;
+  @prop({
+    required: false,
+    index: true,
+    zh: '是否使用',
+    remark: '字典表:is_use',
+  })
+  is_use: string;
 }

+ 19 - 1
src/interface/Office.interface.ts

@@ -20,15 +20,27 @@ export class FVO_Office {
   'address': string = undefined;
   @ApiProperty({ description: '所属' })
   'belong': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
 }
 
 export class QDTO_Office extends SearchBase {
   constructor() {
     const like_prop = [];
-    const props = [];
+    const props = ['name', 'belong', 'type', 'is_use'];
     const mapping = [];
     super({ like_prop, props, mapping });
   }
+  @ApiProperty({ description: '办公处名' })
+  'name': string = undefined;
+  @ApiProperty({ description: '所属' })
+  'belong': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  'is_use': string = undefined;
 }
 
 export class QVO_Office extends FVO_Office {
@@ -48,6 +60,12 @@ export class CDTO_Office {
   @ApiProperty({ description: '所属' })
   @Rule(RuleType['string']().empty(''))
   'belong': string = undefined;
+  @ApiProperty({ description: '类型' })
+  @Rule(RuleType['string']().empty(''))
+  'type': string = undefined;
+  @ApiProperty({ description: '是否使用' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
 }
 
 export class CVO_Office extends FVO_Office {

+ 2 - 0
src/interface/util/user.util.interface.ts

@@ -1,6 +1,8 @@
 export interface CheckUpdateCardAndPid {
   tel?: string;
+  name?: string;
 }
 export interface checkPhoneAndPid {
   tel?: string;
+  name?: string;
 }

+ 25 - 5
src/service/util/user.util.ts

@@ -14,7 +14,7 @@ export class UserUtilService {
   UserModel: ReturnModelType<typeof User>;
 
   /**
-   * 检查创建时,手机号和上级id
+   * 检查创建时,检查手机号和姓名
    * @param data 参数
    */
   async checkPhoneAndPid(data: checkPhoneAndPid) {
@@ -23,19 +23,27 @@ export class UserUtilService {
       const useran = await this.UserModel.count({ tel: data.tel });
       if (useran > 0) {
         throw new ServiceError(
-          '已有用户 使用该手机号',
+          '已有用户 使用该手机号!',
+          FrameworkErrorEnum.BAD_BODY
+        );
+      }
+      // 检查姓名
+      const username = await this.UserModel.count({ name: data.name });
+      if (username > 0) {
+        throw new ServiceError(
+          '已有用户 使用该名称!',
           FrameworkErrorEnum.BAD_BODY
         );
       }
     }
   }
   /**
-   * 检查创建时,手机号
+   * 检查创建时,检查手机号和姓名
    * @param id 当前要修改的数据
    * @param data 参数
    */
   async checkUpdateCardAndPid(id, data: CheckUpdateCardAndPid) {
-    const { tel } = data;
+    const { tel, name } = data;
     if (tel) {
       const useran = await this.UserModel.count({
         _id: { $ne: id },
@@ -43,7 +51,19 @@ export class UserUtilService {
       });
       if (useran > 0) {
         throw new ServiceError(
-          '已有用户 使用该手机号',
+          '已有用户 使用该手机号!',
+          FrameworkErrorEnum.BAD_BODY
+        );
+      }
+    }
+    if (name) {
+      const username = await this.UserModel.count({
+        _id: { $ne: id },
+        name,
+      });
+      if (username > 0) {
+        throw new ServiceError(
+          '已有用户 使用该名称!',
           FrameworkErrorEnum.BAD_BODY
         );
       }