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 { scripts, scriptVersions, users, ratings } from '@/lib/db/schema';
|
||||
import { scripts, scriptVersions, ratings } from '@/lib/db/schema';
|
||||
import { eq, desc, asc, and, or, like, count, sql } from 'drizzle-orm';
|
||||
import { generateId, ApiError } from './index';
|
||||
|
||||
@ -178,27 +178,27 @@ export async function getScripts(filters: ScriptFilters = {}) {
|
||||
}
|
||||
|
||||
if (conditions.length > 0) {
|
||||
query = query.where(and(...conditions));
|
||||
query = query.where(and(...conditions)) as any;
|
||||
}
|
||||
|
||||
// Apply sorting
|
||||
switch (sortBy) {
|
||||
case 'newest':
|
||||
query = query.orderBy(desc(scripts.createdAt));
|
||||
query = query.orderBy(desc(scripts.createdAt)) as any;
|
||||
break;
|
||||
case 'oldest':
|
||||
query = query.orderBy(asc(scripts.createdAt));
|
||||
query = query.orderBy(asc(scripts.createdAt)) as any;
|
||||
break;
|
||||
case 'popular':
|
||||
query = query.orderBy(desc(scripts.viewCount));
|
||||
query = query.orderBy(desc(scripts.viewCount)) as any;
|
||||
break;
|
||||
case 'rating':
|
||||
query = query.orderBy(desc(scripts.rating));
|
||||
query = query.orderBy(desc(scripts.rating)) as any;
|
||||
break;
|
||||
}
|
||||
|
||||
// Apply pagination
|
||||
query = query.limit(limit).offset(offset);
|
||||
query = query.limit(limit).offset(offset) as any;
|
||||
|
||||
const results = await query;
|
||||
|
||||
@ -232,11 +232,12 @@ export async function updateScript(id: string, data: UpdateScriptData, userId: s
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
|
||||
const [updatedScript] = await db
|
||||
await db
|
||||
.update(scripts)
|
||||
.set(updateData)
|
||||
.where(eq(scripts.id, id))
|
||||
.returning();
|
||||
.where(eq(scripts.id, id));
|
||||
|
||||
const updatedScript = { ...script, ...updateData };
|
||||
|
||||
// If content changed, create new version
|
||||
if (data.content && data.version) {
|
||||
@ -279,18 +280,23 @@ export async function deleteScript(id: string, userId: string) {
|
||||
}
|
||||
|
||||
// Approve/reject script (admin only)
|
||||
export async function moderateScript(id: string, isApproved: boolean, moderatorId: string) {
|
||||
export async function moderateScript(id: string, isApproved: boolean, _moderatorId: string) {
|
||||
try {
|
||||
const [updatedScript] = await db
|
||||
const script = await getScriptById(id);
|
||||
if (!script) {
|
||||
throw new ApiError('Script not found', 404);
|
||||
}
|
||||
|
||||
await db
|
||||
.update(scripts)
|
||||
.set({
|
||||
isApproved,
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(eq(scripts.id, id))
|
||||
.returning();
|
||||
.where(eq(scripts.id, id));
|
||||
|
||||
return updatedScript;
|
||||
const moderatedScript = { ...script, isApproved, updatedAt: new Date() };
|
||||
return moderatedScript;
|
||||
} catch (error) {
|
||||
throw new ApiError(`Failed to moderate script: ${error}`, 500);
|
||||
}
|
||||
|
Reference in New Issue
Block a user