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.

48 lines (47 loc) 1.69 kB
/* * */ import { MongoCollectionClass } from '../../mongo-collection.js'; import { AlertSchema, UpdateAlertSchema } from '@tmlmobilidade/types'; import { AsyncSingletonProxy } from '@tmlmobilidade/utils'; /* * */ class AlertsClass extends MongoCollectionClass { static _instance; createSchema = AlertSchema; updateSchema = UpdateAlertSchema; constructor() { super(); } static async getInstance() { if (!AlertsClass._instance) { const instance = new AlertsClass(); await instance.connect(); AlertsClass._instance = instance; } return AlertsClass._instance; } async findByMunicipalityId(municipality_id) { return this.mongoCollection.find({ municipality_ids: { $in: [municipality_id] } }).toArray(); } async findByTitle(title) { return this.mongoCollection.findOne({ title }); } getCollectionIndexes() { return [ { background: true, key: { agency_ids: 1 } }, { background: true, key: { line_ids: 1 } }, { background: true, key: { municipality_ids: 1 } }, { background: true, key: { route_ids: 1 } }, { background: true, key: { stop_ids: 1 } }, { background: true, key: { title: 1 } }, { background: true, key: { active_period_end_date: -1, active_period_start_date: -1 } }, { background: true, key: { publish_end_date: -1, publish_start_date: -1 } }, ]; } getCollectionName() { return 'alerts'; } getEnvName() { return 'TML_INTERFACE_ALERTS'; } } /* * */ export const alerts = AsyncSingletonProxy(AlertsClass);