mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
feat: create junior
This commit is contained in:
56
src/junior/controllers/junior.controller.ts
Normal file
56
src/junior/controllers/junior.controller.ts
Normal file
@ -0,0 +1,56 @@
|
||||
import { Body, Controller, Get, Param, Post, Query, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { IJwtPayload } from '~/auth/interfaces';
|
||||
import { AuthenticatedUser } from '~/common/decorators';
|
||||
import { AccessTokenGuard } from '~/common/guards';
|
||||
import { ApiDataPageResponse, ApiDataResponse } from '~/core/decorators';
|
||||
import { PageOptionsRequestDto } from '~/core/dtos';
|
||||
import { CustomParseUUIDPipe } from '~/core/pipes';
|
||||
import { ResponseFactory } from '~/core/utils';
|
||||
import { CreateJuniorRequestDto } from '../dtos/request';
|
||||
import { JuniorResponseDto } from '../dtos/response';
|
||||
import { JuniorService } from '../services';
|
||||
|
||||
@Controller('juniors')
|
||||
@ApiTags('Juniors')
|
||||
@ApiBearerAuth()
|
||||
export class JuniorController {
|
||||
constructor(private readonly juniorService: JuniorService) {}
|
||||
|
||||
@Post()
|
||||
@UseGuards(AccessTokenGuard)
|
||||
@ApiDataResponse(JuniorResponseDto)
|
||||
async createJunior(@Body() body: CreateJuniorRequestDto, @AuthenticatedUser() user: IJwtPayload) {
|
||||
const junior = await this.juniorService.createJuniors(body, user.sub);
|
||||
|
||||
return ResponseFactory.data(new JuniorResponseDto(junior));
|
||||
}
|
||||
|
||||
@Get()
|
||||
@UseGuards(AccessTokenGuard)
|
||||
@ApiDataPageResponse(JuniorResponseDto)
|
||||
async findJuniors(@AuthenticatedUser() user: IJwtPayload, @Query() pageOptions: PageOptionsRequestDto) {
|
||||
const [juniors, count] = await this.juniorService.findJuniorsByGuardianId(user.sub, pageOptions);
|
||||
|
||||
return ResponseFactory.dataPage(
|
||||
juniors.map((juniors) => new JuniorResponseDto(juniors)),
|
||||
{
|
||||
page: pageOptions.page,
|
||||
size: pageOptions.size,
|
||||
itemCount: count,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@Get(':juniorId')
|
||||
@UseGuards(AccessTokenGuard)
|
||||
@ApiDataResponse(JuniorResponseDto)
|
||||
async findJuniorById(
|
||||
@AuthenticatedUser() user: IJwtPayload,
|
||||
@Param('juniorId', CustomParseUUIDPipe) juniorId: string,
|
||||
) {
|
||||
const junior = await this.juniorService.findJuniorById(juniorId, user.sub);
|
||||
|
||||
return ResponseFactory.data(new JuniorResponseDto(junior));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user