Skip to content

Commit

Permalink
feat: remove user socket
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickChoDev committed Mar 31, 2024
1 parent 8a56053 commit d568b18
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion apps/server/src/controller/player.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class PlayerController {
this.logger.debug('Received message: ' + String(message).trim())
const data = String(message).trim().split(' ')
this.playerService
.submit(socket.user, data[0], parseInt(data[1]))
.submit(data[0], parseInt(data[1]))
.then((game) => {
this.logger.debug(`Incremented: ${String(message).trim()}`)
if (game.id && game.actions.length > 0) {
Expand Down
14 changes: 5 additions & 9 deletions apps/server/src/models/history.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { Game } from './game.model'

export class GameHistory
extends Model<GameHistoryAttributes, GameHistoryInput>
implements GameHistoryAttributes {
implements GameHistoryAttributes
{
public game_id!: string
public player_id!: string
public key!: string
Expand Down Expand Up @@ -58,14 +59,9 @@ export class GameHistoryRepository {
RedisFunctions,
RedisScripts
>,
) { }
) {}

async createHistory(
game_id: string,
player_id: string,
key: string,
vote: number,
) {
async createHistory(game_id: string, key: string, vote: number) {
const total = await this.redis.incrBy(`game::${game_id}::${key}`, vote)
this.redis.keys(`game::${game_id}::*`).then(async (keys) => {
keys.forEach(async (k) => {
Expand Down Expand Up @@ -165,7 +161,7 @@ export class GameHistoryRepository {
return res[1][0] as Game
}),
),
)
),
)
.catch((err) => {
this.logger.error(err)
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/service/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class AdminService {
constructor(
private readonly gameRepository: GameRepository,
private readonly gameHistoryRepository: GameHistoryRepository,
) { }
) {}

async getGameByID(id: string) {
return this.gameRepository.getGameById(id)
Expand Down
9 changes: 2 additions & 7 deletions apps/server/src/service/player.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ export class PlayerService {
return this.gameHistoryRepository.getLastActiveGame()
}

async submit(client: Client, action: string, vote: number) {
async submit(action: string, vote: number) {
const game = await this.gameHistoryRepository.getLastActiveGame()
if (game && game.id && game.status === 'playing') {
await this.gameHistoryRepository.createHistory(
game.id,
client.id,
action,
vote,
)
await this.gameHistoryRepository.createHistory(game.id, action, vote)
return game
}
throw Error('No game is playing')
Expand Down

0 comments on commit d568b18

Please sign in to comment.