Refactoring

* replace TypeORM with Kysely query builder
* refactor migrations
* other changes and fixes
This commit is contained in:
Philipinho
2024-03-29 01:46:11 +00:00
parent cacb5606b1
commit c18c9ae02b
122 changed files with 2619 additions and 3541 deletions

View File

@ -1,17 +0,0 @@
import { DataSource, EntityManager } from 'typeorm';
export async function transactionWrapper(
operation: (...args) => any,
datasource: DataSource,
entityManager: EntityManager,
): Promise<any> {
if (entityManager) {
return await operation(entityManager);
} else {
return await datasource.manager.transaction(
async (manager: EntityManager) => {
return await operation(manager);
},
);
}
}

View File

@ -1,4 +1,7 @@
import { join } from 'path';
import * as path from 'path';
import * as bcrypt from 'bcrypt';
export const envPath = path.resolve(process.cwd(), '..', '..', '.env');
export function generateHostname(name: string): string {
let hostname = name.replace(/[^a-z0-9]/gi, '').toLowerCase();
@ -6,4 +9,18 @@ export function generateHostname(name: string): string {
return hostname;
}
export const envPath = join(__dirname, '..', '..', '..', '.env');
export async function hashPassword(password: string) {
const saltRounds = 12;
return bcrypt.hash(password, saltRounds);
}
export async function comparePasswordHash(
plainPassword: string,
passwordHash: string,
): Promise<boolean> {
return bcrypt.compare(plainPassword, passwordHash);
}
export function getRandomInt(min = 4, max = 5) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}