parent
8714891c2e
commit
0291c73e80
@ -0,0 +1,32 @@ |
||||
import {TransactType} from "./index"; |
||||
|
||||
export interface CharacterTable { |
||||
clearOrCreateCharacterEditor(options: {userId: string, deleteFirst: boolean}): Promise<{inserted: number, deleted: number}> |
||||
} |
||||
|
||||
export class CharacterTableImpl implements CharacterTable { |
||||
private readonly _transact: TransactType |
||||
|
||||
constructor({transact}: { transact: TransactType }) { |
||||
this._transact = transact |
||||
} |
||||
|
||||
async clearOrCreateCharacterEditor( |
||||
{userId, deleteFirst}: { userId: string; deleteFirst: boolean }): Promise<{ inserted: number, deleted: number }> { |
||||
const result = { |
||||
inserted: 0, |
||||
deleted: 0, |
||||
} |
||||
await this._transact({ |
||||
readonly: false, |
||||
async transaction(query) { |
||||
result.deleted = deleteFirst |
||||
? (await query("DELETE FROM character_creation WHERE id = $1", [userId])).rowCount |
||||
: 0 |
||||
result.inserted = |
||||
(await query("INSERT INTO character_creation (id) VALUES ($1) ON CONFLICT (id) DO NOTHING")).rowCount |
||||
} |
||||
}) |
||||
return result |
||||
} |
||||
} |
@ -1,7 +1,14 @@ |
||||
import {Snowflake} from "discord-api-types/globals"; |
||||
import {CharacterTable} from "../database/characters"; |
||||
|
||||
export class CharacterManager { |
||||
async startNewCharacter(user: Snowflake, forceErase: boolean): Promise<{alreadyEditing: boolean}> { |
||||
private |
||||
|
||||
constructor({characters}: {characters: CharacterTable}) { |
||||
} |
||||
|
||||
async startNewCharacter(user: Snowflake, overwrite: boolean): Promise<{alreadyEditing: boolean, created: boolean}> { |
||||
|
||||
} |
||||
|
||||
async abandonEditedCharacter(user: Snowflake): Promise<{abandoned: boolean}> { |
Loading…
Reference in new issue