import { FSDB_COLLECTION } from '@andyburke/fsdb'; import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers'; import { by_character, by_lurid } from '@andyburke/fsdb/organizers'; export type INVITE_CODE = { id: string; creator_id: string; code: string; timestamps: { created: string; expires?: string; cancelled?: string; }; }; export const INVITE_CODES = new FSDB_COLLECTION({ name: 'invite_codes', indexers: { code: new FSDB_INDEXER_SYMLINKS({ name: 'code', field: 'code', organize: by_character }), creator_id: new FSDB_INDEXER_SYMLINKS({ name: 'creator_id', field: 'creator_id', to_many: true, organize: by_lurid }) } }); // TODO: separate out these different validators somewhere? export function VALIDATE_INVITE_CODE(invite_code: INVITE_CODE) { const errors: any[] = []; if (typeof invite_code.id !== 'string' || invite_code.id.length !== 49) { errors.push({ cause: 'invalid_invite_code_id', message: 'An invite code must have a lurid id, eg: able-fish-gold-wing-trip-form-seed-cost-rope-wife' }); } // TODO: further invite code validation if (typeof invite_code.code !== 'string' || invite_code.id.length < 3) { errors.push({ cause: 'invalid_invite_code_code', message: 'An invite code must have a secret code that is at least 3 characters long.' }); } return errors.length ? errors : undefined; }