forked from andyburke/autonomous.contact
feature: start to lay groundwork for reactions
This commit is contained in:
parent
10b3e9ff72
commit
6500d9a9be
4 changed files with 56 additions and 5 deletions
|
|
@ -8,7 +8,7 @@ export type INVITE_CODE = {
|
|||
code: string;
|
||||
timestamps: {
|
||||
created: string;
|
||||
expires?: string;
|
||||
expires: string;
|
||||
cancelled?: string;
|
||||
};
|
||||
};
|
||||
|
|
@ -30,7 +30,7 @@ export const INVITE_CODES = new FSDB_COLLECTION<INVITE_CODE>({
|
|||
}
|
||||
});
|
||||
|
||||
// TODO: separate out these different validators somewhere?
|
||||
const MAX_INVITE_EXPIRE_TIME = 28 * 24 * 60 * 60 * 1_000;
|
||||
export function VALIDATE_INVITE_CODE(invite_code: INVITE_CODE) {
|
||||
const errors: any[] = [];
|
||||
|
||||
|
|
@ -41,7 +41,6 @@ export function VALIDATE_INVITE_CODE(invite_code: INVITE_CODE) {
|
|||
});
|
||||
}
|
||||
|
||||
// TODO: further invite code validation
|
||||
if (typeof invite_code.code !== 'string' || invite_code.id.length < 3) {
|
||||
errors.push({
|
||||
cause: 'invalid_invite_code_code',
|
||||
|
|
@ -49,5 +48,20 @@ export function VALIDATE_INVITE_CODE(invite_code: INVITE_CODE) {
|
|||
});
|
||||
}
|
||||
|
||||
if (typeof invite_code.timestamps?.expires !== 'string') {
|
||||
errors.push({
|
||||
cause: 'missing_invite_expiration',
|
||||
message: 'Invite codes must have an expiration set.'
|
||||
});
|
||||
}
|
||||
|
||||
const expiration_delta = new Date(invite_code.timestamps.expires).valueOf() - new Date(invite_code.timestamps.created).valueOf();
|
||||
if (expiration_delta > MAX_INVITE_EXPIRE_TIME || expiration_delta < 0) {
|
||||
errors.push({
|
||||
cause: 'invite_expiration_invalid',
|
||||
message: 'Invite codes must expire within a limited window after they are created.'
|
||||
});
|
||||
}
|
||||
|
||||
return errors.length ? errors : undefined;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue