mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
27 lines
861 B
TypeScript
27 lines
861 B
TypeScript
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
export async function validateInviteCode(session, inviteCode) {
|
|
const readTxResultPromise = session.readTransaction(async (txc) => {
|
|
const result = await txc.run(
|
|
`MATCH (ic:InviteCode { code: toUpper($inviteCode) })
|
|
RETURN
|
|
CASE
|
|
WHEN ic.expiresAt IS NULL THEN true
|
|
WHEN datetime(ic.expiresAt) >= datetime() THEN true
|
|
ELSE false END AS result`,
|
|
{
|
|
inviteCode,
|
|
},
|
|
)
|
|
return result.records.map((record) => record.get('result'))
|
|
})
|
|
try {
|
|
const txResult = await readTxResultPromise
|
|
return !!txResult[0]
|
|
} finally {
|
|
session.close()
|
|
}
|
|
}
|