@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.
47 lines (46 loc) • 1.48 kB
JavaScript
/* * */
import { MongoCollectionClass } from '../../common/mongo-collection.js';
import { CreateAgencySchema, UpdateAgencySchema } from '@tmlmobilidade/types';
import { asyncSingletonProxy } from '@tmlmobilidade/utils';
/* * */
class AgenciesClass extends MongoCollectionClass {
static _instance;
createSchema = CreateAgencySchema;
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';
}
getEnvName() {
return 'DATABASE_URI';
}
}
/* * */
/**
* @deprecated This class is deprecated and will be removed in the future.
* Use `@tmlmobilidade/go-interfaces-go-db` instead.
*/
export const agencies = asyncSingletonProxy(AgenciesClass);