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
8 changes: 1 addition & 7 deletions apps/web/app/(ee)/api/cron/domains/delete/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ export async function POST(req: Request) {
await verifyQstashSignature({ req, rawBody });

const { domain } = schema.parse(JSON.parse(rawBody));
if (domain === "poly.market") {
// temp skip
return new Response(
`Domain ${domain} is not allowed to be deleted. Skipping...`,
);
}

const domainRecord = await prisma.domain.findUnique({
where: {
Expand Down Expand Up @@ -66,7 +60,7 @@ export async function POST(req: Request) {
linkCache.deleteMany(links),

// Record link in Tinybird
recordLink(links),
recordLink(links, { deleted: true }),

// Remove image from R2 storage if it exists
links
Expand Down
14 changes: 13 additions & 1 deletion apps/web/app/api/domains/[domain]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ export const PATCH = withWorkspace(
// DELETE /api/domains/[domain] - delete a workspace's domain
export const DELETE = withWorkspace(
async ({ params, workspace }) => {
const { slug: domain, registeredDomain } = await getDomainOrThrow({
const {
slug: domain,
registeredDomain,
partnerProgram,
} = await getDomainOrThrow({
workspace,
domain: params.domain,
dubDomainChecks: true,
Expand All @@ -236,6 +240,14 @@ export const DELETE = withWorkspace(
});
}

if (partnerProgram) {
throw new DubApiError({
code: "forbidden",
message:
"You cannot delete a domain that is actively in use in a partner program.",
});
}

await markDomainAsDeleted({
domain,
});
Expand Down
1 change: 1 addition & 0 deletions apps/web/lib/api/domains/get-domain-or-throw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const getDomainOrThrow = async ({
where: { slug: domain },
include: {
registeredDomain: true,
partnerProgram: true,
},
});

Expand Down
1 change: 1 addition & 0 deletions packages/prisma/schema/domain.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ model Domain {
project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)
links Link[]
registeredDomain RegisteredDomain?
partnerProgram Program?

@@index(projectId)
@@index(lastChecked(sort: Asc))
Expand Down
3 changes: 2 additions & 1 deletion packages/prisma/schema/program.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ model Program {
defaultGroupId String
name String
slug String @unique
domain String?
domain String? @unique
url String?
logo String? // TODO: remove after we refactor all program.logo fields to use group.logo instead
primaryRewardEvent EventType @default(sale)
Expand All @@ -52,6 +52,7 @@ model Program {
startedAt DateTime?

workspace Project @relation(fields: [workspaceId], references: [id])
customDomain Domain? @relation(fields: [domain], references: [slug])
partners ProgramEnrollment[]
payouts Payout[]
invoices Invoice[]
Expand Down