idz: Support multiple major versions

Doesn't actually add support for any additional versions, but it
does lay the groundwork.
This commit is contained in:
Tau
2021-02-03 23:43:39 +00:00
committed by Tau
parent 4f7c0145a1
commit 93db3831be
26 changed files with 152 additions and 48 deletions
+9 -4
View File
@@ -8,6 +8,7 @@ import { Row, Transaction } from "../../../sql";
export function _extractProfile(row: Row): Profile {
return {
aimeId: parseInt(row.aime_id!) as AimeId,
version: parseInt(row.version!),
name: row.name!,
lv: parseInt(row.lv!),
exp: parseInt(row.exp!),
@@ -22,8 +23,8 @@ export function _extractProfile(row: Row): Profile {
export class SqlProfileRepository implements ProfileRepository {
constructor(private readonly _txn: Transaction) {}
async find(aimeId: AimeId): Promise<Id<Profile>> {
const profileId = await this.peek(aimeId);
async find(aimeId: AimeId, version: number): Promise<Id<Profile>> {
const profileId = await this.peek(aimeId, version);
if (profileId === undefined) {
throw new Error(`Profile not found for Aime ID ${aimeId}`);
@@ -32,12 +33,16 @@ export class SqlProfileRepository implements ProfileRepository {
return profileId;
}
async peek(aimeId: AimeId): Promise<Id<Profile> | undefined> {
async peek(
aimeId: AimeId,
version: number
): Promise<Id<Profile> | undefined> {
const lookupSql = sql
.select("p.id")
.from("idz_profile p")
.join("aime_player r", { "p.player_id": "r.id" })
.where("r.ext_id", aimeId);
.where("r.ext_id", aimeId)
.and("r.version", version);
const row = await this._txn.fetchRow(lookupSql);
+1
View File
@@ -37,6 +37,7 @@ export class SqlTeamRepository implements TeamRepository {
}
return {
version: parseInt(row.version!),
extId: parseInt(row.ext_id!) as ExtId<Team>,
name: row.name!,
nameBg: parseInt(row.name_bg!),
+3 -1
View File
@@ -8,10 +8,12 @@ import { Transaction } from "../../../sql";
export class SqlTeamAutoRepository implements TeamAutoRepository {
constructor(private readonly _txn: Transaction) {}
async peek(): Promise<[TeamAuto, Id<Team>] | undefined> {
async peek(version: number): Promise<[TeamAuto, Id<Team>] | undefined> {
const peekSql = sql
.select("tt.*")
.from("idz_team_auto tt")
.join("idz_team t", { "tt.id": "t.id" })
.where("t.version", version)
.orderBy("serial_no desc", "name_idx desc")
.limit(1);
+2
View File
@@ -37,6 +37,7 @@ export class SqlTimeAttackRepository implements TimeAttackRepository {
// Profile
"p.name as profile_name",
// Team
"t.version as team_version",
"t.ext_id as team_ext_id",
"t.name as team_name",
"t.name_bg as team_name_bg",
@@ -64,6 +65,7 @@ export class SqlTimeAttackRepository implements TimeAttackRepository {
driverName: row.profile_name!,
team: {
extId: parseInt(row.team_ext_id!) as ExtId<Team>,
version: parseInt(row.team_version!),
name: row.team_name!,
nameBg: parseInt(row.team_name_bg!),
nameFx: parseInt(row.team_name_fx!),