Some checks failed
CI / build-and-test (pull_request) Failing after 1m19s
CI (.gitea/workflows/ci.yaml): lint → typecheck → vitest w/ coverage → OpenNext build → preview smoke → bundle-size budgets; Node 20; npm ci; artifacts; safe env; D1 dry-run scaffold. Budgets: add scripts/budgets.mjs; TOTAL_STATIC_MAX_BYTES and MAX_ASSET_BYTES thresholds; report top offenders; fail on breach; README CI section. Flags: add lib/flags.ts with typed booleans and safe defaults (ADMIN_ENABLED, ARTISTS_MODULE_ENABLED, UPLOADS_ADMIN_ENABLED, BOOKING_ENABLED, PUBLIC_APPOINTMENT_REQUESTS_ENABLED, REFERENCE_UPLOADS_PUBLIC_ENABLED, DEPOSITS_ENABLED, PUBLIC_DB_ARTISTS_ENABLED, ADVANCED_NAV_SCROLL_ANIMATIONS_ENABLED, STRICT_CI_GATES_ENABLED, ISR_CACHE_R2_ENABLED); robust parsing; client provider; unit tests. Wiring: gate Admin shell and admin write APIs (503 JSON on uploads and artists writes); disable booking submit and short-circuit booking mutations when off; render static Hero/Artists when advanced animations off; tests for UI and API guards. Ops: expand docs/prd/rollback-strategy.md with “Feature Flags Operations,” Cloudflare Dashboard and wrangler.toml steps, preview simulation, incident playbook, and post-toggle smoke checklist. Release: add docs/releases/2025-09-19-feature-flags-rollout.md with last-good commit, preview/production flag matrices, rollback notes, and smoke results; link from rollback doc. Chore: fix TS issues (gift-cards boolean handling, Lenis options, tailwind darkMode), remove next-on-pages peer conflict, update package.json scripts, configure Gitea act_runner label, open draft PR to trigger CI. Refs: CI-1, FF-1, FF-2, FF-3, OPS-1 Impact: defaults preserve current behavior; no runtime changes unless flags flipped
122 lines
3.8 KiB
TypeScript
122 lines
3.8 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server"
|
|
import { requireAuth } from "@/lib/auth"
|
|
import { UserRole } from "@/types/database"
|
|
import { createArtistSchema, paginationSchema, artistFiltersSchema } from "@/lib/validations"
|
|
import { getArtists, createArtist } from "@/lib/db"
|
|
import { Flags } from "@/lib/flags"
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
// GET /api/artists - Fetch all artists with optional filtering and pagination
|
|
export async function GET(request: NextRequest, { params }: { params?: any } = {}, context?: any) {
|
|
try {
|
|
const { searchParams } = new URL(request.url)
|
|
|
|
// Parse and validate query parameters
|
|
const pagination = paginationSchema.parse({
|
|
page: searchParams.get("page") || "1",
|
|
limit: searchParams.get("limit") || "10",
|
|
})
|
|
|
|
const filters = artistFiltersSchema.parse({
|
|
isActive: searchParams.get("isActive"),
|
|
specialty: searchParams.get("specialty"),
|
|
search: searchParams.get("search"),
|
|
})
|
|
|
|
// Fetch artists from database with environment context
|
|
const artists = await getArtists(context?.env)
|
|
|
|
// Apply filters
|
|
let filteredArtists = artists
|
|
|
|
if (filters.isActive !== undefined) {
|
|
filteredArtists = filteredArtists.filter(artist =>
|
|
artist.isActive === filters.isActive
|
|
)
|
|
}
|
|
|
|
if (filters.specialty) {
|
|
filteredArtists = filteredArtists.filter(artist =>
|
|
artist.specialties.some(specialty =>
|
|
specialty.toLowerCase().includes(filters.specialty!.toLowerCase())
|
|
)
|
|
)
|
|
}
|
|
|
|
if (filters.search) {
|
|
const searchTerm = filters.search.toLowerCase()
|
|
filteredArtists = filteredArtists.filter(artist =>
|
|
artist.name.toLowerCase().includes(searchTerm) ||
|
|
artist.bio.toLowerCase().includes(searchTerm)
|
|
)
|
|
}
|
|
|
|
// Apply pagination
|
|
const startIndex = (pagination.page - 1) * pagination.limit
|
|
const endIndex = startIndex + pagination.limit
|
|
const paginatedArtists = filteredArtists.slice(startIndex, endIndex)
|
|
|
|
return NextResponse.json({
|
|
artists: paginatedArtists,
|
|
pagination: {
|
|
page: pagination.page,
|
|
limit: pagination.limit,
|
|
total: filteredArtists.length,
|
|
totalPages: Math.ceil(filteredArtists.length / pagination.limit),
|
|
},
|
|
filters,
|
|
})
|
|
} catch (error) {
|
|
console.error("Error fetching artists:", error)
|
|
return NextResponse.json(
|
|
{ error: "Failed to fetch artists" },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|
|
|
|
// POST /api/artists - Create a new artist (Admin only)
|
|
export async function POST(request: NextRequest, { params }: { params?: any } = {}, context?: any) {
|
|
try {
|
|
if (!Flags.ARTISTS_MODULE_ENABLED) {
|
|
return NextResponse.json({ error: 'Artists module disabled' }, { status: 503 })
|
|
}
|
|
// Require admin authentication
|
|
const session = await requireAuth(UserRole.SHOP_ADMIN)
|
|
|
|
const body = await request.json()
|
|
const validatedData = createArtistSchema.parse(body)
|
|
|
|
// Create new artist in database with environment context
|
|
const newArtist = await createArtist({
|
|
...validatedData,
|
|
userId: session.user.id,
|
|
}, context?.env)
|
|
|
|
return NextResponse.json(newArtist, { status: 201 })
|
|
} catch (error) {
|
|
console.error("Error creating artist:", error)
|
|
|
|
if (error instanceof Error) {
|
|
if (error.message.includes("Authentication required")) {
|
|
return NextResponse.json(
|
|
{ error: "Authentication required" },
|
|
{ status: 401 }
|
|
)
|
|
}
|
|
if (error.message.includes("Insufficient permissions")) {
|
|
return NextResponse.json(
|
|
{ error: "Insufficient permissions" },
|
|
{ status: 403 }
|
|
)
|
|
}
|
|
}
|
|
|
|
return NextResponse.json(
|
|
{ error: "Failed to create artist" },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|