forked from dubinc/dub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
35 changed files
with
715 additions
and
1,349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { transferLink } from "@/lib/api/links"; | ||
import { withAuth } from "@/lib/auth"; | ||
import { qstash } from "@/lib/cron"; | ||
import prisma from "@/lib/prisma"; | ||
import { APP_DOMAIN_WITH_NGROK } from "@dub/utils"; | ||
import { NextResponse } from "next/server"; | ||
|
||
// POST /api/links/[linkId]/transfer – transfer a link to another project | ||
export const POST = withAuth(async ({ req, headers, session, link }) => { | ||
let body: { newProjectId: string }; | ||
|
||
try { | ||
body = await req.json(); | ||
} catch (error) { | ||
return new Response("Missing or invalid body.", { status: 400, headers }); | ||
} | ||
|
||
if (!body.newProjectId) { | ||
return new Response("Missing new project ID.", { status: 400, headers }); | ||
} | ||
|
||
const newProject = await prisma.project.findUnique({ | ||
where: { id: body.newProjectId }, | ||
select: { | ||
linksUsage: true, | ||
linksLimit: true, | ||
users: { | ||
where: { | ||
userId: session.user.id, | ||
}, | ||
select: { | ||
role: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
if (!newProject || newProject.users.length === 0) { | ||
return new Response("New project not found.", { status: 404, headers }); | ||
} | ||
|
||
if (newProject.linksUsage >= newProject.linksLimit) { | ||
return new Response("New project has reached its link limit.", { | ||
status: 403, | ||
headers, | ||
}); | ||
} | ||
|
||
const response = await Promise.all([ | ||
transferLink({ | ||
linkId: link!.id, | ||
newProjectId: body.newProjectId, | ||
}), | ||
qstash.publishJSON({ | ||
url: `${APP_DOMAIN_WITH_NGROK}/api/cron/links/event`, | ||
body: { | ||
linkId: link!.id, | ||
type: "transfer", | ||
}, | ||
}), | ||
]); | ||
|
||
return NextResponse.json(response, { | ||
headers, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.