UNPKG

@tmlmobilidade/interfaces

Version:

This package provides SDK-style connectors for interacting with databases (e.g., stops, plans, rides, alerts) and external providers (e.g., authentication, storage). It simplifies data access and integration across projects.

51 lines (50 loc) 1.62 kB
/* * */ import { MongoCollectionClass } from '../../mongo-collection.js'; import { HttpException, HttpStatus } from '@tmlmobilidade/lib'; import { VerificationTokenSchema } from '@tmlmobilidade/types'; import { AsyncSingletonProxy } from '@tmlmobilidade/utils'; /* * */ class VerificationTokensClass extends MongoCollectionClass { static _instance; createSchema = VerificationTokenSchema; updateSchema = VerificationTokenSchema; constructor() { super(); } static async getInstance() { if (!VerificationTokensClass._instance) { const instance = new VerificationTokensClass(); await instance.connect(); VerificationTokensClass._instance = instance; } return VerificationTokensClass._instance; } /** * Finds a verification token by its token. * * @param token - The token to find * @returns The verification token or null if not found */ async findByToken(token) { return this.findOne({ token }); } /** * Disable Update Many */ async updateMany() { throw new HttpException(HttpStatus.METHOD_NOT_ALLOWED, 'Method not allowed for verification tokens'); } getCollectionIndexes() { return [ { background: true, key: { expires_at: 1 } }, { background: true, key: { token: 1 }, unique: true }, ]; } getCollectionName() { return 'verification_tokens'; } getEnvName() { return 'TML_INTERFACE_AUTH'; } } export const verificationTokens = AsyncSingletonProxy(VerificationTokensClass);