File size: 1,283 Bytes
db242f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import * as Joi from 'joi';

import { Body, Controller, Get, Put } from '@nestjs/common';

import { Payload } from '@/common/guards/auth.guard';
import { JoiValidationPipe } from '@/common/pipes/joi';

import { UserService } from './user.service';

const nameSchema = Joi.string().min(4).max(20).required();

@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  /* 用户基本信息:用户名、手机号、邮箱、是否为 Premium 会员 */
  @Get('info')
  async getInfo(@Payload('id') userId: number) {
    return {
      success: true,
      data: await this.userService.getInfo(userId),
    };
  }

  @Get('limit')
  async getPremium(@Payload('id') userId: number) {
    return {
      success: true,
      data: {
        times: 100,
      },
    };
  }

  @Get('orders')
  async getUserOrders(@Payload('id') userId: number) {}

  @Get('settings')
  async getSettings(@Payload('id') userId: number) {
    return await this.userService.getSettings(userId);
  }

  @Put('name')
  async updateName(
    @Payload('id') userId: number,
    @Body('name', new JoiValidationPipe(nameSchema)) name: string,
  ) {
    return {
      success: true,
      data: await this.userService.updateName(userId, name),
    };
  }
}