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