zs před 1 rokem
rodič
revize
39bbfad798

+ 1 - 0
package-lock.json

@@ -11,6 +11,7 @@
       "dependencies": {
         "@elastic/elasticsearch": "^8.12.2",
         "@midwayjs/bootstrap": "^3.12.0",
+        "@midwayjs/bull": "3",
         "@midwayjs/core": "^3.12.0",
         "@midwayjs/decorator": "^3.12.0",
         "@midwayjs/i18n": "3",

+ 68 - 0
src/controller/platform/collection.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 { CollectionService } from '../../service/platform/collection.service';
+import { CDTO_collection, CVO_collection, FVO_collection, QDTO_collection, QVO_collection, UDTO_collection, UVAO_collection } from '../../interface/platform/collection.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['收藏'])
+@Controller('/collection')
+export class CollectionController extends BaseController {
+  @Inject()
+  service: CollectionService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_collection })
+  async create(@Body() data: CDTO_collection) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_collection(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_collection })
+  async query(@Query() filter: QDTO_collection, @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_collection(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_collection })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_collection(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_collection })
+  async update(@Param('id') id: string, @Body() body: UDTO_collection) {
+    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.');
+  }
+}

+ 15 - 0
src/entity/platform/collection.entity.ts

@@ -0,0 +1,15 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'collection' },
+})
+export class Collection extends BaseModel {
+  @prop({ required: false, index: true, zh: '平台用户id' })
+  user: string;
+  @prop({ required: false, index: true, zh: '来源id' })
+  source: string;
+  @prop({ required: false, index: true, zh: '类型' })
+  type: string;
+  @prop({ required: false, index: false, zh: '收藏时间' })
+  time: string;
+}

+ 82 - 0
src/interface/platform/collection.interface.ts

@@ -0,0 +1,82 @@
+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_collection {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '平台用户id' })
+  'user': string = undefined;
+  @ApiProperty({ description: '来源id' })
+  'source': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '收藏时间' })
+  'time': string = undefined;
+}
+
+export class QDTO_collection extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['user', 'source', 'type'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '平台用户id' })
+  'user': string = undefined;
+  @ApiProperty({ description: '来源id' })
+  'source': string = undefined;
+  @ApiProperty({ description: '类型' })
+  'type': string = undefined;
+}
+
+export class QVO_collection extends FVO_collection {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_collection {
+  @ApiProperty({ description: '平台用户id' })
+  @Rule(RuleType['string']().empty(''))
+  'user': string = undefined;
+  @ApiProperty({ description: '来源id' })
+  @Rule(RuleType['string']().empty(''))
+  'source': string = undefined;
+  @ApiProperty({ description: '类型' })
+  @Rule(RuleType['string']().empty(''))
+  'type': string = undefined;
+  @ApiProperty({ description: '收藏时间' })
+  @Rule(RuleType['string']().empty(''))
+  'time': string = undefined;
+}
+
+export class CVO_collection extends FVO_collection {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_collection extends CDTO_collection {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_collection extends FVO_collection {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

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