1
0
forked from noxious/server

Greatly improved server code base

This commit is contained in:
2024-12-28 17:26:17 +01:00
parent bd85908014
commit bd3bf6f580
39 changed files with 227 additions and 246 deletions

View File

@ -1,4 +1,5 @@
import { EntityManager } from '@mikro-orm/core'
import Database from '#application/database'
import { appLogger } from '#application/logger'
@ -8,18 +9,18 @@ export abstract class BaseEntity {
}
async save(): Promise<this> {
return this.performDbOperation('persist', 'save entity')
return this.execute('persist', 'save entity')
}
async update(): Promise<this> {
return this.performDbOperation('merge', 'update entity')
return this.execute('merge', 'update entity')
}
async delete(): Promise<this> {
return this.performDbOperation('remove', 'remove entity')
return this.execute('remove', 'remove entity')
}
private async performDbOperation(method: 'persist' | 'merge' | 'remove', actionDescription: string): Promise<this> {
private async execute(method: 'persist' | 'merge' | 'remove', actionDescription: string): Promise<this> {
try {
const em = this.getEntityManager()
@ -38,4 +39,4 @@ export abstract class BaseEntity {
throw error
}
}
}
}