forked from Yara724/api
64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Body,
|
|
Patch,
|
|
Param,
|
|
Delete,
|
|
UseGuards,
|
|
} from "@nestjs/common";
|
|
import { ApiBearerAuth, ApiBody, ApiParam, ApiTags } from "@nestjs/swagger";
|
|
import { GlobalGuard } from "src/auth/guards/global.guard";
|
|
import { CurrentUser } from "src/decorators/user.decorator";
|
|
import { Roles } from "src/decorators/roles.decorator";
|
|
import { PlatesService } from "src/plates/plates.service";
|
|
import { AddPlateDto, AddPlateProfileDto } from "./dto/user/AddPlateDto";
|
|
import { UpdateUserProfileDtoRq } from "./dto/user/update-profile.dto";
|
|
import { ProfileService } from "./profile.service";
|
|
|
|
@Controller("user/profile")
|
|
@ApiTags("user")
|
|
@ApiBearerAuth()
|
|
@Roles()
|
|
export class ProfileController {
|
|
constructor(
|
|
private readonly profileService: ProfileService,
|
|
private readonly plateService: PlatesService,
|
|
) {}
|
|
|
|
@Get()
|
|
@UseGuards(GlobalGuard)
|
|
async getProfile(@CurrentUser() user) {
|
|
return await this.profileService.getProfileDetail(user.username);
|
|
}
|
|
|
|
@Patch()
|
|
@UseGuards(GlobalGuard)
|
|
@ApiBody({ type: UpdateUserProfileDtoRq })
|
|
async updateProfile(
|
|
@CurrentUser() user,
|
|
@Body() body: UpdateUserProfileDtoRq,
|
|
) {
|
|
return await this.profileService.updateProfile(user.username, body);
|
|
}
|
|
|
|
@Post("plate")
|
|
@UseGuards(GlobalGuard)
|
|
@ApiBody({ type: AddPlateProfileDto })
|
|
async addPlate(@CurrentUser() user, @Body() body: AddPlateDto) {
|
|
console.log(
|
|
"🚀 ~ file: profile.controller.ts:50 ~ ProfileController ~ addPlate ~ user:",
|
|
user,
|
|
);
|
|
return await this.plateService.addPlate(user.sub, body);
|
|
}
|
|
|
|
@Delete("plate/:id")
|
|
@UseGuards(GlobalGuard)
|
|
@ApiParam({ name: "id", required: true })
|
|
async deletePlate(@Param("id") id) {
|
|
return await this.plateService.deletePlate(id);
|
|
}
|
|
}
|