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.

42 lines (41 loc) 1.22 kB
/* * */ import { MongoCollectionClass } from '../../common/mongo-collection.js'; import { CreateEventSchema, UpdateEventSchema } from '@tmlmobilidade/types'; import { asyncSingletonProxy } from '@tmlmobilidade/utils'; /* * */ class EventsClass extends MongoCollectionClass { static _instance; createSchema = CreateEventSchema; updateSchema = UpdateEventSchema; constructor() { super(); } static async getInstance() { if (!EventsClass._instance) { const instance = new EventsClass(); await instance.connect(); EventsClass._instance = instance; } return EventsClass._instance; } /** * Finds Event documents by agency IDs. * * @param ids - The agency IDs to search for * @returns A promise that resolves to an array of matching documents */ async findByAgencyIds(ids) { return this.mongoCollection.find({ agency_ids: { $in: ids } }).toArray(); } getCollectionIndexes() { return []; } getCollectionName() { return 'events'; } getEnvName() { return 'DATABASE_URI'; } } /* * */ export const events = asyncSingletonProxy(EventsClass);