Files
car-crushers-portal/functions/api/short-links/[[id]].ts
Regalijan cfc57c838e
All checks were successful
Test, Build, Deploy / Test, Build, and Deploy (push) Successful in 55s
Test, Build, Deploy / Create Sentry Release (push) Successful in 6s
More events team nonsense
2026-04-11 03:30:46 -04:00

55 lines
1.2 KiB
TypeScript

import { jsonError } from "../../common.js";
export async function onRequestDelete(context: RequestContext) {
const path = decodeURIComponent(context.params.id as string);
await context.data.prisma.shortLink.delete({
where: {
path,
user: context.data.current_user.id,
},
});
return new Response(null, {
status: 204,
});
}
export async function onRequestPatch(context: RequestContext) {
const { body } = context.data;
if (!body) return jsonError("Request body missing", 400);
let data: { path: any };
try {
data = JSON.parse(body);
} catch {
return jsonError("Invalid JSON", 400);
}
if (Object.keys(data).find((k) => k !== "path"))
return jsonError("Only the `path` property can be modified.", 400);
const { path } = data;
if (typeof path !== "string")
return jsonError("The `path` property must be a string", 400);
if (path.length > 256) return jsonError("Path is too long", 400);
await context.data.prisma.shortLink.update({
data: {
path,
},
where: {
path: decodeURIComponent(context.params.id as string),
user: context.data.current_user.id,
},
});
return new Response(null, {
status: 204,
});
}