user.controller.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {
  2. Body,
  3. Controller,
  4. Del,
  5. Get,
  6. Inject,
  7. Param,
  8. Post,
  9. } from '@midwayjs/core';
  10. import { UserService } from '../../service/system/user.service';
  11. import { RF } from '../../response/CustomerResponse';
  12. import { Page, Query } from '../../decorator/page.decorator';
  13. @Controller('/user')
  14. export class UserController {
  15. @Inject()
  16. service: UserService;
  17. @Post('/')
  18. async create(@Body() body) {
  19. await this.service.checkInDB(body);
  20. const data = await this.service.create(body);
  21. return RF.success(data);
  22. }
  23. @Get('/')
  24. async query(@Query() query, @Page() page) {
  25. const result = await this.service.page(query, page);
  26. return RF.success(result);
  27. }
  28. @Get('/:id')
  29. async fetch(@Param('id') _id: string) {
  30. const result = await this.service.findOne({ _id });
  31. return RF.success(result);
  32. }
  33. @Post('/:id')
  34. async update(@Param('id') _id: string, @Body() body) {
  35. // 删除account字段,不允许更改
  36. delete body.account;
  37. const result = await this.service.update({ _id }, body);
  38. return RF.success(result);
  39. }
  40. @Del('/:id')
  41. async delete(@Param('id') _id: string) {
  42. await this.service.delete({ _id });
  43. return RF.success();
  44. }
  45. }