@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.28 kB
JavaScript
/* * */
import { MongoCollectionClass } from '../../common/mongo-collection.js';
import { CreateAnnotationSchema, UpdateAnnotationSchema } from '@tmlmobilidade/types';
import { asyncSingletonProxy } from '@tmlmobilidade/utils';
/* * */
class AnnotationsClass extends MongoCollectionClass {
static _instance;
createSchema = CreateAnnotationSchema;
updateSchema = UpdateAnnotationSchema;
constructor() {
super();
}
static async getInstance() {
if (!AnnotationsClass._instance) {
const instance = new AnnotationsClass();
await instance.connect();
AnnotationsClass._instance = instance;
}
return AnnotationsClass._instance;
}
/**
* Finds Annotation documents by agency IDs.
*
* @param ids - The agency IDs to search for
* @returns A promise that resolves to an array of matching documents
*/
async findByAgencyIds(ids) {
return this.mongoCollection.find({ agency_ids: { $in: ids } }).toArray();
}
getCollectionIndexes() {
return [];
}
getCollectionName() {
return 'annotations';
}
getEnvName() {
return 'DATABASE_URI';
}
}
/* * */
export const annotations = asyncSingletonProxy(AnnotationsClass);