fix(invitations): fix expires requirement in the admin endpoint
This commit is contained in:
parent
be6c30dfee
commit
c7b675f841
1 changed files with 11 additions and 0 deletions
|
|
@ -8,18 +8,29 @@ export default defineEventHandler(async (h3) => {
|
|||
const isAdmin = body.isAdmin;
|
||||
const username = body.username;
|
||||
const email = body.email;
|
||||
const expires = body.expires;
|
||||
|
||||
if (!expires)
|
||||
throw createError({ statusCode: 400, statusMessage: "No expires field." });
|
||||
if (isAdmin !== undefined && typeof isAdmin !== "boolean")
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "isAdmin must be a boolean",
|
||||
});
|
||||
|
||||
const expiresDate = new Date(expires);
|
||||
if (!(expiresDate instanceof Date && !isNaN(expiresDate.getTime())))
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Invalid expires date",
|
||||
});
|
||||
|
||||
const invitation = await prisma.invitation.create({
|
||||
data: {
|
||||
isAdmin: isAdmin,
|
||||
username: username,
|
||||
email: email,
|
||||
expires: expiresDate
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue