modeling out expense entities and dtos
This commit is contained in:
parent
acdb7ad9c9
commit
7011e44662
10 changed files with 83 additions and 14 deletions
11
bruno/Common Cents/Expenses/Expenses.bru
Normal file
11
bruno/Common Cents/Expenses/Expenses.bru
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
meta {
|
||||
name: Expenses
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{localBaseUrl}}/health
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
3
bruno/Common Cents/Expenses/folder.bru
Normal file
3
bruno/Common Cents/Expenses/folder.bru
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
meta {
|
||||
name: Expenses
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
meta {
|
||||
name: Healthcheck
|
||||
type: http
|
||||
seq: 2
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
export class CreateExpenseDto {}
|
||||
19
src/controllers/expenses/expense.dto.ts
Normal file
19
src/controllers/expenses/expense.dto.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { PartialType } from '@nestjs/mapped-types';
|
||||
|
||||
export class CreateExpenseDto {
|
||||
year: string;
|
||||
month: string;
|
||||
day: string;
|
||||
cents: number;
|
||||
category: string;
|
||||
subcategory?: string[];
|
||||
merchant?: string;
|
||||
tags?: string[];
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export class UpdateExpenseDto extends PartialType(CreateExpenseDto) { }
|
||||
|
||||
export class GetExpenseDto extends CreateExpenseDto{
|
||||
id: number;
|
||||
}
|
||||
32
src/controllers/expenses/expense.entities.ts
Normal file
32
src/controllers/expenses/expense.entities.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
export class Expense {
|
||||
id: number;
|
||||
year: string;
|
||||
month: string;
|
||||
day: string;
|
||||
cents: number;
|
||||
category: Category;
|
||||
subcategory?: SubCategory[];
|
||||
merchant?: Merchant;
|
||||
tags?: Tag[];
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export class Category {
|
||||
id: number;
|
||||
category: string;
|
||||
}
|
||||
|
||||
export class SubCategory {
|
||||
id: number;
|
||||
subcategory: string;
|
||||
}
|
||||
|
||||
export class Merchant {
|
||||
id: number;
|
||||
merchant: string;
|
||||
}
|
||||
|
||||
export class Tag {
|
||||
id: number;
|
||||
tag: string;
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
export class Expense {}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { ExpensesService } from '../../services/expenses.service';
|
||||
import { CreateExpenseDto } from './create-expense.dto';
|
||||
import { UpdateExpenseDto } from './update-expense.dto';
|
||||
import { CreateExpenseDto, GetExpenseDto, UpdateExpenseDto } from './expense.dto';
|
||||
|
||||
@Controller('expenses')
|
||||
export class ExpensesController {
|
||||
|
|
@ -13,7 +12,7 @@ export class ExpensesController {
|
|||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
findAll(): GetExpenseDto[] {
|
||||
return this.expensesService.findAll();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateExpenseDto } from './create-expense.dto';
|
||||
|
||||
export class UpdateExpenseDto extends PartialType(CreateExpenseDto) {}
|
||||
|
|
@ -1,15 +1,26 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { CreateExpenseDto } from '../controllers/expenses/create-expense.dto';
|
||||
import { UpdateExpenseDto } from '../controllers/expenses/update-expense.dto';
|
||||
import { Expense } from '../controllers/expenses/expense.entities';
|
||||
import {CreateExpenseDto, GetExpenseDto, UpdateExpenseDto} from '../controllers/expenses/expense.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ExpensesService {
|
||||
private fakeTempData: GetExpenseDto[] = [
|
||||
{
|
||||
id: 123,
|
||||
year: '2025',
|
||||
month: '12',
|
||||
day: '10',
|
||||
cents: 987,
|
||||
category: 'Automotive'
|
||||
}
|
||||
];
|
||||
|
||||
create(createExpenseDto: CreateExpenseDto) {
|
||||
return 'This action adds a new expense';
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all expenses`;
|
||||
findAll(): GetExpenseDto[] {
|
||||
return this.fakeTempData;
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue