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.

49 lines (48 loc) 1.46 kB
/* * */ import { MongoCollectionClass } from '../../mongo-collection.js'; import { AgencySchema, UpdateAgencySchema } from '@tmlmobilidade/types'; import { AsyncSingletonProxy } from '@tmlmobilidade/utils'; /* * */ class AgenciesClass extends MongoCollectionClass { static _instance; createSchema = AgencySchema; updateSchema = UpdateAgencySchema; constructor() { super(); } static async getInstance() { if (!AgenciesClass._instance) { const instance = new AgenciesClass(); await instance.connect(); AgenciesClass._instance = instance; } return AgenciesClass._instance; } async findByCode(code) { return this.mongoCollection.findOne({ code }); } async updateByCode(code, fields) { return this.mongoCollection.updateOne({ code }, { $set: fields }); } getCollectionIndexes() { return [ { background: true, key: { name: 1 }, unique: true }, { background: true, key: { code: 1 }, unique: true }, { background: true, key: { email: 1 }, unique: true }, ]; } getCollectionName() { return 'agencies'; } getCreateSchema() { return AgencySchema; } getEnvName() { return 'TML_INTERFACE_AGENCIES'; } getUpdateSchema() { return UpdateAgencySchema; } } /* * */ export const agencies = AsyncSingletonProxy(AgenciesClass);