Skip to content

Commit

Permalink
fix: Apply fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
matthe815 committed Aug 3, 2024
1 parent ff2febb commit d353125
Showing 1 changed file with 37 additions and 39 deletions.
76 changes: 37 additions & 39 deletions src/lib/riitag/neo/std/Covers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import { user } from '@prisma/client'

const xml2js = require('xml2js')

const pg = require('pg');
const { Client } = pg
const client = new Client({
host: 'localhost',
user: 'postgres',
password: 'postgres',
database: 'riitag',
port: 2345
})

export default class Covers extends ModuleBase {
x: number
y: number
Expand Down Expand Up @@ -186,21 +196,45 @@ export default class Covers extends ModuleBase {
return cover
}

async fix (userId: number) {
await client.connect()
const res = await client.query('SELECT * FROM playlog WHERE user_id=$1', [userId])
console.log(res.rows) // Hello world!

for (const row of res.rows) {
console.log(row)

const res = await client.query('SELECT * FROM game WHERE game_pk=$1', [row.game_pk])
if (res.rows.length === 0) {
console.log('No game found for game_pk', row.game_pk)
await client.query('DELETE FROM playlog WHERE game_pk=$1', [row.game_pk])
}
console.log(res.rows)
}

await client.end()
}

/**
* Get all of the covers for a user.
* @param user The user to get the covers for.
* @returns
*/
async getAllUserCovers (user: user): Promise<string[]> {
await this.fix(user.id)
const playlog = await prisma.playlog.findMany({
where: {
user: {
id: user.id
}
},
select: {
game_pk: true,
playlog_id: true
game: {
select: {
game_id: true,
console: true
}
}
},
orderBy: {
played_on: 'desc'
Expand All @@ -214,45 +248,9 @@ export default class Covers extends ModuleBase {
return []
}

for (const entry of playlog) {
const doesntmatter = await prisma.game.findFirst({
where: {
game_pk: entry.game_pk
}
})
if (!doesntmatter || doesntmatter.console === CONSOLE.THREEDS) {
await prisma.playlog.delete({
where: {
playlog_id: entry.playlog_id
}
})
}
}

const otherPlaylog = await prisma.playlog.findMany({
where: {
user: {
id: user.id
}
},
select: {
game: {
select: {
console: true,
game_id: true
}
}
},
orderBy: {
played_on: 'desc'
},
distinct: ['game_pk'],
take: this.max
})

const coverPaths = []

for (const logEntry of otherPlaylog) {
for (const logEntry of playlog) {
coverPaths.push(this.getCover(
logEntry.game.console,
user.cover_type,
Expand Down

0 comments on commit d353125

Please sign in to comment.