forked from noxious/server
Many many more improvements
This commit is contained in:
@@ -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,
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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()
|
||||
}
|
||||
|
5
src/application/base/baseService.ts
Normal file
5
src/application/base/baseService.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Logger } from '#application/logger'
|
||||
|
||||
export abstract class BaseService {
|
||||
protected readonly logger: Logger = new Logger('game')
|
||||
}
|
Reference in New Issue
Block a user