From f874f56816cc4da4b412fd51b8385791cda6283e Mon Sep 17 00:00:00 2001 From: Tau Date: Sun, 26 May 2019 19:59:36 -0400 Subject: [PATCH] idz: Expose some row mappers --- src/idz/db/chara.ts | 28 ++++++++++++++++------------ src/idz/db/profile.ts | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/idz/db/chara.ts b/src/idz/db/chara.ts index 60627cb..6e50c6b 100644 --- a/src/idz/db/chara.ts +++ b/src/idz/db/chara.ts @@ -6,6 +6,21 @@ import { Profile } from "../model/profile"; import { FacetRepository } from "../repo"; import { Id } from "../../db"; +export function _extractChara(row: any): Chara { + return { + gender: row.gender, + field_02: row.field_02, + field_04: row.field_04, + field_06: row.field_06, + field_08: row.field_08, + field_0A: row.field_0A, + field_0C: row.field_0C, + field_0E: row.field_0E, + title: row.title, + background: row.background, + }; +} + export class SqlCharaRepository implements FacetRepository { constructor(private readonly _conn: ClientBase) {} @@ -19,18 +34,7 @@ export class SqlCharaRepository implements FacetRepository { const { rows } = await this._conn.query(loadSql); const row = rows[0]; - return { - gender: row.gender, - field_02: row.field_02, - field_04: row.field_04, - field_06: row.field_06, - field_08: row.field_08, - field_0A: row.field_0A, - field_0C: row.field_0C, - field_0E: row.field_0E, - title: row.title, - background: row.background, - }; + return _extractChara(row); } async save(profileId: Id, chara: Chara): Promise { diff --git a/src/idz/db/profile.ts b/src/idz/db/profile.ts index ae2f071..4691bf4 100644 --- a/src/idz/db/profile.ts +++ b/src/idz/db/profile.ts @@ -6,7 +6,7 @@ import { ProfileRepository } from "../repo"; import { generateId, Id } from "../../db"; import { AimeId } from "../../model"; -function _extractProfile(row: any): Profile { +export function _extractProfile(row: any): Profile { return { aimeId: row.aime_id, name: row.name,