Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

update update-sale-action

Kiran K74694d633109
diff --git a/apps/web/lib/actions/update-sale-status.ts b/apps/web/lib/actions/update-sale-status.ts
index 95cc8516b8..03de90f245 100644
--- a/apps/web/lib/actions/update-sale-status.ts
+++ b/apps/web/lib/actions/update-sale-status.ts
@@ -5,33 +5,41 @@ import { SaleStatus } from "@prisma/client";
import { z } from "zod";
import { authActionClient } from "./safe-action";
-const schema = z.object({
+const updateSaleStatusSchema = z.object({
workspaceId: z.string(),
saleId: z.string(),
status: z.nativeEnum(SaleStatus),
});
export const updateSaleStatusAction = authActionClient
- .schema(schema)
+ .schema(updateSaleStatusSchema)
.action(async ({ parsedInput, ctx }) => {
const { workspace } = ctx;
const { saleId, status } = parsedInput;
- await prisma.sale.update({
+ const sale = await prisma.sale.findUniqueOrThrow({
where: {
id: saleId,
program: {
workspaceId: workspace.id,
},
},
+ });
+
+ if (sale.status === "paid") {
+ throw new Error("You cannot update a paid sale status.");
+ }
+
+ await prisma.sale.update({
+ where: {
+ id: sale.id,
+ },
data: {
status,
},
});
- // TODO:
- // Send email to the partner informing them about the sale status change
-
+ // TODO: [payouts] Send email to the partner informing them about the sale status change
// TODO: [payouts] Update associated payout based on new status (fraud, duplicate, etc.)
return {