The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update add-program-resource.ts
Tim Wilson0f7530f1d77c
diff --git a/apps/web/lib/actions/partners/program-resources/add-program-resource.ts b/apps/web/lib/actions/partners/program-resources/add-program-resource.tsindex 74f61f2046..7b4dcf253a 100644--- a/apps/web/lib/actions/partners/program-resources/add-program-resource.ts+++ b/apps/web/lib/actions/partners/program-resources/add-program-resource.ts@@ -53,26 +53,21 @@ export const addProgramResourceAction = authActionClient},});- if (!program) {- throw new Error("Program not found");- }+ if (!program) throw new Error("Program not found");- // Get current resources or initialize empty structureconst currentResources = (program.resources as any) || {logos: [],colors: [],files: [],};- // Create a copy of the current resources to updateconst updatedResources = { ...currentResources };- // Handle different resource typesif (resourceType === "logo" || resourceType === "file") {const { file } = parsedInput;// Upload the file to storage- const fileKey = `programs/${programId}/${resourceType}s/${nanoid(7)}`;+ const fileKey = `programs/${program.id}/${resourceType}s/${nanoid(7)}`;const uploadResult = await storage.upload(fileKey, file);if (!uploadResult || !uploadResult.url) {@@ -83,7 +78,6 @@ export const addProgramResourceAction = authActionClientconst base64Data = file.replace(/^data:.+;base64,/, "");const fileSize = Math.ceil((base64Data.length * 3) / 4);- // Create the new resource object using the schemaconst newResource = programResourceFileSchema.parse({id: nanoid(10),name,@@ -97,52 +91,34 @@ export const addProgramResourceAction = authActionClient...(updatedResources[resourceKey] || []),newResource,];-- // Update the program with the new resources- await prisma.program.update({- where: {- id: programId,- },- data: {- resources: updatedResources,- },- });-- return {- success: true,- resource: newResource,- };} else if (resourceType === "color") {const { color } = parsedInput;- // Create the new color resource using the schemaconst newResource = programResourceColorSchema.parse({id: nanoid(10),name,color,});- // Update the colors array in the resources objectupdatedResources.colors = [...(updatedResources.colors || []),newResource,];-- // Update the program with the new resources- await prisma.program.update({- where: {- id: programId,- },- data: {- resources: updatedResources,- },- });-- return {- success: true,- resource: newResource,- };+ } else {+ throw new Error("Invalid resource type");}- throw new Error("Invalid resource type");+ // Update the program with the new resources+ await prisma.program.update({+ where: {+ id: program.id,+ },+ data: {+ resources: updatedResources,+ },+ });++ return {+ success: true,+ };});