main: fix build issues
Signed-off-by: nfel <nfilsaraee@gmail.com>
This commit is contained in:
parent
df1f8af8e6
commit
acbaebb947
@ -3,10 +3,11 @@ import { albumDb } from '@/lib/db';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const album = albumDb.getById(params.id);
|
||||
const { id } = await params;
|
||||
const album = albumDb.getById(id);
|
||||
|
||||
if (!album) {
|
||||
return NextResponse.json(
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
""
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { albumDb } from '@/lib/db';
|
||||
import { Album } from '@/lib/types';
|
||||
|
||||
13
lib/db.ts
13
lib/db.ts
@ -98,6 +98,7 @@ function seedInitialData() {
|
||||
// Album operations
|
||||
export const albumDb = {
|
||||
getAll(): Album[] {
|
||||
const db = getDatabase();
|
||||
const rows = db.prepare('SELECT * FROM albums ORDER BY year DESC').all();
|
||||
return rows.map((row: any) => ({
|
||||
...row,
|
||||
@ -106,6 +107,7 @@ export const albumDb = {
|
||||
},
|
||||
|
||||
getById(id: string): Album | null {
|
||||
const db = getDatabase();
|
||||
const row = db.prepare('SELECT * FROM albums WHERE id = ?').get(id) as any;
|
||||
if (!row) return null;
|
||||
return {
|
||||
@ -115,6 +117,7 @@ export const albumDb = {
|
||||
},
|
||||
|
||||
create(album: Album): void {
|
||||
const db = getDatabase();
|
||||
db.prepare(`
|
||||
INSERT INTO albums (id, title, coverImage, year, genre, description, price, songs)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
@ -131,6 +134,7 @@ export const albumDb = {
|
||||
},
|
||||
|
||||
update(id: string, album: Album): void {
|
||||
const db = getDatabase();
|
||||
db.prepare(`
|
||||
UPDATE albums
|
||||
SET title = ?, coverImage = ?, year = ?, genre = ?, description = ?, price = ?, songs = ?, updatedAt = strftime('%s', 'now')
|
||||
@ -148,6 +152,7 @@ export const albumDb = {
|
||||
},
|
||||
|
||||
delete(id: string): void {
|
||||
const db = getDatabase();
|
||||
db.prepare('DELETE FROM albums WHERE id = ?').run(id);
|
||||
},
|
||||
};
|
||||
@ -155,6 +160,7 @@ export const albumDb = {
|
||||
// Purchase operations
|
||||
export const purchaseDb = {
|
||||
getAll(): Purchase[] {
|
||||
const db = getDatabase();
|
||||
const rows = db.prepare('SELECT * FROM purchases ORDER BY purchaseDate DESC').all();
|
||||
return rows.map((row: any) => ({
|
||||
id: row.id,
|
||||
@ -169,6 +175,7 @@ export const purchaseDb = {
|
||||
},
|
||||
|
||||
getByAlbumId(albumId: string): Purchase[] {
|
||||
const db = getDatabase();
|
||||
const rows = db.prepare('SELECT * FROM purchases WHERE albumId = ? ORDER BY purchaseDate DESC').all(albumId);
|
||||
return rows.map((row: any) => ({
|
||||
id: row.id,
|
||||
@ -183,6 +190,7 @@ export const purchaseDb = {
|
||||
},
|
||||
|
||||
getByTransactionId(transactionId: string): Purchase | null {
|
||||
const db = getDatabase();
|
||||
const row = db.prepare('SELECT * FROM purchases WHERE transactionId = ?').get(transactionId) as any;
|
||||
if (!row) return null;
|
||||
return {
|
||||
@ -198,6 +206,7 @@ export const purchaseDb = {
|
||||
},
|
||||
|
||||
create(purchase: Omit<Purchase, 'id'>): Purchase {
|
||||
const db = getDatabase();
|
||||
const result = db.prepare(`
|
||||
INSERT INTO purchases (albumId, transactionId, customerName, email, phoneNumber, txReceipt, purchaseDate)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
@ -218,9 +227,7 @@ export const purchaseDb = {
|
||||
},
|
||||
|
||||
delete(id: number): void {
|
||||
const db = getDatabase();
|
||||
db.prepare('DELETE FROM purchases WHERE id = ?').run(id);
|
||||
},
|
||||
};
|
||||
|
||||
// Initialize database on import
|
||||
getDatabase();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user