diff --git a/src/server/dbal/dbal.ts b/src/server/dbal/dbal.ts index 70411ed..edfb45e 100644 --- a/src/server/dbal/dbal.ts +++ b/src/server/dbal/dbal.ts @@ -14,6 +14,16 @@ export type DbRelease = { manifest: PicobookManifest; } +export type DbReleaseInternal = { + id: string; + slug: string; + repo: string; + version: string; + carts: {carts: {name: string; rom: number[]}[]}; + author: string; + manifest: PicobookManifest; +} + const compareVersions = (a: string, b: string) => { const [a1, a2] = a.split(".").map(x => Number(x)); const [b1, b2] = b.split(".").map(x => Number(x)); @@ -32,24 +42,24 @@ export const getReleases = async (where: { version?: string; }): Promise => { const {author, slug, version} = where; + let rows: DbReleaseInternal[]; if (!version) { - const rows = await db.query(sql` + rows = await db.query(sql` SELECT * from releases WHERE slug = ${slug} AND author = ${author} `); - return rows; } else { - const rows = await db.query(sql` + rows = await db.query(sql` SELECT * from releases WHERE slug = ${slug} AND author = ${author} AND version = ${version} `); - return rows; } + return rows.map(row => ({...row, carts: row.carts.carts})); } export const getRelease = async (where: { @@ -82,7 +92,7 @@ export const insertRelease = async (props: {manifest: PicobookManifest, carts: { const now = new Date(); await db.query(sql` INSERT INTO releases (id, slug, repo, version, author, carts, manifest, created_at) - VALUES (${id}, ${slug}, ${repo}, ${version}, ${author}, ${carts}, ${manifest}, ${now}) + VALUES (${id}, ${slug}, ${repo}, ${version}, ${author}, ${{carts}}, ${manifest}, ${now}) `); return id; }