1
0
forked from noxious/server

Many many more improvements

This commit is contained in:
2024-12-28 19:21:15 +01:00
parent bd3bf6f580
commit 918f5141fc
27 changed files with 178 additions and 191 deletions

View File

@@ -1,6 +1,10 @@
import { Request, Response } from 'express'
import { Logger } from '#application/logger'
export abstract class BaseController {
protected readonly logger: Logger = new Logger('http')
protected sendSuccess(res: Response, data?: any, message?: string, status: number = 200) {
return res.status(status).json({
success: true,

View File

@@ -1,9 +1,11 @@
import { EntityManager } from '@mikro-orm/core'
import Database from '#application/database'
import { appLogger } from '#application/logger'
import { Logger } from '#application/logger'
export abstract class BaseEntity {
protected readonly logger: Logger = new Logger('entity')
private getEntityManager(): EntityManager {
return Database.getEntityManager()
}
@@ -35,7 +37,7 @@ export abstract class BaseEntity {
throw error
}
} catch (error) {
appLogger.error(`Failed to ${actionDescription}: ${error instanceof Error ? error.message : String(error)}`)
this.logger.error(`Failed to ${actionDescription}: ${error instanceof Error ? error.message : String(error)}`)
throw error
}
}

View File

@@ -1,8 +1,11 @@
import { Server } from 'socket.io'
import { Logger } from '#application/logger'
import { TSocket } from '#application/types'
export abstract class BaseEvent {
protected readonly logger: Logger = new Logger('game')
constructor(
readonly io: Server,
readonly socket: TSocket

View File

@@ -2,7 +2,11 @@ import { EntityManager } from '@mikro-orm/core'
import Database from '../database'
import { Logger } from '#application/logger'
export abstract class BaseRepository {
protected readonly logger: Logger = new Logger('repository')
protected get em(): EntityManager {
return Database.getEntityManager()
}

View File

@@ -0,0 +1,5 @@
import { Logger } from '#application/logger'
export abstract class BaseService {
protected readonly logger: Logger = new Logger('game')
}