81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
|
|
import type { Relation } from 'typeorm';
|
|
import { Category } from './Category.js';
|
|
import { User } from './User.js';
|
|
import { decimalTransformer } from '../utils/decimal.js';
|
|
import { dateTimeColumnType } from '../utils/db-column-types.js';
|
|
|
|
export type RecurringFrequency = 'WEEKLY' | 'MONTHLY' | 'YEARLY';
|
|
|
|
@Entity('recurring_expenses')
|
|
export class RecurringExpense {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id!: string;
|
|
|
|
@Column({ type: 'varchar', length: 140 })
|
|
title!: string;
|
|
|
|
@Column({ type: 'text', nullable: true })
|
|
description!: string | null;
|
|
|
|
@Column({ type: 'decimal', precision: 12, scale: 2, transformer: decimalTransformer })
|
|
amount!: number;
|
|
|
|
@Column({ type: 'varchar', length: 80, nullable: true })
|
|
merchant!: string | null;
|
|
|
|
@Column({ type: 'varchar', length: 50, nullable: true })
|
|
paymentMethod!: string | null;
|
|
|
|
@Column({ type: 'varchar', length: 12, default: 'PLN' })
|
|
currency!: string;
|
|
|
|
@Column({ type: 'varchar', length: 20, default: 'MONTHLY' })
|
|
frequency!: RecurringFrequency;
|
|
|
|
@Column({ type: 'int', default: 1 })
|
|
intervalValue!: number;
|
|
|
|
@Column({ type: 'date' })
|
|
startDate!: string;
|
|
|
|
@Column({ type: 'date' })
|
|
nextRunDate!: string;
|
|
|
|
@Column({ type: 'date', nullable: true })
|
|
lastRunDate!: string | null;
|
|
|
|
@Column({ type: 'date', nullable: true })
|
|
endDate!: string | null;
|
|
|
|
@Column({ type: 'int', nullable: true })
|
|
maxOccurrences!: number | null;
|
|
|
|
@Column({ type: 'int', default: 0 })
|
|
generatedCount!: number;
|
|
|
|
@Column({ type: 'varchar', length: 20, default: 'PENDING' })
|
|
defaultStatus!: string;
|
|
|
|
@Column({ type: 'simple-json', nullable: true })
|
|
tags!: string[] | null;
|
|
|
|
@Column({ type: 'simple-json', nullable: true })
|
|
customFields!: Record<string, string> | null;
|
|
|
|
@Column({ type: 'boolean', default: true })
|
|
isActive!: boolean;
|
|
|
|
@CreateDateColumn({ type: dateTimeColumnType })
|
|
createdAt!: Date;
|
|
|
|
@UpdateDateColumn({ type: dateTimeColumnType })
|
|
updatedAt!: Date;
|
|
|
|
@ManyToOne(() => User, { onDelete: 'CASCADE' })
|
|
user!: Relation<User>;
|
|
|
|
@ManyToOne(() => Category, { eager: true, onDelete: 'RESTRICT' })
|
|
category!: Relation<Category>;
|
|
}
|