You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.6 KiB
54 lines
1.6 KiB
import {TransactType} from "./index";
|
|
|
|
export interface BattleTypeData {
|
|
id: string
|
|
name: string
|
|
emoji: string
|
|
display_order: number
|
|
}
|
|
|
|
export interface BattleTypeRelationshipData {
|
|
attacker: string
|
|
defender: string
|
|
damage_percentage: number
|
|
}
|
|
|
|
export interface BattleTypeTablesData {
|
|
types: BattleTypeData[]
|
|
relationships: BattleTypeRelationshipData[]
|
|
}
|
|
|
|
export interface BattleTypeTable {
|
|
getTypesAndRelationships(): Promise<BattleTypeTablesData>
|
|
}
|
|
|
|
export class BattleTypeTableImpl implements BattleTypeTable {
|
|
private readonly _transact: TransactType
|
|
|
|
constructor({transact}: { transact: TransactType }) {
|
|
this._transact = transact
|
|
}
|
|
|
|
async getTypesAndRelationships(): Promise<BattleTypeTablesData> {
|
|
const result: BattleTypeTablesData = {
|
|
types: [],
|
|
relationships: [],
|
|
}
|
|
await this._transact({
|
|
readonly: true,
|
|
async transaction(query) {
|
|
const types = await query<{ id: string, name: string, emoji: string, display_order: number }>(
|
|
`SELECT id, name, emoji, display_order
|
|
FROM battle_types`
|
|
)
|
|
const relationships = await query<{ attacker: string, defender: string, damage_percentage: number }>(
|
|
`SELECT attacker, defender, damage_percentage
|
|
FROM battle_types_relationships`
|
|
)
|
|
result.types = types.rows
|
|
result.relationships = relationships.rows
|
|
}
|
|
})
|
|
return result
|
|
}
|
|
} |