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.

43 lines (42 loc) 1.3 kB
/* * */ import { MongoCollectionClass } from '../../mongo-collection.js'; import { HttpException, HttpStatus } from '@tmlmobilidade/lib'; import { SessionSchema } from '@tmlmobilidade/types'; import { AsyncSingletonProxy } from '@tmlmobilidade/utils'; /* * */ class SessionsClass extends MongoCollectionClass { static _instance; createSchema = SessionSchema; updateSchema = SessionSchema; constructor() { super(); } static async getInstance() { if (!SessionsClass._instance) { const instance = new SessionsClass(); await instance.connect(); SessionsClass._instance = instance; } return SessionsClass._instance; } /** * Disable Update Many */ async updateMany() { throw new HttpException(HttpStatus.METHOD_NOT_ALLOWED, 'Method not allowed for sessions'); } getCollectionIndexes() { return [ { background: true, key: { user_id: 1 } }, { background: true, key: { expires: 1 } }, { background: true, key: { token: 1 }, unique: true }, ]; } getCollectionName() { return 'sessions'; } getEnvName() { return 'TML_INTERFACE_AUTH'; } } export const sessions = AsyncSingletonProxy(SessionsClass);