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.21 kB
/* * */ import { MongoCollectionClass } from '../../common/mongo-collection.js'; import { CreateFareSchema, UpdateFareSchema } from '@tmlmobilidade/types'; import { asyncSingletonProxy } from '@tmlmobilidade/utils'; /* * */ class FaresClass extends MongoCollectionClass { static _instance; createSchema = CreateFareSchema; updateSchema = UpdateFareSchema; constructor() { super(); } static async getInstance() { if (!FaresClass._instance) { const instance = new FaresClass(); await instance.connect(); FaresClass._instance = instance; } return FaresClass._instance; } /** * Finds Fare 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 'fares'; } getEnvName() { return 'DATABASE_URI'; } } /* * */ export const fares = asyncSingletonProxy(FaresClass);