mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
refactor: remove unsed code
This commit is contained in:
@ -1,82 +0,0 @@
|
||||
import { Body, Controller, Get, HttpCode, HttpStatus, Param, Patch, Post, Query, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { Roles } from '~/auth/enums';
|
||||
import { IJwtPayload } from '~/auth/interfaces';
|
||||
import { AllowedRoles, AuthenticatedUser } from '~/common/decorators';
|
||||
import { RolesGuard } from '~/common/guards';
|
||||
import { ApiDataPageResponse, ApiDataResponse, ApiLangRequestHeader } from '~/core/decorators';
|
||||
import { CustomParseUUIDPipe } from '~/core/pipes';
|
||||
import { ResponseFactory } from '~/core/utils';
|
||||
import { CreateMoneyRequestRequestDto, MoneyRequestsFiltersRequestDto } from '../dtos/request';
|
||||
import { MoneyRequestResponseDto } from '../dtos/response/money-request.response.dto';
|
||||
import { MoneyRequestsService } from '../services';
|
||||
|
||||
@Controller('money-requests')
|
||||
@ApiTags('Money Requests')
|
||||
@ApiBearerAuth()
|
||||
@ApiLangRequestHeader()
|
||||
export class MoneyRequestsController {
|
||||
constructor(private readonly moneyRequestsService: MoneyRequestsService) {}
|
||||
|
||||
@Post()
|
||||
@UseGuards(RolesGuard)
|
||||
@AllowedRoles(Roles.JUNIOR)
|
||||
@ApiDataResponse(MoneyRequestResponseDto)
|
||||
async createMoneyRequest(@AuthenticatedUser() { sub }: IJwtPayload, @Body() body: CreateMoneyRequestRequestDto) {
|
||||
const moneyRequest = await this.moneyRequestsService.createMoneyRequest(sub, body);
|
||||
|
||||
return ResponseFactory.data(new MoneyRequestResponseDto(moneyRequest));
|
||||
}
|
||||
|
||||
@UseGuards(RolesGuard)
|
||||
@AllowedRoles(Roles.GUARDIAN)
|
||||
@Get()
|
||||
@ApiDataPageResponse(MoneyRequestResponseDto)
|
||||
async findMoneyRequests(@AuthenticatedUser() { sub }: IJwtPayload, @Query() filters: MoneyRequestsFiltersRequestDto) {
|
||||
const [moneyRequests, itemCount] = await this.moneyRequestsService.findMoneyRequests(sub, filters);
|
||||
|
||||
return ResponseFactory.dataPage(
|
||||
moneyRequests.map((moneyRequest) => new MoneyRequestResponseDto(moneyRequest)),
|
||||
{
|
||||
itemCount,
|
||||
page: filters.page,
|
||||
size: filters.size,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@UseGuards(RolesGuard)
|
||||
@AllowedRoles(Roles.GUARDIAN)
|
||||
@Get(':moneyRequestId')
|
||||
@ApiDataResponse(MoneyRequestResponseDto)
|
||||
async findMoneyRequestById(
|
||||
@AuthenticatedUser() { sub }: IJwtPayload,
|
||||
@Param('moneyRequestId', CustomParseUUIDPipe) moneyRequestId: string,
|
||||
) {
|
||||
const moneyRequest = await this.moneyRequestsService.findMoneyRequestById(moneyRequestId, sub);
|
||||
|
||||
return ResponseFactory.data(new MoneyRequestResponseDto(moneyRequest));
|
||||
}
|
||||
|
||||
@UseGuards(RolesGuard)
|
||||
@AllowedRoles(Roles.GUARDIAN)
|
||||
@Patch(':moneyRequestId/approve')
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
async approveMoneyRequest(
|
||||
@AuthenticatedUser() { sub }: IJwtPayload,
|
||||
@Param('moneyRequestId', CustomParseUUIDPipe) moneyRequestId: string,
|
||||
) {
|
||||
await this.moneyRequestsService.approveMoneyRequest(moneyRequestId, sub);
|
||||
}
|
||||
|
||||
@UseGuards(RolesGuard)
|
||||
@AllowedRoles(Roles.GUARDIAN)
|
||||
@Patch(':moneyRequestId/reject')
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
async rejectMoneyRequest(
|
||||
@AuthenticatedUser() { sub }: IJwtPayload,
|
||||
@Param('moneyRequestId', CustomParseUUIDPipe) moneyRequestId: string,
|
||||
) {
|
||||
await this.moneyRequestsService.rejectMoneyRequest(moneyRequestId, sub);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user