Compare commits
No commits in common. "1173ab4274d57c9147746cf37e7440071b976c80" and "c6434de89d83fcf9e17aa5caa74b3a519344f1f0" have entirely different histories.
1173ab4274
...
c6434de89d
28 changed files with 86 additions and 313 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -54,6 +54,3 @@ pids
|
||||||
|
|
||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
|
||||||
# Database
|
|
||||||
common-cents.db
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
meta {
|
meta {
|
||||||
name: Categories
|
name: Categories
|
||||||
seq: 2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auth {
|
auth {
|
||||||
|
|
|
||||||
11
bruno/Common Cents/Expenses/LOC DEL Expense.bru
Normal file
11
bruno/Common Cents/Expenses/LOC DEL Expense.bru
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
meta {
|
||||||
|
name: LOC DEL Expense
|
||||||
|
type: http
|
||||||
|
seq: 3
|
||||||
|
}
|
||||||
|
|
||||||
|
delete {
|
||||||
|
url: {{localBaseUrl}}/expenses/2aa94170-2c57-4c4f-a1e7-13544ba72917
|
||||||
|
body: none
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
meta {
|
|
||||||
name: LOC DELETE Expense
|
|
||||||
type: http
|
|
||||||
seq: 5
|
|
||||||
}
|
|
||||||
|
|
||||||
delete {
|
|
||||||
url: {{localBaseUrl}}/{{resourcePath}}/{{resourceId}}
|
|
||||||
body: none
|
|
||||||
auth: inherit
|
|
||||||
}
|
|
||||||
|
|
||||||
vars:pre-request {
|
|
||||||
resourceId: 41294f87-ab77-4fdd-9509-6968e6533962
|
|
||||||
}
|
|
||||||
|
|
@ -5,11 +5,7 @@ meta {
|
||||||
}
|
}
|
||||||
|
|
||||||
get {
|
get {
|
||||||
url: {{localBaseUrl}}/{{resourcePath}}/{{resourceId}}
|
url: {{localBaseUrl}}/expenses/2aa94170-2c57-4c4f-a1e7-13544ba72917
|
||||||
body: none
|
body: none
|
||||||
auth: inherit
|
auth: inherit
|
||||||
}
|
}
|
||||||
|
|
||||||
vars:pre-request {
|
|
||||||
resourceId: 1d6d2842-b271-489b-bd93-e3ceaee5a139
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ meta {
|
||||||
}
|
}
|
||||||
|
|
||||||
get {
|
get {
|
||||||
url: {{localBaseUrl}}/{{resourcePath}}
|
url: {{localBaseUrl}}/expenses
|
||||||
body: none
|
body: none
|
||||||
auth: inherit
|
auth: inherit
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
bruno/Common Cents/Expenses/LOC PATCH Expense Full.bru
Normal file
23
bruno/Common Cents/Expenses/LOC PATCH Expense Full.bru
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
meta {
|
||||||
|
name: LOC PATCH Expense Full
|
||||||
|
type: http
|
||||||
|
seq: 6
|
||||||
|
}
|
||||||
|
|
||||||
|
patch {
|
||||||
|
url: {{localBaseUrl}}/expenses/0708e7f7-3a2a-4b93-81da-38954925ca78
|
||||||
|
body: json
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"date": "2025-12-15",
|
||||||
|
"cents": 888,
|
||||||
|
"categoryId": "1",
|
||||||
|
"merchantId": "1",
|
||||||
|
"subcategoryIds": ["2"],
|
||||||
|
"tagIds": ["2"],
|
||||||
|
"description": "PATCHED Desc."
|
||||||
|
}
|
||||||
|
}
|
||||||
23
bruno/Common Cents/Expenses/LOC POST Expense Full.bru
Normal file
23
bruno/Common Cents/Expenses/LOC POST Expense Full.bru
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
meta {
|
||||||
|
name: LOC POST Expense Full
|
||||||
|
type: http
|
||||||
|
seq: 4
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
url: {{localBaseUrl}}/expenses
|
||||||
|
body: json
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"date": "2025-12-01",
|
||||||
|
"cents": 987,
|
||||||
|
"categoryId": "1",
|
||||||
|
"merchantId": "1",
|
||||||
|
"subcategoryIds": ["1","2"],
|
||||||
|
"tagIds": ["1","2"],
|
||||||
|
"description": "NEW FULL expense"
|
||||||
|
}
|
||||||
|
}
|
||||||
20
bruno/Common Cents/Expenses/LOC POST Expense Partial.bru
Normal file
20
bruno/Common Cents/Expenses/LOC POST Expense Partial.bru
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
meta {
|
||||||
|
name: LOC POST Expense Partial
|
||||||
|
type: http
|
||||||
|
seq: 5
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
url: {{localBaseUrl}}/expenses
|
||||||
|
body: json
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"date": "2025-12-01",
|
||||||
|
"cents": 987,
|
||||||
|
"categoryId": "1",
|
||||||
|
"description": "NEW PARTIAL expense"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
meta {
|
|
||||||
name: LOC POST Expense
|
|
||||||
type: http
|
|
||||||
seq: 3
|
|
||||||
}
|
|
||||||
|
|
||||||
post {
|
|
||||||
url: {{localBaseUrl}}/{{resourcePath}}
|
|
||||||
body: json
|
|
||||||
auth: inherit
|
|
||||||
}
|
|
||||||
|
|
||||||
body:json {
|
|
||||||
{
|
|
||||||
"year": "2026",
|
|
||||||
"month": "01",
|
|
||||||
"day": "02",
|
|
||||||
"cents": 1000,
|
|
||||||
"description": "With cat, subcat and merchant and two tags",
|
|
||||||
"category": {
|
|
||||||
"id": "a73fbfdd-1949-4be9-8cdc-ea9197b9b8b6"
|
|
||||||
},
|
|
||||||
"subCategory": {
|
|
||||||
"id": "270ceaea-9cb8-4c6a-846f-ea35ed4d12f7"
|
|
||||||
},
|
|
||||||
"merchant": {
|
|
||||||
"id": "61246db4-3110-4fe2-bdab-d819b8fd0705"
|
|
||||||
},
|
|
||||||
"tags": [
|
|
||||||
{
|
|
||||||
"id": "2616f724-f3ce-46df-8b30-897f147f6b74"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "16ed84e0-2d17-45c7-ada8-6fe7f8cc8720"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
meta {
|
|
||||||
name: LOC PUT Expense
|
|
||||||
type: http
|
|
||||||
seq: 4
|
|
||||||
}
|
|
||||||
|
|
||||||
put {
|
|
||||||
url: {{localBaseUrl}}/{{resourcePath}}
|
|
||||||
body: json
|
|
||||||
auth: inherit
|
|
||||||
}
|
|
||||||
|
|
||||||
body:json {
|
|
||||||
{
|
|
||||||
"id": "0254a07d-9dfa-4c06-b7b3-48d30efff991",
|
|
||||||
"description": "Cat, no sub-cat or merchant",
|
|
||||||
"category": {
|
|
||||||
"id": "db434e98-5f32-4202-b69c-eb7d1d248b3e"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +1,4 @@
|
||||||
meta {
|
meta {
|
||||||
name: Expenses
|
name: Expenses
|
||||||
}
|
seq: 2
|
||||||
|
|
||||||
auth {
|
|
||||||
mode: inherit
|
|
||||||
}
|
|
||||||
|
|
||||||
vars:pre-request {
|
|
||||||
resourcePath: expenses
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
meta {
|
meta {
|
||||||
name: Merchants
|
name: Merchants
|
||||||
seq: 3
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auth {
|
auth {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
meta {
|
meta {
|
||||||
name: Sub-categories
|
name: Sub-categories
|
||||||
seq: 4
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auth {
|
auth {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
meta {
|
meta {
|
||||||
name: Tags
|
name: Tags
|
||||||
seq: 5
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auth {
|
auth {
|
||||||
|
|
|
||||||
BIN
common-cents.db
Normal file
BIN
common-cents.db
Normal file
Binary file not shown.
|
|
@ -9,14 +9,12 @@ import { CategoriesModule } from './categories/categories.module';
|
||||||
import { Category } from './categories/entities/category.entity';
|
import { Category } from './categories/entities/category.entity';
|
||||||
import { SubCategoriesModule } from './sub-categories/sub-categories.module';
|
import { SubCategoriesModule } from './sub-categories/sub-categories.module';
|
||||||
import { SubCategory } from './sub-categories/entities/sub-category.entity';
|
import { SubCategory } from './sub-categories/entities/sub-category.entity';
|
||||||
import { ExpensesModule } from './expenses/expenses.module';
|
|
||||||
import { Expense } from './expenses/entities/expense.entity';
|
|
||||||
|
|
||||||
const sqliteConfig: TypeOrmModuleOptions = {
|
const sqliteConfig: TypeOrmModuleOptions = {
|
||||||
synchronize: true, // typeorm -h (schema:sync)
|
synchronize: true, // typeorm -h (schema:sync)
|
||||||
type: 'sqlite',
|
type: 'sqlite',
|
||||||
database: 'common-cents.db',
|
database: 'common-cents.db',
|
||||||
entities: [Merchant, Tag, Category, SubCategory, Expense]
|
entities: [Merchant, Tag, Category, SubCategory]
|
||||||
}
|
}
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
|
|
@ -25,8 +23,7 @@ const sqliteConfig: TypeOrmModuleOptions = {
|
||||||
MerchantsModule,
|
MerchantsModule,
|
||||||
TagsModule,
|
TagsModule,
|
||||||
CategoriesModule,
|
CategoriesModule,
|
||||||
SubCategoriesModule,
|
SubCategoriesModule
|
||||||
ExpensesModule
|
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: []
|
providers: []
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,6 @@ export class Category {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
@Column({ unique: true })
|
@Column()
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
import { Category } from '../../categories/entities/category.entity';
|
|
||||||
|
|
||||||
export class CreateExpenseDto {
|
|
||||||
year: string;
|
|
||||||
month: string;
|
|
||||||
day: string;
|
|
||||||
cents: number;
|
|
||||||
description: string;
|
|
||||||
category: Category
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
import { PartialType } from '@nestjs/mapped-types';
|
|
||||||
import { CreateExpenseDto } from './create-expense.dto';
|
|
||||||
|
|
||||||
export class UpdateExpenseDto extends PartialType(CreateExpenseDto) {
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
import { Column, Entity, JoinTable, ManyToMany, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
|
||||||
import { Tag } from '../../tags/entities/tag.entity';
|
|
||||||
import { SubCategory } from '../../sub-categories/entities/sub-category.entity';
|
|
||||||
import { Category } from '../../categories/entities/category.entity';
|
|
||||||
import { Merchant } from '../../merchants/entities/merchant.entity';
|
|
||||||
|
|
||||||
@Entity()
|
|
||||||
export class Expense {
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@Column()
|
|
||||||
year: string;
|
|
||||||
|
|
||||||
@Column()
|
|
||||||
month: string;
|
|
||||||
|
|
||||||
@Column()
|
|
||||||
day: string;
|
|
||||||
|
|
||||||
@Column()
|
|
||||||
cents: number;
|
|
||||||
|
|
||||||
@Column({ nullable: true })
|
|
||||||
description: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => Category, { eager: true })
|
|
||||||
category: Category;
|
|
||||||
|
|
||||||
@ManyToOne(() => SubCategory, { nullable: true, eager: true })
|
|
||||||
subCategory: SubCategory;
|
|
||||||
|
|
||||||
@ManyToOne(() => Merchant, { nullable: true, eager: true })
|
|
||||||
merchant: Merchant;
|
|
||||||
|
|
||||||
@ManyToMany(() => Tag, { nullable: true, eager: true })
|
|
||||||
@JoinTable()
|
|
||||||
tags: Tag[];
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { DataSource, Repository } from 'typeorm';
|
|
||||||
import { Expense } from './entities/expense.entity';
|
|
||||||
import { UpdateExpenseDto } from './dto/update-expense.dto';
|
|
||||||
import { CreateExpenseDto } from './dto/create-expense.dto';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class ExpenseDataService {
|
|
||||||
private expenses: Repository<Expense>;
|
|
||||||
|
|
||||||
public constructor(private dataSource: DataSource) {
|
|
||||||
this.expenses = this.dataSource.getRepository(Expense);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getAll(): Promise<Expense[]> {
|
|
||||||
return await this.expenses.find();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getById(id: string): Promise<Expense | null> {
|
|
||||||
return await this.expenses.findOneBy({ id });
|
|
||||||
}
|
|
||||||
|
|
||||||
public async create(expense: CreateExpenseDto): Promise<Expense> {
|
|
||||||
return await this.expenses.save(expense);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async update(expense: UpdateExpenseDto): Promise<Expense> {
|
|
||||||
return await this.expenses.save(expense);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async delete(id: string): Promise<void> {
|
|
||||||
await this.expenses.delete({ id });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
import {
|
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
Post,
|
|
||||||
Put,
|
|
||||||
Delete,
|
|
||||||
Body,
|
|
||||||
Param,
|
|
||||||
HttpCode,
|
|
||||||
HttpStatus,
|
|
||||||
BadRequestException,
|
|
||||||
NotFoundException,
|
|
||||||
InternalServerErrorException
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { ExpensesService } from './expenses.service';
|
|
||||||
import { CreateExpenseDto } from './dto/create-expense.dto';
|
|
||||||
import { UpdateExpenseDto } from './dto/update-expense.dto';
|
|
||||||
import { Expense } from './entities/expense.entity';
|
|
||||||
|
|
||||||
@Controller('expenses')
|
|
||||||
export class ExpensesController {
|
|
||||||
constructor(private readonly expensesService: ExpensesService) { }
|
|
||||||
|
|
||||||
@Get()
|
|
||||||
@HttpCode(HttpStatus.OK)
|
|
||||||
public async findAll(): Promise<Expense[]> {
|
|
||||||
return await this.expensesService.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id')
|
|
||||||
@HttpCode(HttpStatus.OK)
|
|
||||||
public async findOne(@Param('id') id: string): Promise<Expense> {
|
|
||||||
if (!id) {
|
|
||||||
throw new BadRequestException('No ID provided.');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return await this.expensesService.findById(id);
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
throw new NotFoundException(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post()
|
|
||||||
@HttpCode(HttpStatus.CREATED)
|
|
||||||
public async create(@Body() expense: CreateExpenseDto): Promise<Expense> {
|
|
||||||
if (!expense) {
|
|
||||||
throw new BadRequestException('Expense name cannot be empty.');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return await this.expensesService.create(expense);
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
throw new InternalServerErrorException(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Put()
|
|
||||||
@HttpCode(HttpStatus.OK)
|
|
||||||
public async update(@Body() expense: UpdateExpenseDto): Promise<Expense> {
|
|
||||||
if (!expense.id) {
|
|
||||||
throw new BadRequestException('Expense ID cannot be empty.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return await this.expensesService.update(expense);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete(':id')
|
|
||||||
@HttpCode(HttpStatus.NO_CONTENT)
|
|
||||||
public async remove(@Param('id') id: string): Promise<void> {
|
|
||||||
return await this.expensesService.remove(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { ExpensesService } from './expenses.service';
|
|
||||||
import { ExpensesController } from './expenses.controller';
|
|
||||||
import { ExpenseDataService } from './expense-data.service';
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
controllers: [ExpensesController],
|
|
||||||
providers: [ExpensesService, ExpenseDataService],
|
|
||||||
})
|
|
||||||
export class ExpensesModule { }
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { CreateExpenseDto } from './dto/create-expense.dto';
|
|
||||||
import { UpdateExpenseDto } from './dto/update-expense.dto';
|
|
||||||
import { ExpenseDataService } from './expense-data.service';
|
|
||||||
import { Expense } from './entities/expense.entity';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class ExpensesService {
|
|
||||||
public constructor(private expenseDataService: ExpenseDataService) { }
|
|
||||||
|
|
||||||
public async findAll(): Promise<Expense[]> {
|
|
||||||
return await this.expenseDataService.getAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async findById(id: string): Promise<Expense> {
|
|
||||||
const expense = await this.expenseDataService.getById(id);
|
|
||||||
if (!expense) {
|
|
||||||
throw new Error('No expense found');
|
|
||||||
}
|
|
||||||
|
|
||||||
return expense;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async create(expense: CreateExpenseDto): Promise<Expense> {
|
|
||||||
return await this.expenseDataService.create(expense);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async update(expense: UpdateExpenseDto): Promise<Expense> {
|
|
||||||
return await this.expenseDataService.update(expense);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async remove(id: string): Promise<void> {
|
|
||||||
await this.expenseDataService.delete(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -5,6 +5,6 @@ export class Merchant {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
@Column({ unique: true })
|
@Column()
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,6 @@ export class SubCategory {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
@Column({ unique: true })
|
@Column()
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,6 @@ export class Tag {
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
@Column({ unique: true })
|
@Column()
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue