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:
2025-08-15 22:35:15 +01:00
parent f7dc75d514
commit 7d100e7e0f
16 changed files with 224 additions and 124 deletions

View File

@ -1,6 +1,6 @@
import { db } from '@/lib/db';
import { ratings, scripts } from '@/lib/db/schema';
import { eq, and, avg, count, sql } from 'drizzle-orm';
import { eq, and, avg, count } from 'drizzle-orm';
import { generateId, ApiError } from './index';
export interface CreateRatingData {
@ -27,24 +27,31 @@ export async function rateScript(data: CreateRatingData) {
let ratingRecord;
if (existingRating) {
// Update existing rating
[ratingRecord] = await db
await db
.update(ratings)
.set({
rating: data.rating,
updatedAt: new Date(),
})
.where(eq(ratings.id, existingRating.id))
.returning();
.where(eq(ratings.id, existingRating.id));
ratingRecord = {
...existingRating,
rating: data.rating,
updatedAt: new Date(),
};
} else {
// Create new rating
[ratingRecord] = await db.insert(ratings).values({
ratingRecord = {
id: generateId(),
scriptId: data.scriptId,
userId: data.userId,
rating: data.rating,
createdAt: new Date(),
updatedAt: new Date(),
}).returning();
};
await db.insert(ratings).values(ratingRecord);
}
// Update script's average rating and count
@ -107,7 +114,7 @@ async function updateScriptRating(scriptId: string) {
.from(ratings)
.where(eq(ratings.scriptId, scriptId));
const avgRating = stats.avgRating ? Math.round(stats.avgRating * 10) / 10 : 0;
const avgRating = stats.avgRating ? Math.round(Number(stats.avgRating) * 10) / 10 : 0;
const ratingCount = stats.ratingCount || 0;
await db
@ -174,7 +181,7 @@ export async function getScriptRatingStats(scriptId: string) {
.where(eq(ratings.scriptId, scriptId));
return {
averageRating: totals.avgRating ? Math.round(totals.avgRating * 10) / 10 : 0,
averageRating: totals.avgRating ? Math.round(Number(totals.avgRating) * 10) / 10 : 0,
totalRatings: totals.totalRatings || 0,
distribution,
};