extra wrapping so not json array in db
This commit is contained in:
		| @@ -14,6 +14,16 @@ export type DbRelease = { | |||||||
| 	manifest: PicobookManifest; | 	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 compareVersions = (a: string, b: string) => { | ||||||
| 	const [a1, a2] = a.split(".").map(x => Number(x)); | 	const [a1, a2] = a.split(".").map(x => Number(x)); | ||||||
| 	const [b1, b2] = b.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; | 	version?: string; | ||||||
| }): Promise<DbRelease[]> => { | }): Promise<DbRelease[]> => { | ||||||
| 	const {author, slug, version} = where; | 	const {author, slug, version} = where; | ||||||
|  | 	let rows: DbReleaseInternal[]; | ||||||
| 	if (!version) { | 	if (!version) { | ||||||
| 		const rows = await db.query(sql` | 		rows = await db.query(sql` | ||||||
| 			SELECT * from releases | 			SELECT * from releases | ||||||
| 			WHERE | 			WHERE | ||||||
| 				slug = ${slug} AND | 				slug = ${slug} AND | ||||||
| 				author = ${author} | 				author = ${author} | ||||||
| 		`); | 		`); | ||||||
| 		return rows; |  | ||||||
| 	} else { | 	} else { | ||||||
| 		const rows = await db.query(sql` | 		rows = await db.query(sql` | ||||||
| 			SELECT * from releases | 			SELECT * from releases | ||||||
| 			WHERE | 			WHERE | ||||||
| 				slug = ${slug} AND | 				slug = ${slug} AND | ||||||
| 				author = ${author} AND | 				author = ${author} AND | ||||||
| 				version = ${version} | 				version = ${version} | ||||||
| 		`); | 		`); | ||||||
| 		return rows; |  | ||||||
| 	} | 	} | ||||||
|  | 	return rows.map(row => ({...row, carts: row.carts.carts})); | ||||||
| } | } | ||||||
|  |  | ||||||
| export const getRelease = async (where: { | export const getRelease = async (where: { | ||||||
| @@ -82,7 +92,7 @@ export const insertRelease = async (props: {manifest: PicobookManifest, carts: { | |||||||
| 	const now = new Date(); | 	const now = new Date(); | ||||||
| 	await db.query(sql` | 	await db.query(sql` | ||||||
| 		INSERT INTO releases (id, slug, repo, version, author, carts, manifest, created_at) | 		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; | 	return id; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 dylan
					dylan