123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import {
- Body,
- Controller,
- Del,
- Get,
- Inject,
- Param,
- Post,
- } from '@midwayjs/core';
- import { UserService } from '../../service/system/user.service';
- import { RF } from '../../response/CustomerResponse';
- import { Page, Query } from '../../decorator/page.decorator';
- @Controller('/user')
- export class UserController {
- @Inject()
- service: UserService;
- @Post('/')
- async create(@Body() body) {
- await this.service.checkInDB(body);
- const data = await this.service.create(body);
- return RF.success(data);
- }
- @Get('/')
- async query(@Query() query, @Page() page) {
- const result = await this.service.page(query, page);
- return RF.success(result);
- }
- @Get('/:id')
- async fetch(@Param('id') _id: string) {
- const result = await this.service.findOne({ _id });
- return RF.success(result);
- }
- @Post('/:id')
- async update(@Param('id') _id: string, @Body() body) {
- // 删除account字段,不允许更改
- delete body.account;
- const result = await this.service.update({ _id }, body);
- return RF.success(result);
- }
- @Del('/:id')
- async delete(@Param('id') _id: string) {
- await this.service.delete({ _id });
- return RF.success();
- }
- }
|