123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import {
- Body,
- Controller,
- Del,
- Inject,
- Param,
- Post,
- Query,
- } from '@midwayjs/decorator';
- import { BaseController } from 'free-midway-component';
- import { UserService } from '../service/user.service';
- import {
- CDTO_user,
- CVO_user,
- FVO_user,
- QDTO_user,
- QVO_user,
- UDTO_user,
- UVAO_user,
- } from '../interface/user.interface';
- import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
- import { Validate } from '@midwayjs/validate';
- @ApiTags(['用户'])
- @Controller('/user')
- export class UserController extends BaseController {
- @Inject()
- service: UserService;
- @Post('/')
- @Validate()
- @ApiResponse({ type: CVO_user })
- async create(@Body() data: CDTO_user) {
- await this.service.findOrCreate(data.openid);
- return 'ok';
- }
- @ApiQuery({ name: 'query' })
- @ApiResponse({ type: QVO_user })
- async query(
- @Query() filter: QDTO_user,
- @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_user(i);
- data.push(newData);
- }
- const total = await this.service.count(filter);
- return { data, total };
- }
- @ApiResponse({ type: FVO_user })
- async fetch(@Param('id') id: string) {
- const data = await this.service.fetch(id);
- const result = new FVO_user(data);
- return result;
- }
- @Validate()
- @ApiResponse({ type: UVAO_user })
- async update(@Param('id') id: string, @Body() body: UDTO_user) {
- 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.');
- }
- }
|