fix docker build
This commit is contained in:
@@ -3,6 +3,7 @@ import fs from 'node:fs';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import process from 'node:process';
|
import process from 'node:process';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import { createRequire } from 'node:module';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { AppDataSource } from '../config/data-source.js';
|
import { AppDataSource } from '../config/data-source.js';
|
||||||
import { env } from '../config/env.js';
|
import { env } from '../config/env.js';
|
||||||
@@ -38,42 +39,53 @@ const userUpdateSchema = z.object({
|
|||||||
defaultCurrency: z.string().min(3).max(8).optional()
|
defaultCurrency: z.string().min(3).max(8).optional()
|
||||||
});
|
});
|
||||||
|
|
||||||
type PackageJson = { version?: string };
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
const readPackageJsonSafe = (filePath: string | null): PackageJson | null => {
|
type PackageLike = { version?: string };
|
||||||
if (!filePath || !fs.existsSync(filePath)) return null;
|
|
||||||
|
|
||||||
|
function readPackageJsonSafe(filePath: string): PackageLike | null {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(fs.readFileSync(filePath, 'utf8')) as PackageJson;
|
if (!fs.existsSync(filePath)) return null;
|
||||||
|
return JSON.parse(fs.readFileSync(filePath, 'utf8')) as PackageLike;
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const findNearestPackageJson = (startDir: string): string | null => {
|
|
||||||
let currentDir = path.resolve(startDir);
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
const candidate = path.join(currentDir, 'package.json');
|
|
||||||
if (fs.existsSync(candidate)) return candidate;
|
|
||||||
|
|
||||||
const parentDir = path.dirname(currentDir);
|
|
||||||
if (parentDir == currentDir) return null;
|
|
||||||
currentDir = parentDir;
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const apiPackagePath = findNearestPackageJson(__dirname);
|
function findApiPackage(): PackageLike | null {
|
||||||
const apiPackage = readPackageJsonSafe(apiPackagePath);
|
return (
|
||||||
const apiRootDir = apiPackagePath ? path.dirname(apiPackagePath) : null;
|
readPackageJsonSafe(path.resolve(__dirname, '../../package.json')) ??
|
||||||
const projectRootPackagePath = apiRootDir ? findNearestPackageJson(path.dirname(apiRootDir)) : null;
|
readPackageJsonSafe(path.resolve(__dirname, '../package.json'))
|
||||||
const rootPackage = readPackageJsonSafe(projectRootPackagePath);
|
|
||||||
const webPackage = readPackageJsonSafe(
|
|
||||||
projectRootPackagePath ? path.join(path.dirname(projectRootPackagePath), 'web', 'package.json') : null
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function findRootPackage(): PackageLike | null {
|
||||||
|
const candidates = [
|
||||||
|
path.resolve(__dirname, '../../../package.json'),
|
||||||
|
path.resolve(__dirname, '../../package.json'),
|
||||||
|
path.resolve(__dirname, '../package.json')
|
||||||
|
];
|
||||||
|
for (const candidate of candidates) {
|
||||||
|
const pkg = readPackageJsonSafe(candidate);
|
||||||
|
if (!pkg) continue;
|
||||||
|
if (candidate.endsWith('/api/package.json') || candidate.endsWith('\\api\\package.json')) continue;
|
||||||
|
return pkg;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function findWebPackage(): PackageLike | null {
|
||||||
|
return (
|
||||||
|
readPackageJsonSafe(path.resolve(__dirname, '../../../web/package.json')) ??
|
||||||
|
readPackageJsonSafe(path.resolve(__dirname, '../../web/package.json'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rootPackage = findRootPackage();
|
||||||
|
const apiPackage = findApiPackage();
|
||||||
|
const webPackage = findWebPackage();
|
||||||
|
|
||||||
const settingsRepo = () => AppDataSource.getRepository(AppSetting);
|
const settingsRepo = () => AppDataSource.getRepository(AppSetting);
|
||||||
const userRepo = () => AppDataSource.getRepository(User);
|
const userRepo = () => AppDataSource.getRepository(User);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
|
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
|
||||||
|
import type { Relation } from 'typeorm';
|
||||||
import { Category } from './Category.js';
|
import { Category } from './Category.js';
|
||||||
import { User } from './User.js';
|
import { User } from './User.js';
|
||||||
import { decimalTransformer } from '../utils/decimal.js';
|
import { decimalTransformer } from '../utils/decimal.js';
|
||||||
@@ -31,8 +32,8 @@ export class Budget {
|
|||||||
updatedAt!: Date;
|
updatedAt!: Date;
|
||||||
|
|
||||||
@ManyToOne(() => User, { onDelete: 'CASCADE' })
|
@ManyToOne(() => User, { onDelete: 'CASCADE' })
|
||||||
user!: User;
|
user!: Relation<User>;
|
||||||
|
|
||||||
@ManyToOne(() => Category, { eager: true, nullable: true, onDelete: 'SET NULL' })
|
@ManyToOne(() => Category, { eager: true, nullable: true, onDelete: 'SET NULL' })
|
||||||
category!: Category | null;
|
category!: Relation<Category> | null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
import { Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
import type { Relation } from 'typeorm';
|
||||||
import { Expense } from './Expense.js';
|
import { Expense } from './Expense.js';
|
||||||
import { User } from './User.js';
|
import { User } from './User.js';
|
||||||
import { dateTimeColumnType } from '../utils/db-column-types.js';
|
import { dateTimeColumnType } from '../utils/db-column-types.js';
|
||||||
@@ -21,8 +22,8 @@ export class Category {
|
|||||||
createdAt!: Date;
|
createdAt!: Date;
|
||||||
|
|
||||||
@ManyToOne(() => User, (user) => user.categories, { nullable: true, onDelete: 'CASCADE' })
|
@ManyToOne(() => User, (user) => user.categories, { nullable: true, onDelete: 'CASCADE' })
|
||||||
user!: User | null;
|
user!: Relation<User> | null;
|
||||||
|
|
||||||
@OneToMany(() => Expense, (expense) => expense.category)
|
@OneToMany(() => Expense, (expense) => expense.category)
|
||||||
expenses!: Expense[];
|
expenses!: Relation<Expense[]>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
|
import { Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
|
||||||
|
import type { Relation } from 'typeorm';
|
||||||
import { Category } from './Category.js';
|
import { Category } from './Category.js';
|
||||||
import { Proof } from './Proof.js';
|
import { Proof } from './Proof.js';
|
||||||
import { User } from './User.js';
|
import { User } from './User.js';
|
||||||
@@ -62,11 +63,11 @@ export class Expense {
|
|||||||
updatedAt!: Date;
|
updatedAt!: Date;
|
||||||
|
|
||||||
@ManyToOne(() => User, (user) => user.expenses, { onDelete: 'CASCADE' })
|
@ManyToOne(() => User, (user) => user.expenses, { onDelete: 'CASCADE' })
|
||||||
user!: User;
|
user!: Relation<User>;
|
||||||
|
|
||||||
@ManyToOne(() => Category, (category) => category.expenses, { eager: true, onDelete: 'RESTRICT' })
|
@ManyToOne(() => Category, (category) => category.expenses, { eager: true, onDelete: 'RESTRICT' })
|
||||||
category!: Category;
|
category!: Relation<Category>;
|
||||||
|
|
||||||
@OneToMany(() => Proof, (proof) => proof.expense, { eager: true, cascade: true })
|
@OneToMany(() => Proof, (proof) => proof.expense, { eager: true, cascade: true })
|
||||||
proofs!: Proof[];
|
proofs!: Relation<Proof[]>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
|
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
|
||||||
|
import type { Relation } from 'typeorm';
|
||||||
import { User } from './User.js';
|
import { User } from './User.js';
|
||||||
import { dateTimeColumnType } from '../utils/db-column-types.js';
|
import { dateTimeColumnType } from '../utils/db-column-types.js';
|
||||||
|
|
||||||
@@ -26,5 +27,5 @@ export class Merchant {
|
|||||||
updatedAt!: Date;
|
updatedAt!: Date;
|
||||||
|
|
||||||
@ManyToOne(() => User, { onDelete: 'CASCADE' })
|
@ManyToOne(() => User, { onDelete: 'CASCADE' })
|
||||||
user!: User;
|
user!: Relation<User>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
import type { Relation } from 'typeorm';
|
||||||
import { Expense } from './Expense.js';
|
import { Expense } from './Expense.js';
|
||||||
import { dateTimeColumnType } from '../utils/db-column-types.js';
|
import { dateTimeColumnType } from '../utils/db-column-types.js';
|
||||||
|
|
||||||
@@ -34,5 +35,5 @@ export class Proof {
|
|||||||
createdAt!: Date;
|
createdAt!: Date;
|
||||||
|
|
||||||
@ManyToOne(() => Expense, (expense) => expense.proofs, { onDelete: 'CASCADE' })
|
@ManyToOne(() => Expense, (expense) => expense.proofs, { onDelete: 'CASCADE' })
|
||||||
expense!: Expense;
|
expense!: Relation<Expense>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
|
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
|
||||||
|
import type { Relation } from 'typeorm';
|
||||||
import { Category } from './Category.js';
|
import { Category } from './Category.js';
|
||||||
import { User } from './User.js';
|
import { User } from './User.js';
|
||||||
import { decimalTransformer } from '../utils/decimal.js';
|
import { decimalTransformer } from '../utils/decimal.js';
|
||||||
@@ -72,8 +73,8 @@ export class RecurringExpense {
|
|||||||
updatedAt!: Date;
|
updatedAt!: Date;
|
||||||
|
|
||||||
@ManyToOne(() => User, { onDelete: 'CASCADE' })
|
@ManyToOne(() => User, { onDelete: 'CASCADE' })
|
||||||
user!: User;
|
user!: Relation<User>;
|
||||||
|
|
||||||
@ManyToOne(() => Category, { eager: true, onDelete: 'RESTRICT' })
|
@ManyToOne(() => Category, { eager: true, onDelete: 'RESTRICT' })
|
||||||
category!: Category;
|
category!: Relation<Category>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Column, CreateDateColumn, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
import { Column, CreateDateColumn, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
import type { Relation } from 'typeorm';
|
||||||
import { Category } from './Category.js';
|
import { Category } from './Category.js';
|
||||||
import { Expense } from './Expense.js';
|
import { Expense } from './Expense.js';
|
||||||
import { dateTimeColumnType } from '../utils/db-column-types.js';
|
import { dateTimeColumnType } from '../utils/db-column-types.js';
|
||||||
@@ -51,8 +52,8 @@ export class User {
|
|||||||
createdAt!: Date;
|
createdAt!: Date;
|
||||||
|
|
||||||
@OneToMany(() => Category, (category) => category.user)
|
@OneToMany(() => Category, (category) => category.user)
|
||||||
categories!: Category[];
|
categories!: Relation<Category[]>;
|
||||||
|
|
||||||
@OneToMany(() => Expense, (expense) => expense.user)
|
@OneToMany(() => Expense, (expense) => expense.user)
|
||||||
expenses!: Expense[];
|
expenses!: Relation<Expense[]>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,2 @@
|
|||||||
import type { ColumnType } from 'typeorm';
|
export const dateTimeColumnType: 'timestamp' | 'datetime' =
|
||||||
|
process.env.DB_TYPE === 'postgres' ? 'timestamp' : 'datetime';
|
||||||
const dbType = (process.env.DB_TYPE ?? 'sqlite').toLowerCase();
|
|
||||||
|
|
||||||
export const dateTimeColumnType: ColumnType = dbType === 'postgres' ? 'timestamp' : 'datetime';
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
"budgets": [
|
"budgets": [
|
||||||
{
|
{
|
||||||
"type": "initial",
|
"type": "initial",
|
||||||
"maximumWarning": "1MB",
|
"maximumWarning": "1.5MB",
|
||||||
"maximumError": "2MB"
|
"maximumError": "2MB"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user