Merge branch 'main' into dev
This commit is contained in:
commit
03ea59c7e3
2
src/database/migrations/5-fifth-migration.sql
Normal file
2
src/database/migrations/5-fifth-migration.sql
Normal file
@ -0,0 +1,2 @@
|
||||
ALTER TABLE releases DROP COLUMN created_at;
|
||||
ALTER TABLE releases ADD created_at timestamp;
|
@ -38,7 +38,7 @@ const handler = async ({payload}: FirRouteInput<typeof payloadT>) => {
|
||||
|
||||
const carts = await getCarts(repoPath, manifest.carts);
|
||||
|
||||
insertRelease({
|
||||
await insertRelease({
|
||||
manifest,
|
||||
carts,
|
||||
});
|
||||
|
@ -1,9 +1,7 @@
|
||||
// Database Access Layer stuff goes here
|
||||
|
||||
// Database Access Layer stuff goes here
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { db, sql } from "../../database/db"
|
||||
import { JsonValue } from '@firebox/tsutil';
|
||||
import { db, sql } from "../../database/db";
|
||||
import { PicobookManifest } from '../types';
|
||||
|
||||
export type DbRelease = {
|
||||
@ -16,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));
|
||||
@ -34,24 +42,24 @@ export const getReleases = async (where: {
|
||||
version?: string;
|
||||
}): Promise<DbRelease[]> => {
|
||||
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: {
|
||||
@ -78,12 +86,13 @@ export const getRelease = async (where: {
|
||||
|
||||
export const insertRelease = async (props: {manifest: PicobookManifest, carts: {name: string; rom: number[]}[]}) => {
|
||||
const {manifest, carts} = props;
|
||||
// console.log('carts', JSON.stringify(carts));
|
||||
const {id: slug, author, repo, version} = manifest;
|
||||
const id = uuidv4();
|
||||
const now = new Date();
|
||||
await db.query(sql`
|
||||
INSERT INTO chats (id, slug, repo, version, author, carts, manifest, created_at)
|
||||
VALUES (${id}, ${slug}, ${repo}, ${version}, ${author} ${carts}, ${manifest}, ${now})
|
||||
INSERT INTO releases (id, slug, repo, version, author, carts, manifest, created_at)
|
||||
VALUES (${id}, ${slug}, ${repo}, ${version}, ${author}, ${{carts}}, ${manifest}, ${now})
|
||||
`);
|
||||
return id;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import echo from "./api/echo.ts";
|
||||
import getRelease from "./api/getRelease.ts";
|
||||
import release from "./api/release.ts";
|
||||
import webhook from "./api/webhook.ts";
|
||||
|
||||
@ -6,6 +7,7 @@ export const routeList = [
|
||||
echo,
|
||||
webhook,
|
||||
release,
|
||||
getRelease,
|
||||
];
|
||||
|
||||
export type RouteList = typeof routeList;
|
Loading…
x
Reference in New Issue
Block a user