Refactor Docker setup for frontend-only builds by removing server-side API files, creating mock APIs, and updating health check notes. Adjusted Vite configuration for browser compatibility and refined API handling in various components to improve user experience and maintainability.
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { db } from '@/lib/db';
|
||||
import { scriptCollections, collectionScripts, scripts } from '@/lib/db/schema';
|
||||
import { scriptCollections, collectionScripts } from '@/lib/db/schema';
|
||||
import { eq, and, desc } from 'drizzle-orm';
|
||||
import { generateId, ApiError } from './index';
|
||||
|
||||
@ -22,7 +22,7 @@ export async function createCollection(data: CreateCollectionData) {
|
||||
const collectionId = generateId();
|
||||
const now = new Date();
|
||||
|
||||
const [collection] = await db.insert(scriptCollections).values({
|
||||
await db.insert(scriptCollections).values({
|
||||
id: collectionId,
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
@ -30,7 +30,17 @@ export async function createCollection(data: CreateCollectionData) {
|
||||
isPublic: data.isPublic ?? true,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
}).returning();
|
||||
});
|
||||
|
||||
const collection = {
|
||||
id: collectionId,
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
authorId: data.authorId,
|
||||
isPublic: data.isPublic ?? true,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
};
|
||||
|
||||
return collection;
|
||||
} catch (error) {
|
||||
@ -150,11 +160,12 @@ export async function updateCollection(id: string, data: UpdateCollectionData, u
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
|
||||
const [updatedCollection] = await db
|
||||
await db
|
||||
.update(scriptCollections)
|
||||
.set(updateData)
|
||||
.where(eq(scriptCollections.id, id))
|
||||
.returning();
|
||||
.where(eq(scriptCollections.id, id));
|
||||
|
||||
const updatedCollection = { ...collection, ...updateData };
|
||||
|
||||
return updatedCollection;
|
||||
} catch (error) {
|
||||
@ -205,14 +216,16 @@ export async function addScriptToCollection(collectionId: string, scriptId: stri
|
||||
throw new ApiError('Script is already in this collection', 400);
|
||||
}
|
||||
|
||||
const [collectionScript] = await db.insert(collectionScripts).values({
|
||||
const collectionScriptData = {
|
||||
id: generateId(),
|
||||
collectionId,
|
||||
scriptId,
|
||||
addedAt: new Date(),
|
||||
}).returning();
|
||||
};
|
||||
|
||||
return collectionScript;
|
||||
await db.insert(collectionScripts).values(collectionScriptData);
|
||||
|
||||
return collectionScriptData;
|
||||
} catch (error) {
|
||||
if (error instanceof ApiError) throw error;
|
||||
throw new ApiError(`Failed to add script to collection: ${error}`, 500);
|
||||
|
Reference in New Issue
Block a user