|
|
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) {} |
|
|
|
|
|
|
|
|
@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), |
|
|
}; |
|
|
} |
|
|
} |
|
|
|