Migrate the rest of the easy stuff
This commit is contained in:
@@ -6,11 +6,14 @@ export async function onRequestPost(context: RequestContext) {
|
||||
if (typeof path !== "string" || path.length > 256)
|
||||
return jsonError("Invalid path", 400);
|
||||
|
||||
const result = await context.env.D1.prepare(
|
||||
"SELECT path FROM short_links WHERE path = ?;",
|
||||
)
|
||||
.bind(path)
|
||||
.first();
|
||||
const result = await context.data.prisma.shortLink.findUnique({
|
||||
select: {
|
||||
path: true,
|
||||
},
|
||||
where: {
|
||||
path,
|
||||
},
|
||||
});
|
||||
|
||||
if (result)
|
||||
return jsonError(
|
||||
@@ -78,11 +81,13 @@ export async function onRequestPost(context: RequestContext) {
|
||||
400,
|
||||
);
|
||||
|
||||
await context.env.D1.prepare(
|
||||
"INSERT INTO short_links (created_at, destination, path, user) VALUES (?, ?, ?, ?);",
|
||||
)
|
||||
.bind(Date.now(), destination, path, context.data.current_user.id)
|
||||
.run();
|
||||
await context.data.prisma.shortLink.create({
|
||||
data: {
|
||||
destination,
|
||||
path,
|
||||
user: context.data.current_user.id,
|
||||
},
|
||||
});
|
||||
|
||||
return new Response(null, {
|
||||
status: 204,
|
||||
|
||||
Reference in New Issue
Block a user