Browse Source

修改项目管理

zs 1 year ago
parent
commit
53ff7d3731

+ 68 - 0
src/controller/platform/project.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 { ProjectService } from '../../service/platform/project.service';
+import { CDTO_project, CVO_project, FVO_project, QDTO_project, QVO_project, UDTO_project, UVAO_project } from '../../interface/platform/project.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['项目'])
+@Controller('/project')
+export class ProjectController extends BaseController {
+  @Inject()
+  service: ProjectService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_project })
+  async create(@Body() data: CDTO_project) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_project(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_project })
+  async query(@Query() filter: QDTO_project, @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_project(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_project })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_project(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_project })
+  async update(@Param('id') id: string, @Body() body: UDTO_project) {
+    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.');
+  }
+}

+ 29 - 0
src/entity/platform/project.entity.ts

@@ -0,0 +1,29 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'project' },
+})
+export class Project extends BaseModel {
+  @prop({ required: false, index: false, zh: '平台用户id' })
+  user: string;
+  @prop({ required: false, index: true, zh: '名称' })
+  name: string;
+  @prop({ required: false, index: true, zh: '发布时间' })
+  time: string;
+  @prop({ required: false, index: true, zh: '行业分类' })
+  type: string;
+  @prop({ required: false, index: true, zh: '成熟度' })
+  maturity: string;
+  @prop({ required: false, index: true, zh: '技术类型' })
+  skill: string;
+  @prop({ required: false, index: true, zh: '领域' })
+  field: string;
+  @prop({ required: false, index: true, zh: '合作类型' })
+  cooperate: string;
+  @prop({ required: false, index: false, zh: '简介' })
+  brief: string;
+  @prop({ required: false, index: false, zh: '是否公开' })
+  is_use: string;
+  @prop({ required: false, index: true, zh: '状态' })
+  status: string;
+}

+ 129 - 0
src/interface/platform/project.interface.ts

@@ -0,0 +1,129 @@
+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_project {
+  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: '发布时间' })
+  'time': string = undefined;
+  @ApiProperty({ description: '行业分类' })
+  'type': string = undefined;
+  @ApiProperty({ description: '成熟度' })
+  'maturity': string = undefined;
+  @ApiProperty({ description: '技术类型' })
+  'skill': string = undefined;
+  @ApiProperty({ description: '领域' })
+  'field': string = undefined;
+  @ApiProperty({ description: '合作类型' })
+  'cooperate': string = undefined;
+  @ApiProperty({ description: '简介' })
+  'brief': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QDTO_project extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['name', 'time', 'type', 'maturity', 'skill', 'field', 'cooperate', 'status', 'is_use'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '名称' })
+  'name': string = undefined;
+  @ApiProperty({ description: '发布时间' })
+  'time': string = undefined;
+  @ApiProperty({ description: '行业分类' })
+  'type': string = undefined;
+  @ApiProperty({ description: '成熟度' })
+  'maturity': string = undefined;
+  @ApiProperty({ description: '技术类型' })
+  'skill': string = undefined;
+  @ApiProperty({ description: '领域' })
+  'field': string = undefined;
+  @ApiProperty({ description: '合作类型' })
+  'cooperate': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  'is_use': string = undefined;
+}
+
+export class QVO_project extends FVO_project {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_project {
+  @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(''))
+  'time': string = undefined;
+  @ApiProperty({ description: '行业分类' })
+  @Rule(RuleType['string']().empty(''))
+  'type': string = undefined;
+  @ApiProperty({ description: '成熟度' })
+  @Rule(RuleType['string']().empty(''))
+  'maturity': string = undefined;
+  @ApiProperty({ description: '技术类型' })
+  @Rule(RuleType['string']().empty(''))
+  'skill': string = undefined;
+  @ApiProperty({ description: '领域' })
+  @Rule(RuleType['string']().empty(''))
+  'field': string = undefined;
+  @ApiProperty({ description: '合作类型' })
+  @Rule(RuleType['string']().empty(''))
+  'cooperate': string = undefined;
+  @ApiProperty({ description: '简介' })
+  @Rule(RuleType['string']().empty(''))
+  'brief': string = undefined;
+  @ApiProperty({ description: '是否公开' })
+  @Rule(RuleType['string']().empty(''))
+  'is_use': string = undefined;
+  @ApiProperty({ description: '状态' })
+  @Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+}
+
+export class CVO_project extends FVO_project {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_project extends CDTO_project {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_project extends FVO_project {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 11 - 0
src/service/platform/project.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 { Project } from '../../entity/platform/project.entity';
+type modelType = ReturnModelType<typeof Project>;
+@Provide()
+export class ProjectService extends BaseService<modelType> {
+  @InjectEntityModel(Project)
+  model: modelType;
+}