Skip to content

Commit

Permalink
Feat/api (#15)
Browse files Browse the repository at this point in the history
* feat: perf for scoreboard

* feat: improve perf

* feat: improve perf

* feat: improve socket time

* feat: scoreboard weight

* fix: scoreboard event when start game

* feat: db logging

* feat: remove healthz logging

* feat: remove pg layer history

* feat: scoreboard log

* fix: all rooms broadvaster

* fix: subClient connect

* feat: weight score

* feat: weight score clamp

* feat: weight score optimizer
  • Loading branch information
PatrickChoDev authored Mar 30, 2024
1 parent e26fd58 commit 9ca2812
Show file tree
Hide file tree
Showing 13 changed files with 489 additions and 159 deletions.
126 changes: 112 additions & 14 deletions apps/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
"author": "",
"license": "ISC",
"dependencies": {
"@redis/search": "^1.1.6",
"@socket.io/redis-adapter": "^8.3.0",
"@types/pg": "^8.11.4",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"morgan": "^1.10.0",
"pg": "^8.11.3",
"redis": "^4.6.13",
"sequelize": "^6.37.1",
"socket.io": "^4.7.5",
"split": "^1.0.1",
"winston": "^3.13.0"
},
"optionalDependencies": {
Expand All @@ -30,6 +33,8 @@
},
"devDependencies": {
"@types/express": "^4.17.21",
"@types/morgan": "^1.9.9",
"@types/split": "^1.0.5",
"nodemon": "^3.1.0",
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
Expand Down
56 changes: 39 additions & 17 deletions apps/server/src/controller/admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ export class AdminController {
constructor(
private readonly io: Server,
private readonly adminService: AdminService,
) {}
async getGames(req: Request, res: Response) {
const games = await this.adminService.getAllGames()
) { }
async listGames(req: Request, res: Response) {
const games = await this.adminService.listGames()
res.json(games)
}

async getGame(req: Request, res: Response) {
const game = await this.adminService.getGame(req.params.id)
async getGameByID(req: Request, res: Response) {
const game = await this.adminService.getGameByID(req.params.id)
if (!game) return res.status(404).send({ err: 'Game not found' })
res.json(game)
}

Expand All @@ -24,27 +25,48 @@ export class AdminController {
res.json(game)
}

async getGameById(req: Request, res: Response) {
const game = await this.adminService.getGame(req.params.id)
res.json(game)
}

async getState(req: Request, res: Response) {
const state = await this.adminService.getState()
async getGameState(req: Request, res: Response) {
const state = await this.adminService.getGameState()
res.json(state)
}

async startGame(req: Request, res: Response) {
const game = await this.adminService.startGame(req.params.id)
const game = await this.adminService.startGame(
req.params.id,
req.query.reset === 'true',
)
res.json(game)
this.io.emit('events', 'start')
this.io.emit('state', await this.adminService.getState())
this.io.sockets.emit('events', 'start')
this.io.sockets.emit(
'state',
await this.adminService.getGameState().then((game) => game.id),
)
this.io.sockets.to('scoreboard').emit('scoreboard', await this.adminService.getScoreboard(game.id, game.actions.map((a) => a.key)))
}

async endGame(req: Request, res: Response) {
const game = await this.adminService.endGame(req.params.id)
res.json(game)
this.io.emit('events', 'stop')
this.io.emit('state', await this.adminService.getState())
this.io.sockets.emit('events', 'stop')
this.io.sockets.emit(
'state',
await this.adminService.getGameState().then((game) => game.id),
)
this.io.engine.emit('stop')
}

async getGameSummary(req: Request, res: Response) {
const game = await this.adminService.getGameByID(req.params.id)
if (!game) return res.status(404).send({ err: 'Game not found' })
const summary = await this.adminService.getGameSummary(game.id, game.actions.map((a) => a.key))
res.json(summary)
}

async setScreenState(req: Request, res: Response) {
if (req.params.state !== 'full' && req.params.state !== 'overlay')
return res.status(400)
const response = await this.adminService.setScreenState(req.params.state)
this.io.to('scoreboard').emit('screen', req.params.state)
res.json(response)
}
}
Loading

0 comments on commit 9ca2812

Please sign in to comment.