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.

48 lines (47 loc) 1.56 kB
/* * */ import { MongoCollectionClass } from '../../common/mongo-collection.js'; import { CreateVerificationTokenSchema, UpdateVerificationTokenSchema } from '@tmlmobilidade/types'; import { asyncSingletonProxy } from '@tmlmobilidade/utils'; /* * */ class VerificationTokensClass extends MongoCollectionClass { static _instance; createSchema = CreateVerificationTokenSchema; updateSchema = UpdateVerificationTokenSchema; 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 }); } getCollectionIndexes() { return [ { background: true, key: { expires_at: 1 } }, { background: true, key: { token: 1 }, unique: true }, ]; } getCollectionName() { return 'verification_tokens'; } getEnvName() { return 'DATABASE_URI'; } } /* * */ /** * @deprecated This class is deprecated and will be removed in the future. * Use `@tmlmobilidade/go-interfaces-go-db` instead. */ export const verificationTokens = asyncSingletonProxy(VerificationTokensClass);