Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions apps/web/app/(ee)/api/customers/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,30 @@ export const PATCH = withWorkspace(

if (avatar && !isStored(avatar) && finalCustomerAvatar) {
waitUntil(
Promise.allSettled([
storage.upload({
storage
.upload({
key: finalCustomerAvatar.replace(`${R2_URL}/`, ""),
body: avatar,
opts: {
width: 128,
height: 128,
},
})
.then(() => {
if (oldCustomerAvatar && isStored(oldCustomerAvatar)) {
storage.delete({
key: oldCustomerAvatar.replace(`${R2_URL}/`, ""),
});
}
})
.catch(async (error) => {
console.error("Error persisting customer avatar to R2", error);
// if the avatar fails to upload to R2, set the avatar to null in the database
await prisma.customer.update({
where: { id: customer.id },
data: { avatar: null },
});
}),
oldCustomerAvatar &&
isStored(oldCustomerAvatar) &&
storage.delete({
key: oldCustomerAvatar.replace(`${R2_URL}/`, ""),
}),
]),
);
}

Expand Down
29 changes: 21 additions & 8 deletions apps/web/app/(ee)/api/customers/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,27 @@ export const POST = withWorkspace(

if (avatar && !isStored(avatar) && finalCustomerAvatar) {
waitUntil(
storage.upload({
key: finalCustomerAvatar.replace(`${R2_URL}/`, ""),
body: avatar,
opts: {
width: 128,
height: 128,
},
}),
storage
.upload({
key: finalCustomerAvatar.replace(`${R2_URL}/`, ""),
body: avatar,
opts: {
width: 128,
height: 128,
},
})
.catch(async (error) => {
console.error("Error persisting customer avatar to R2", error);
// if the avatar fails to upload to R2, set the avatar to null in the database
await prisma.customer.update({
where: {
id: customer.id,
},
data: {
avatar: null,
},
});
}),
);
}

Expand Down
27 changes: 19 additions & 8 deletions apps/web/lib/api/conversions/track-lead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,25 @@ export const trackLead = async ({
finalCustomerAvatar
) {
// persist customer avatar to R2
await storage.upload({
key: finalCustomerAvatar.replace(`${R2_URL}/`, ""),
body: customerAvatar,
opts: {
width: 128,
height: 128,
},
});
await storage
.upload({
key: finalCustomerAvatar.replace(`${R2_URL}/`, ""),
body: customerAvatar,
opts: {
width: 128,
height: 128,
},
})
.catch(async (error) => {
console.error("Error persisting customer avatar to R2", error);
// if the avatar fails to upload to R2, set the avatar to null in the database
if (customer) {
await prisma.customer.update({
where: { id: customer.id },
data: { avatar: null },
});
}
});
}

// if not deferred mode, process the following right away:
Expand Down
27 changes: 19 additions & 8 deletions apps/web/lib/api/conversions/track-sale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,25 @@ export const trackSale = async ({
if (customerAvatar && !isStored(customerAvatar) && finalCustomerAvatar) {
// persist customer avatar to R2 if it's not already stored
waitUntil(
storage.upload({
key: finalCustomerAvatar.replace(`${R2_URL}/`, ""),
body: customerAvatar,
opts: {
width: 128,
height: 128,
},
}),
storage
.upload({
key: finalCustomerAvatar.replace(`${R2_URL}/`, ""),
body: customerAvatar,
opts: {
width: 128,
height: 128,
},
})
.catch(async (error) => {
console.error("Error persisting customer avatar to R2", error);
// if the avatar fails to upload to R2, set the avatar to null in the database
if (newCustomer) {
await prisma.customer.update({
where: { id: newCustomer.id },
data: { avatar: null },
});
}
}),
);
}

Expand Down
35 changes: 0 additions & 35 deletions apps/web/lib/openapi/customers/create-customer.ts

This file was deleted.

2 changes: 0 additions & 2 deletions apps/web/lib/openapi/customers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ZodOpenApiPathsObject } from "zod-openapi";
import { createCustomer } from "./create-customer";
import { deleteCustomer } from "./delete-customer";
import { getCustomer } from "./get-customer";
import { getCustomers } from "./get-customers";
Expand All @@ -8,7 +7,6 @@ import { updateCustomer } from "./update-customer";
export const customersPaths: ZodOpenApiPathsObject = {
"/customers": {
get: getCustomers,
post: createCustomer,
},
"/customers/{id}": {
get: getCustomer,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/tests/fraud/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { describe, expect, test } from "vitest";
import { IntegrationHarness } from "../utils/integration";

describe.concurrent("/fraud/**", async () => {
describe.skip.concurrent("/fraud/**", async () => {
const h = new IntegrationHarness();
const { http } = await h.init();

Expand Down