mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-03-10 20:51:44 +00:00
61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
import {
|
|
BaseEntity,
|
|
Column,
|
|
CreateDateColumn,
|
|
Entity,
|
|
JoinColumn,
|
|
ManyToOne,
|
|
OneToMany,
|
|
PrimaryGeneratedColumn,
|
|
UpdateDateColumn,
|
|
} from 'typeorm';
|
|
import { Guardian } from '~/guardian/entities/guradian.entity';
|
|
import { Junior } from '~/junior/entities';
|
|
import { AllowanceFrequency, AllowanceScheduleStatus } from '../enums';
|
|
import { AllowanceCredit } from './allowance-credit.entity';
|
|
|
|
@Entity('allowance_schedules')
|
|
export class AllowanceSchedule extends BaseEntity {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id!: string;
|
|
|
|
@Column({ type: 'decimal', precision: 12, scale: 2, name: 'amount' })
|
|
amount!: number;
|
|
|
|
@Column({ type: 'varchar', name: 'frequency' })
|
|
frequency!: AllowanceFrequency;
|
|
|
|
@Column({ type: 'varchar', name: 'status', default: AllowanceScheduleStatus.ON })
|
|
status!: AllowanceScheduleStatus;
|
|
|
|
@Column({ type: 'timestamp with time zone', name: 'next_run_at' })
|
|
nextRunAt!: Date;
|
|
|
|
@Column({ type: 'timestamp with time zone', name: 'last_run_at', nullable: true })
|
|
lastRunAt!: Date | null;
|
|
|
|
@CreateDateColumn({ type: 'timestamp with time zone', default: () => 'CURRENT_TIMESTAMP', name: 'created_at' })
|
|
createdAt!: Date;
|
|
|
|
@UpdateDateColumn({ type: 'timestamp with time zone', default: () => 'CURRENT_TIMESTAMP', name: 'updated_at' })
|
|
updatedAt!: Date;
|
|
|
|
@Column({ type: 'uuid', name: 'guardian_id' })
|
|
guardianId!: string;
|
|
|
|
@ManyToOne(() => Guardian, (guardian) => guardian.allowanceSchedules, { onDelete: 'CASCADE' })
|
|
@JoinColumn({ name: 'guardian_id' })
|
|
guardian!: Guardian;
|
|
|
|
@Column({ type: 'uuid', name: 'junior_id' })
|
|
juniorId!: string;
|
|
|
|
@ManyToOne(() => Junior, (junior) => junior.allowanceSchedules, { onDelete: 'CASCADE' })
|
|
@JoinColumn({ name: 'junior_id' })
|
|
junior!: Junior;
|
|
|
|
@OneToMany(() => AllowanceCredit, (credit) => credit.schedule)
|
|
credits!: AllowanceCredit[];
|
|
|
|
}
|