Greatly improved server code base
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user