removed sub-categories

This commit is contained in:
Joe Arndt 2026-02-13 11:47:12 -06:00
parent b7acc9e352
commit fdf0efd17f
22 changed files with 71 additions and 295 deletions

View file

@ -4,7 +4,6 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { MerchantsModule } from './merchants/merchants.module';
import { TagsModule } from './tags/tags.module';
import { CategoriesModule } from './categories/categories.module';
import { SubCategoriesModule } from './sub-categories/sub-categories.module';
import { ExpensesModule } from './expenses/expenses.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
@ -37,7 +36,6 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
MerchantsModule,
TagsModule,
CategoriesModule,
SubCategoriesModule,
ExpensesModule
],
controllers: [HealthcheckController]

View file

@ -1,10 +1,47 @@
import { Category } from '../../categories/entities/category.entity';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Merchant } from '../../merchants/entities/merchant.entity';
import { Tag } from '../../tags/entities/tag.entity';
export class CreateExpenseDto {
@ApiProperty({
description: '4-digit year of expense'
})
year: string;
@ApiProperty({
description: '2-digit month of expense'
})
month: string;
@ApiProperty({
description: '2-digit day of expense'
})
day: string;
@ApiProperty({
description: 'Amount of expense in cents'
})
cents: number;
description: string;
@ApiProperty({
description: 'Category of expense'
})
category: Category
@ApiPropertyOptional({
description: 'Optional note about expense'
})
note?: string;
@ApiPropertyOptional({
description: 'Optional merchant for the expense'
})
merchant?: Merchant;
@ApiPropertyOptional({
type: [Tag],
description: 'Optional list of tags for the expense'
})
tags?: Tag[];
}

View file

@ -1,6 +1,9 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateExpenseDto } from './create-expense.dto';
import { ApiProperty } from '@nestjs/swagger';
export class UpdateExpenseDto extends PartialType(CreateExpenseDto) {
export class UpdateExpenseDto extends CreateExpenseDto {
@ApiProperty({
description: 'UUID of the expense'
})
id: string;
}

View file

@ -1,6 +1,5 @@
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';
@ -21,14 +20,11 @@ export class Expense {
@Column()
cents: number;
@Column({ nullable: true })
description: string;
@ManyToOne(() => Category, { eager: true })
category: Category;
@ManyToOne(() => SubCategory, { nullable: true, eager: true })
subCategory: SubCategory;
@Column({ nullable: true })
note: string;
@ManyToOne(() => Merchant, { nullable: true, eager: true })
merchant: Merchant;

View file

@ -1,3 +0,0 @@
export class CreateSubCategoryDto {
name: string;
}

View file

@ -1,4 +0,0 @@
export class UpdateSubCategoryDto {
id: string;
name: string;
}

View file

@ -1,10 +0,0 @@
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class SubCategory {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ unique: true })
name: string;
}

View file

@ -1,75 +0,0 @@
import {
Controller,
Get,
Post,
Put,
Delete,
Body,
Param,
HttpCode,
HttpStatus,
BadRequestException,
NotFoundException,
InternalServerErrorException
} from '@nestjs/common';
import { SubCategoriesService } from './sub-categories.service';
import { CreateSubCategoryDto } from './dto/create-sub-category.dto';
import { UpdateSubCategoryDto } from './dto/update-sub-category.dto';
import { SubCategory } from './entities/sub-category.entity';
@Controller('sub-categories')
export class SubCategoriesController {
constructor(private readonly subCategoriesService: SubCategoriesService) { }
@Get()
@HttpCode(HttpStatus.OK)
public async findAll(): Promise<SubCategory[]> {
return await this.subCategoriesService.findAll();
}
@Get(':id')
@HttpCode(HttpStatus.OK)
public async findOne(@Param('id') id: string): Promise<SubCategory> {
if (!id) {
throw new BadRequestException('No ID provided.');
}
try {
return await this.subCategoriesService.findById(id);
}
catch (error) {
throw new NotFoundException(error);
}
}
@Post()
@HttpCode(HttpStatus.CREATED)
public async create(@Body() subCategory: CreateSubCategoryDto): Promise<SubCategory> {
if (!subCategory.name) {
throw new BadRequestException('Sub-category name cannot be empty.');
}
try {
return await this.subCategoriesService.create(subCategory);
}
catch (error) {
throw new InternalServerErrorException(error);
}
}
@Put()
@HttpCode(HttpStatus.OK)
public async update(@Body() subCategory: UpdateSubCategoryDto): Promise<SubCategory> {
if (!subCategory.id) {
throw new BadRequestException('Sub-category ID cannot be empty.');
}
return await this.subCategoriesService.update(subCategory);
}
@Delete(':id')
@HttpCode(HttpStatus.NO_CONTENT)
public async remove(@Param('id') id: string): Promise<void> {
return await this.subCategoriesService.remove(id);
}
}

View file

@ -1,14 +0,0 @@
import { Module } from '@nestjs/common';
import { SubCategoriesService } from './sub-categories.service';
import { SubCategoriesController } from './sub-categories.controller';
import { SubCategoryDataService } from './sub-category-data.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { SubCategory } from './entities/sub-category.entity';
@Module({
controllers: [SubCategoriesController],
providers: [SubCategoriesService, SubCategoryDataService],
imports: [TypeOrmModule.forFeature([SubCategory])],
exports: [TypeOrmModule]
})
export class SubCategoriesModule { }

View file

@ -1,35 +0,0 @@
import { Injectable } from '@nestjs/common';
import { CreateSubCategoryDto } from './dto/create-sub-category.dto';
import { UpdateSubCategoryDto } from './dto/update-sub-category.dto';
import { SubCategoryDataService } from './sub-category-data.service';
import { SubCategory } from './entities/sub-category.entity';
@Injectable()
export class SubCategoriesService {
public constructor(private subCategoryDataService: SubCategoryDataService) { }
public async findAll(): Promise<SubCategory[]> {
return await this.subCategoryDataService.getAll();
}
public async findById(id: string): Promise<SubCategory> {
const subCategory = await this.subCategoryDataService.getById(id);
if (!subCategory) {
throw new Error('No sub-category found');
}
return subCategory;
}
public async create(subCategory: CreateSubCategoryDto): Promise<SubCategory> {
return await this.subCategoryDataService.create(subCategory.name);
}
public async update(subCategory: UpdateSubCategoryDto): Promise<SubCategory> {
return await this.subCategoryDataService.update(subCategory);
}
public async remove(id: string): Promise<void> {
await this.subCategoryDataService.delete(id);
}
}

View file

@ -1,33 +0,0 @@
import { Injectable } from '@nestjs/common';
import { DataSource, Repository } from 'typeorm';
import { SubCategory } from './entities/sub-category.entity';
import { UpdateSubCategoryDto } from './dto/update-sub-category.dto';
@Injectable()
export class SubCategoryDataService {
private subCategories: Repository<SubCategory>;
public constructor(private dataSource: DataSource) {
this.subCategories = this.dataSource.getRepository(SubCategory);
}
public async getAll(): Promise<SubCategory[]> {
return await this.subCategories.find();
}
public async getById(id: string): Promise<SubCategory | null> {
return await this.subCategories.findOneBy({ id });
}
public async create(name: string): Promise<SubCategory> {
return await this.subCategories.save({ name });
}
public async update(subCategory: UpdateSubCategoryDto): Promise<SubCategory> {
return await this.subCategories.save(subCategory);
}
public async delete(id: string): Promise<void> {
await this.subCategories.delete({ id });
}
}