You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

27 lines
856 B

import { createTimelineEvent } from "#server/service/timeline";
import { visibilitySchema } from "#server/constants/visibility";
export default defineWrappedResponseHandler(async (event) => {
const user = await event.context.auth.requireUser();
const body = await readBody<{
occurredOn: string;
title: string;
bodyMarkdown?: string | null;
linkUrl?: string | null;
visibility: string;
}>(event);
const occurredOn = new Date(body.occurredOn);
if (Number.isNaN(occurredOn.getTime())) {
throw createError({ statusCode: 400, statusMessage: "occurredOn 无效" });
}
const ev = await createTimelineEvent(user.id, {
occurredOn,
title: body.title,
bodyMarkdown: body.bodyMarkdown,
linkUrl: body.linkUrl,
visibility: visibilitySchema.parse(body.visibility),
});
return R.success({ event: ev });
});