Browse Source

新增表

zs 11 months ago
parent
commit
d1f765bae4

+ 68 - 0
src/controller/platform/supply.controller.ts

@@ -0,0 +1,68 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { SupplyService } from '../../service/platform/supply.service';
+import { CDTO_supply, CVO_supply, FVO_supply, QDTO_supply, QVO_supply, UDTO_supply, UVAO_supply } from '../../interface/platform/supply.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['供给'])
+@Controller('/supply')
+export class SupplyController extends BaseController {
+  @Inject()
+  service: SupplyService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_supply })
+  async create(@Body() data: CDTO_supply) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_supply(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_supply })
+  async query(@Query() filter: QDTO_supply, @Query('skip') skip: number, @Query('limit') limit: number) {
+    const list = await this.service.query(filter, { skip, limit });
+    const data = [];
+    for (const i of list) {
+      const newData = new QVO_supply(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_supply })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_supply(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_supply })
+  async update(@Param('id') id: string, @Body() body: UDTO_supply) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 33 - 0
src/entity/platform/supply.entity.ts

@@ -0,0 +1,33 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'supply' },
+})
+export class Supply extends BaseModel {
+  @prop({ required: false, index: true, zh: '平台用户id' })
+  user: string;
+  @prop({ required: false, index: true, zh: '名称' })
+  name: string;
+  @prop({ required: false, index: true, zh: '类型' })
+  type: string;
+  @prop({ required: false, index: true, zh: '行业领域' })
+  field: string;
+  @prop({ required: false, index: false, zh: '需求紧急度' })
+  urgent: string;
+  @prop({ required: false, index: true, zh: '合作方式' })
+  method: string;
+  @prop({ required: false, index: false, zh: '有效期' })
+  time: Array<any>;
+  @prop({ required: false, index: false, zh: '价格' })
+  money: string;
+  @prop({ required: false, index: true, zh: '需求地区' })
+  area: Array<any>;
+  @prop({ required: false, index: false, zh: '简介' })
+  brief: string;
+  @prop({ required: false, index: true, zh: '需求状态', default: '0' })
+  demand_status: string;
+  @prop({ required: false, index: true, zh: '是否公开', default: '1' })
+  is_use: string;
+  @prop({ required: false, index: true, zh: '状态' })
+  status: string;
+}

+ 139 - 0
src/interface/platform/supply.interface.ts

@@ -0,0 +1,139 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_supply {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '用户id' })
+  'user': string = undefined;
+  @ApiProperty({ description: '名称' })
+  'name': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '行业领域' })
+  'field': string = undefined;
+  @ApiProperty({ description: '需求紧急度' })
+  'urgent': string = undefined;
+  @ApiProperty({ description: '合作方式' })
+  'method': string = undefined;
+  @ApiProperty({ description: '有效期' })
+  'time': string = undefined;
+  @ApiProperty({ description: '价格' })
+  'money': string = undefined;
+  @ApiProperty({ description: '需求地区' })
+  'area': Array<any> = undefined;
+  @ApiProperty({ description: '简介' })
+  'brief': string = undefined;
+  @ApiProperty({ description: '需求状态' })
+  'demand_status': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  'is_use': string = undefined;
+}
+
+export class QDTO_supply extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['user', 'name', 'type', 'field', 'method', 'area', 'demand_status', 'status', 'is_use'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '用户id' })
+  'user': string = undefined;
+  @ApiProperty({ description: '名称' })
+  'name': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '行业领域' })
+  'field': string = undefined;
+  @ApiProperty({ description: '合作方式' })
+  'method': string = undefined;
+  @ApiProperty({ description: '需求地区' })
+  'area': Array<any> = undefined;
+  @ApiProperty({ description: '需求状态' })
+  'demand_status': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  'is_use': string = undefined;
+}
+
+export class QVO_supply extends FVO_supply {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_supply {
+  @ApiProperty({ description: '用户id' })
+  @Rule(RuleType['string']().empty(''))
+  'user': string = undefined;
+  @ApiProperty({ description: '名称' })
+  @Rule(RuleType['string']().empty(''))
+  'name': string = undefined;
+  @ApiProperty({ description: '类型' })
+  @Rule(RuleType['string']().empty(''))
+  'type': string = undefined;
+  @ApiProperty({ description: '行业领域' })
+  @Rule(RuleType['string']().empty(''))
+  'field': string = undefined;
+  @ApiProperty({ description: '需求紧急度' })
+  @Rule(RuleType['string']().empty(''))
+  'urgent': string = undefined;
+  @ApiProperty({ description: '合作方式' })
+  @Rule(RuleType['string']().empty(''))
+  'method': string = undefined;
+  @ApiProperty({ description: '有效期' })
+  @Rule(RuleType['string']().empty(''))
+  'time': string = undefined;
+  @ApiProperty({ description: '价格' })
+  @Rule(RuleType['string']().empty(''))
+  'money': string = undefined;
+  @ApiProperty({ description: '需求地区' })
+  @Rule(RuleType['array']().empty(''))
+  'area': Array<any> = undefined;
+  @ApiProperty({ description: '简介' })
+  @Rule(RuleType['string']().empty(''))
+  'brief': string = undefined;
+  @ApiProperty({ description: '需求状态' })
+  @Rule(RuleType['string']().empty(''))
+  'demand_status': string = undefined;
+  @ApiProperty({ description: '状态' })
+  @Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+}
+
+export class CVO_supply extends FVO_supply {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_supply extends CDTO_supply {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_supply extends FVO_supply {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 11 - 0
src/service/platform/supply.service.ts

@@ -0,0 +1,11 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { Supply } from '../../entity/platform/supply.entity';
+type modelType = ReturnModelType<typeof Supply>;
+@Provide()
+export class SupplyService extends BaseService<modelType> {
+  @InjectEntityModel(Supply)
+  model: modelType;
+}