121 lines
3.0 KiB
TypeScript
121 lines
3.0 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
} from '@nestjs/common';
|
|
import { ExpenseItem, ExpenseList, User } from '@prisma/client';
|
|
|
|
import { Authorized } from '@/shared/decorators';
|
|
|
|
import {
|
|
CreateExpenseList,
|
|
CreateExpenseListItem,
|
|
DeleteExpenseList,
|
|
DeleteExpenseListItem,
|
|
EditExpenseList,
|
|
EditExpenseListItem,
|
|
FindAllExpenseLists,
|
|
FindExpenseList,
|
|
FindExpenseListItem,
|
|
} from './decorators';
|
|
import {
|
|
CreateExpenseListItemDto,
|
|
EditExpenseListItemDto,
|
|
CreateExpenseListDto,
|
|
EditExpenseListDto,
|
|
} from './dto';
|
|
import { ExpensesService } from './expenses.service';
|
|
|
|
@Controller('expenses')
|
|
export class ExpensesController {
|
|
constructor(private readonly expensesService: ExpensesService) {}
|
|
|
|
@Post('list')
|
|
@CreateExpenseList()
|
|
async createList(
|
|
@Body() body: CreateExpenseListDto,
|
|
@Authorized('userId') userId: User['id'],
|
|
) {
|
|
return this.expensesService.createList(body, userId);
|
|
}
|
|
|
|
@Get('list/:id')
|
|
@FindExpenseList()
|
|
async findList(
|
|
@Param('id') id: ExpenseList['id'],
|
|
@Authorized('userId') userId: User['id'],
|
|
) {
|
|
return this.expensesService.getListById(id, userId);
|
|
}
|
|
|
|
@Get('list')
|
|
@FindAllExpenseLists()
|
|
async findAllLists(@Authorized('userId') userId: User['id']) {
|
|
return this.expensesService.getAllLists(userId);
|
|
}
|
|
|
|
@Patch('list/:id')
|
|
@EditExpenseList()
|
|
async editList(
|
|
@Param('id') id: ExpenseList['id'],
|
|
@Body() body: EditExpenseListDto,
|
|
@Authorized('userId') userId: User['id'],
|
|
) {
|
|
return this.expensesService.editList(id, body, userId);
|
|
}
|
|
|
|
@Delete('list/:id')
|
|
@DeleteExpenseList()
|
|
async deleteList(
|
|
@Param('id') id: ExpenseList['id'],
|
|
@Authorized('userId') userId: User['id'],
|
|
) {
|
|
return this.expensesService.deleteList(id, userId);
|
|
}
|
|
|
|
@Post('list/:id/items')
|
|
@CreateExpenseListItem()
|
|
async createListItem(
|
|
@Body() body: CreateExpenseListItemDto,
|
|
@Param('id') listId: ExpenseList['id'],
|
|
@Authorized('userId') userId: User['id'],
|
|
) {
|
|
return this.expensesService.createListItem(body, listId, userId);
|
|
}
|
|
|
|
@Get('list/:listId/items/:id')
|
|
@FindExpenseListItem()
|
|
async findListItem(
|
|
@Param('listId') listId: ExpenseList['id'],
|
|
@Param('id') id: ExpenseItem['id'],
|
|
@Authorized('userId') userId: User['id'],
|
|
) {
|
|
return this.expensesService.findListItemById(id, listId, userId);
|
|
}
|
|
|
|
@Patch('list/:listId/items/:id')
|
|
@EditExpenseListItem()
|
|
async editListItem(
|
|
@Body() body: EditExpenseListItemDto,
|
|
@Param('listId') listId: ExpenseList['id'],
|
|
@Param('id') id: ExpenseItem['id'],
|
|
@Authorized('userId') userId: User['id'],
|
|
) {
|
|
return this.expensesService.editListItem(body, id, listId, userId);
|
|
}
|
|
|
|
@Delete('list/:listId/items/:id')
|
|
@DeleteExpenseListItem()
|
|
async deleteListItem(
|
|
@Param('listId') listId: ExpenseList['id'],
|
|
@Param('id') id: ExpenseItem['id'],
|
|
@Authorized('userId') userId: User['id'],
|
|
) {
|
|
return this.expensesService.deleteListItem(id, listId, userId);
|
|
}
|
|
}
|