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.18 kB
/* * */ import { MongoCollectionClass } from '../../mongo-collection.js'; import { PlanSchema, UpdatePlanSchema } from '@tmlmobilidade/types'; import { AsyncSingletonProxy } from '@tmlmobilidade/utils'; /* * */ class PlansClass extends MongoCollectionClass { static _instance; createSchema = PlanSchema; updateSchema = UpdatePlanSchema; constructor() { super(); } static async getInstance() { if (!PlansClass._instance) { const instance = new PlansClass(); await instance.connect(); PlansClass._instance = instance; } return PlansClass._instance; } /** * Finds Plan documents by agency ID. * * @param id - The agency ID to search for * @returns A promise that resolves to an array of matching documents */ async findByAgencyId(id) { return this.mongoCollection.find({ agency_id: id }).toArray(); } getCollectionIndexes() { return []; } getCollectionName() { return 'plans'; } getEnvName() { return 'TML_INTERFACE_PLANS'; } } /* * */ export const plans = AsyncSingletonProxy(PlansClass);