removed sub-categories
This commit is contained in:
parent
b7acc9e352
commit
fdf0efd17f
22 changed files with 71 additions and 295 deletions
|
|
@ -12,6 +12,6 @@ post {
|
||||||
|
|
||||||
body:json {
|
body:json {
|
||||||
{
|
{
|
||||||
"name": "First Cat"
|
"name": "Household:Supplies"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,25 +14,28 @@ body:json {
|
||||||
{
|
{
|
||||||
"year": "2026",
|
"year": "2026",
|
||||||
"month": "01",
|
"month": "01",
|
||||||
"day": "02",
|
"day": "03",
|
||||||
"cents": 1000,
|
"cents": 1234,
|
||||||
"description": "With cat, no subcat or merchant or tags",
|
"note": "Additional Expense Test",
|
||||||
"category": {
|
"category": {
|
||||||
"id": "72644e00-f1fa-4029-bd9c-2e82eb965aeb"
|
"id": "96db93d8-2f7e-462c-b520-8754a5900253"
|
||||||
}
|
},
|
||||||
// "subCategory": {
|
"merchant": {
|
||||||
// "id": "270ceaea-9cb8-4c6a-846f-ea35ed4d12f7"
|
"id": "9afbe4fd-9077-473a-9d08-f5fb4c8f692f"
|
||||||
// },
|
},
|
||||||
// "merchant": {
|
"tags": [
|
||||||
// "id": "61246db4-3110-4fe2-bdab-d819b8fd0705"
|
{
|
||||||
// },
|
"id": "db6d60d9-66e1-4005-a5a3-1e165812aa3c",
|
||||||
// "tags": [
|
"name": "Tag One"
|
||||||
// {
|
},
|
||||||
// "id": "2616f724-f3ce-46df-8b30-897f147f6b74"
|
{
|
||||||
// },
|
"id": "999a8e68-5232-43e0-adf5-98af75aa01ba",
|
||||||
// {
|
"name": "Tag Two"
|
||||||
// "id": "16ed84e0-2d17-45c7-ada8-6fe7f8cc8720"
|
},
|
||||||
// }
|
{
|
||||||
// ]
|
"id": "619d5c95-65fc-4795-8828-ee1adfe289f8",
|
||||||
|
"name": "Tag Three"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
meta {
|
meta {
|
||||||
name: Expenses
|
name: Expenses
|
||||||
|
seq: 3
|
||||||
}
|
}
|
||||||
|
|
||||||
auth {
|
auth {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
meta {
|
meta {
|
||||||
name: Health
|
name: Healthcheck
|
||||||
type: http
|
type: http
|
||||||
seq: 1
|
seq: 1
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
meta {
|
meta {
|
||||||
name: Merchants
|
name: Merchants
|
||||||
seq: 3
|
seq: 4
|
||||||
}
|
}
|
||||||
|
|
||||||
auth {
|
auth {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
meta {
|
|
||||||
name: LOC DELETE Sub-category
|
|
||||||
type: http
|
|
||||||
seq: 5
|
|
||||||
}
|
|
||||||
|
|
||||||
delete {
|
|
||||||
url: {{localBaseUrl}}/{{resourcePath}}/{{resourceId}}
|
|
||||||
body: none
|
|
||||||
auth: inherit
|
|
||||||
}
|
|
||||||
|
|
||||||
vars:pre-request {
|
|
||||||
resourceId: cbf30070-9ff7-419f-a567-f7d145be445b
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
meta {
|
|
||||||
name: LOC GET Sub-categories
|
|
||||||
type: http
|
|
||||||
seq: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
get {
|
|
||||||
url: {{localBaseUrl}}/{{resourcePath}}
|
|
||||||
body: none
|
|
||||||
auth: inherit
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
meta {
|
|
||||||
name: LOC GET Sub-category By ID
|
|
||||||
type: http
|
|
||||||
seq: 2
|
|
||||||
}
|
|
||||||
|
|
||||||
get {
|
|
||||||
url: {{localBaseUrl}}/{{resourcePath}}/{{resourceId}}
|
|
||||||
body: none
|
|
||||||
auth: inherit
|
|
||||||
}
|
|
||||||
|
|
||||||
vars:pre-request {
|
|
||||||
resourceId: 1d6d2842-b271-489b-bd93-e3ceaee5a139
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
meta {
|
|
||||||
name: LOC POST Sub-category
|
|
||||||
type: http
|
|
||||||
seq: 3
|
|
||||||
}
|
|
||||||
|
|
||||||
post {
|
|
||||||
url: {{localBaseUrl}}/{{resourcePath}}
|
|
||||||
body: json
|
|
||||||
auth: inherit
|
|
||||||
}
|
|
||||||
|
|
||||||
body:json {
|
|
||||||
{
|
|
||||||
"name": "Sub-category Three"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
meta {
|
|
||||||
name: LOC PUT Sub-category
|
|
||||||
type: http
|
|
||||||
seq: 4
|
|
||||||
}
|
|
||||||
|
|
||||||
put {
|
|
||||||
url: {{localBaseUrl}}/{{resourcePath}}
|
|
||||||
body: json
|
|
||||||
auth: inherit
|
|
||||||
}
|
|
||||||
|
|
||||||
body:json {
|
|
||||||
{
|
|
||||||
"id": "1d6d2842-b271-489b-bd93-e3ceaee5a139",
|
|
||||||
"name": "Merchant One"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
meta {
|
|
||||||
name: Sub-categories
|
|
||||||
seq: 4
|
|
||||||
}
|
|
||||||
|
|
||||||
auth {
|
|
||||||
mode: inherit
|
|
||||||
}
|
|
||||||
|
|
||||||
vars:pre-request {
|
|
||||||
resourcePath: sub-categories
|
|
||||||
}
|
|
||||||
|
|
@ -4,7 +4,6 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { MerchantsModule } from './merchants/merchants.module';
|
import { MerchantsModule } from './merchants/merchants.module';
|
||||||
import { TagsModule } from './tags/tags.module';
|
import { TagsModule } from './tags/tags.module';
|
||||||
import { CategoriesModule } from './categories/categories.module';
|
import { CategoriesModule } from './categories/categories.module';
|
||||||
import { SubCategoriesModule } from './sub-categories/sub-categories.module';
|
|
||||||
import { ExpensesModule } from './expenses/expenses.module';
|
import { ExpensesModule } from './expenses/expenses.module';
|
||||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||||
|
|
||||||
|
|
@ -37,7 +36,6 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||||
MerchantsModule,
|
MerchantsModule,
|
||||||
TagsModule,
|
TagsModule,
|
||||||
CategoriesModule,
|
CategoriesModule,
|
||||||
SubCategoriesModule,
|
|
||||||
ExpensesModule
|
ExpensesModule
|
||||||
],
|
],
|
||||||
controllers: [HealthcheckController]
|
controllers: [HealthcheckController]
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,47 @@
|
||||||
import { Category } from '../../categories/entities/category.entity';
|
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 {
|
export class CreateExpenseDto {
|
||||||
|
@ApiProperty({
|
||||||
|
description: '4-digit year of expense'
|
||||||
|
})
|
||||||
year: string;
|
year: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: '2-digit month of expense'
|
||||||
|
})
|
||||||
month: string;
|
month: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: '2-digit day of expense'
|
||||||
|
})
|
||||||
day: string;
|
day: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'Amount of expense in cents'
|
||||||
|
})
|
||||||
cents: number;
|
cents: number;
|
||||||
description: string;
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'Category of expense'
|
||||||
|
})
|
||||||
category: Category
|
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[];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
import { PartialType } from '@nestjs/mapped-types';
|
|
||||||
import { CreateExpenseDto } from './create-expense.dto';
|
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;
|
id: string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { Column, Entity, JoinTable, ManyToMany, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
import { Column, Entity, JoinTable, ManyToMany, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
import { Tag } from '../../tags/entities/tag.entity';
|
import { Tag } from '../../tags/entities/tag.entity';
|
||||||
import { SubCategory } from '../../sub-categories/entities/sub-category.entity';
|
|
||||||
import { Category } from '../../categories/entities/category.entity';
|
import { Category } from '../../categories/entities/category.entity';
|
||||||
import { Merchant } from '../../merchants/entities/merchant.entity';
|
import { Merchant } from '../../merchants/entities/merchant.entity';
|
||||||
|
|
||||||
|
|
@ -21,14 +20,11 @@ export class Expense {
|
||||||
@Column()
|
@Column()
|
||||||
cents: number;
|
cents: number;
|
||||||
|
|
||||||
@Column({ nullable: true })
|
|
||||||
description: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => Category, { eager: true })
|
@ManyToOne(() => Category, { eager: true })
|
||||||
category: Category;
|
category: Category;
|
||||||
|
|
||||||
@ManyToOne(() => SubCategory, { nullable: true, eager: true })
|
@Column({ nullable: true })
|
||||||
subCategory: SubCategory;
|
note: string;
|
||||||
|
|
||||||
@ManyToOne(() => Merchant, { nullable: true, eager: true })
|
@ManyToOne(() => Merchant, { nullable: true, eager: true })
|
||||||
merchant: Merchant;
|
merchant: Merchant;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
export class CreateSubCategoryDto {
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
export class UpdateSubCategoryDto {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
||||||
|
|
||||||
@Entity()
|
|
||||||
export class SubCategory {
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@Column({ unique: true })
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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 { }
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue