main: fix build issues

Signed-off-by: nfel <nfilsaraee@gmail.com>
This commit is contained in:
nfel 2025-12-27 23:37:46 +03:30
parent df1f8af8e6
commit acbaebb947
Signed by: nfel
GPG Key ID: DCC0BF3F92B0D45F
3 changed files with 14 additions and 5 deletions

View File

@ -3,10 +3,11 @@ import { albumDb } from '@/lib/db';
export async function GET( export async function GET(
request: NextRequest, request: NextRequest,
{ params }: { params: { id: string } } { params }: { params: Promise<{ id: string }> }
) { ) {
try { try {
const album = albumDb.getById(params.id); const { id } = await params;
const album = albumDb.getById(id);
if (!album) { if (!album) {
return NextResponse.json( return NextResponse.json(

View File

@ -1,3 +1,4 @@
""
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { albumDb } from '@/lib/db'; import { albumDb } from '@/lib/db';
import { Album } from '@/lib/types'; import { Album } from '@/lib/types';

View File

@ -98,6 +98,7 @@ function seedInitialData() {
// Album operations // Album operations
export const albumDb = { export const albumDb = {
getAll(): Album[] { getAll(): Album[] {
const db = getDatabase();
const rows = db.prepare('SELECT * FROM albums ORDER BY year DESC').all(); const rows = db.prepare('SELECT * FROM albums ORDER BY year DESC').all();
return rows.map((row: any) => ({ return rows.map((row: any) => ({
...row, ...row,
@ -106,6 +107,7 @@ export const albumDb = {
}, },
getById(id: string): Album | null { getById(id: string): Album | null {
const db = getDatabase();
const row = db.prepare('SELECT * FROM albums WHERE id = ?').get(id) as any; const row = db.prepare('SELECT * FROM albums WHERE id = ?').get(id) as any;
if (!row) return null; if (!row) return null;
return { return {
@ -115,6 +117,7 @@ export const albumDb = {
}, },
create(album: Album): void { create(album: Album): void {
const db = getDatabase();
db.prepare(` db.prepare(`
INSERT INTO albums (id, title, coverImage, year, genre, description, price, songs) INSERT INTO albums (id, title, coverImage, year, genre, description, price, songs)
VALUES (?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
@ -131,6 +134,7 @@ export const albumDb = {
}, },
update(id: string, album: Album): void { update(id: string, album: Album): void {
const db = getDatabase();
db.prepare(` db.prepare(`
UPDATE albums UPDATE albums
SET title = ?, coverImage = ?, year = ?, genre = ?, description = ?, price = ?, songs = ?, updatedAt = strftime('%s', 'now') SET title = ?, coverImage = ?, year = ?, genre = ?, description = ?, price = ?, songs = ?, updatedAt = strftime('%s', 'now')
@ -148,6 +152,7 @@ export const albumDb = {
}, },
delete(id: string): void { delete(id: string): void {
const db = getDatabase();
db.prepare('DELETE FROM albums WHERE id = ?').run(id); db.prepare('DELETE FROM albums WHERE id = ?').run(id);
}, },
}; };
@ -155,6 +160,7 @@ export const albumDb = {
// Purchase operations // Purchase operations
export const purchaseDb = { export const purchaseDb = {
getAll(): Purchase[] { getAll(): Purchase[] {
const db = getDatabase();
const rows = db.prepare('SELECT * FROM purchases ORDER BY purchaseDate DESC').all(); const rows = db.prepare('SELECT * FROM purchases ORDER BY purchaseDate DESC').all();
return rows.map((row: any) => ({ return rows.map((row: any) => ({
id: row.id, id: row.id,
@ -169,6 +175,7 @@ export const purchaseDb = {
}, },
getByAlbumId(albumId: string): Purchase[] { getByAlbumId(albumId: string): Purchase[] {
const db = getDatabase();
const rows = db.prepare('SELECT * FROM purchases WHERE albumId = ? ORDER BY purchaseDate DESC').all(albumId); const rows = db.prepare('SELECT * FROM purchases WHERE albumId = ? ORDER BY purchaseDate DESC').all(albumId);
return rows.map((row: any) => ({ return rows.map((row: any) => ({
id: row.id, id: row.id,
@ -183,6 +190,7 @@ export const purchaseDb = {
}, },
getByTransactionId(transactionId: string): Purchase | null { getByTransactionId(transactionId: string): Purchase | null {
const db = getDatabase();
const row = db.prepare('SELECT * FROM purchases WHERE transactionId = ?').get(transactionId) as any; const row = db.prepare('SELECT * FROM purchases WHERE transactionId = ?').get(transactionId) as any;
if (!row) return null; if (!row) return null;
return { return {
@ -198,6 +206,7 @@ export const purchaseDb = {
}, },
create(purchase: Omit<Purchase, 'id'>): Purchase { create(purchase: Omit<Purchase, 'id'>): Purchase {
const db = getDatabase();
const result = db.prepare(` const result = db.prepare(`
INSERT INTO purchases (albumId, transactionId, customerName, email, phoneNumber, txReceipt, purchaseDate) INSERT INTO purchases (albumId, transactionId, customerName, email, phoneNumber, txReceipt, purchaseDate)
VALUES (?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?)
@ -218,9 +227,7 @@ export const purchaseDb = {
}, },
delete(id: number): void { delete(id: number): void {
const db = getDatabase();
db.prepare('DELETE FROM purchases WHERE id = ?').run(id); db.prepare('DELETE FROM purchases WHERE id = ?').run(id);
}, },
}; };
// Initialize database on import
getDatabase();