import { Column, CreateDateColumn, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm'; import type { Relation } from 'typeorm'; import { Category } from './Category.js'; import { Expense } from './Expense.js'; import { dateTimeColumnType } from '../utils/db-column-types.js'; export type UserRole = 'ADMIN' | 'USER'; @Entity('users') export class User { @PrimaryGeneratedColumn('uuid') id!: string; @Column({ type: 'varchar', length: 120 }) fullName!: string; @Column({ type: 'varchar', unique: true, length: 160 }) email!: string; @Column({ type: 'varchar', length: 255 }) passwordHash!: string; @Column({ type: 'varchar', length: 20, default: 'USER' }) role!: UserRole; @Column({ type: 'boolean', default: true }) isActive!: boolean; @Column({ type: 'varchar', length: 8, default: 'PLN' }) defaultCurrency!: string; @Column({ type: 'simple-json', nullable: true }) reportPreferences!: { enabled?: boolean; frequency?: 'monthly' | 'yearly' | 'threshold'; thresholdAmount?: number; sendToEmail?: string | null; categoryIds?: string[]; } | null; @Column({ type: 'simple-json', nullable: true }) shoppingListIntegration!: { enabled?: boolean; baseUrl?: string; apiToken?: string; authMode?: 'bearer' | 'x-api-token' | 'both'; ownerId?: string | null; defaultListId?: string | null; } | null; @CreateDateColumn({ type: dateTimeColumnType }) createdAt!: Date; @OneToMany(() => Category, (category) => category.user) categories!: Relation; @OneToMany(() => Expense, (expense) => expense.user) expenses!: Relation; }