@tmlmobilidade/interfaces 20250325.1729.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/src/interfaces/agencies/agencies.interface.d.ts +18 -0
- package/dist/src/interfaces/agencies/agencies.interface.js +46 -0
- package/dist/src/interfaces/alerts/alerts.interface.d.ts +15 -0
- package/dist/src/interfaces/alerts/alerts.interface.js +44 -0
- package/dist/src/interfaces/apex-t11/apex-t11.interface.d.ts +13 -0
- package/dist/src/interfaces/apex-t11/apex-t11.interface.js +37 -0
- package/dist/src/interfaces/apex-t19/apex-t19.interface.d.ts +13 -0
- package/dist/src/interfaces/apex-t19/apex-t19.interface.js +36 -0
- package/dist/src/interfaces/auth/roles.interface.d.ts +24 -0
- package/dist/src/interfaces/auth/roles.interface.js +44 -0
- package/dist/src/interfaces/auth/sessions.interface.d.ts +17 -0
- package/dist/src/interfaces/auth/sessions.interface.js +37 -0
- package/dist/src/interfaces/auth/users.interface.d.ts +97 -0
- package/dist/src/interfaces/auth/users.interface.js +112 -0
- package/dist/src/interfaces/auth/verification-tokens.interface.d.ts +24 -0
- package/dist/src/interfaces/auth/verification-tokens.interface.js +45 -0
- package/dist/src/interfaces/files/files.interface.d.ts +41 -0
- package/dist/src/interfaces/files/files.interface.js +129 -0
- package/dist/src/interfaces/hashed-shapes/hashed-shapes.interface.d.ts +13 -0
- package/dist/src/interfaces/hashed-shapes/hashed-shapes.interface.js +31 -0
- package/dist/src/interfaces/hashed-trips/hashed-trips.interface.d.ts +13 -0
- package/dist/src/interfaces/hashed-trips/hashed-trips.interface.js +32 -0
- package/dist/src/interfaces/index.d.ts +19 -0
- package/dist/src/interfaces/index.js +20 -0
- package/dist/src/interfaces/localities/localities.interface.d.ts +28 -0
- package/dist/src/interfaces/localities/localities.interface.js +49 -0
- package/dist/src/interfaces/municipalities/municipalities.interface.d.ts +28 -0
- package/dist/src/interfaces/municipalities/municipalities.interface.js +49 -0
- package/dist/src/interfaces/organizations/organizations.interface.d.ts +52 -0
- package/dist/src/interfaces/organizations/organizations.interface.js +54 -0
- package/dist/src/interfaces/plans/plans.interface.d.ts +20 -0
- package/dist/src/interfaces/plans/plans.interface.js +38 -0
- package/dist/src/interfaces/rides/rides.interface.d.ts +55 -0
- package/dist/src/interfaces/rides/rides.interface.js +102 -0
- package/dist/src/interfaces/stops/stops.interface.d.ts +30 -0
- package/dist/src/interfaces/stops/stops.interface.js +59 -0
- package/dist/src/interfaces/vehicle-events/vehicle-events.interface.d.ts +13 -0
- package/dist/src/interfaces/vehicle-events/vehicle-events.interface.js +37 -0
- package/dist/src/interfaces/zones/zones.interface.d.ts +35 -0
- package/dist/src/interfaces/zones/zones.interface.js +59 -0
- package/dist/src/providers/auth/auth.d.ts +47 -0
- package/dist/src/providers/auth/auth.js +132 -0
- package/dist/src/providers/email/email.d.ts +21 -0
- package/dist/src/providers/email/email.js +75 -0
- package/dist/src/providers/index.d.ts +5 -0
- package/dist/src/providers/index.js +6 -0
- package/dist/src/providers/storage/s3-storage.d.ts +58 -0
- package/dist/src/providers/storage/s3-storage.js +161 -0
- package/dist/src/providers/storage/storage.factory.d.ts +20 -0
- package/dist/src/providers/storage/storage.factory.js +22 -0
- package/dist/src/providers/storage/storage.interface.d.ts +9 -0
- package/dist/src/providers/storage/storage.interface.js +2 -0
- package/package.json +55 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { MongoCollectionClass } from '@tmlmobilidade/lib';
|
|
2
|
+
import { HttpException, HttpStatus } from '@tmlmobilidade/lib';
|
|
3
|
+
import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
4
|
+
class VerificationTokensClass extends MongoCollectionClass {
|
|
5
|
+
static _instance;
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
}
|
|
9
|
+
static async getInstance() {
|
|
10
|
+
if (!VerificationTokensClass._instance) {
|
|
11
|
+
const instance = new VerificationTokensClass();
|
|
12
|
+
await instance.connect();
|
|
13
|
+
VerificationTokensClass._instance = instance;
|
|
14
|
+
}
|
|
15
|
+
return VerificationTokensClass._instance;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Finds a verification token by its token.
|
|
19
|
+
*
|
|
20
|
+
* @param token - The token to find
|
|
21
|
+
* @returns The verification token or null if not found
|
|
22
|
+
*/
|
|
23
|
+
async findByToken(token) {
|
|
24
|
+
return this.findOne({ token });
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Disable Update Many
|
|
28
|
+
*/
|
|
29
|
+
async updateMany() {
|
|
30
|
+
throw new HttpException(HttpStatus.METHOD_NOT_ALLOWED, 'Method not allowed for verification tokens');
|
|
31
|
+
}
|
|
32
|
+
getCollectionIndexes() {
|
|
33
|
+
return [
|
|
34
|
+
{ background: true, key: { expires_at: 1 } },
|
|
35
|
+
{ background: true, key: { token: 1 }, unique: true },
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
getCollectionName() {
|
|
39
|
+
return 'verification_tokens';
|
|
40
|
+
}
|
|
41
|
+
getEnvName() {
|
|
42
|
+
return 'TML_INTERFACE_AUTH';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export const verificationTokens = AsyncSingletonProxy(VerificationTokensClass);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MongoCollectionClass } from '@tmlmobilidade/lib';
|
|
2
|
+
import { CreateFileDto, File, UpdateFileDto } from '@tmlmobilidade/types';
|
|
3
|
+
import { DeleteResult, IndexDescription, InsertOneResult } from 'mongodb';
|
|
4
|
+
declare class FilesClass extends MongoCollectionClass<File, CreateFileDto, UpdateFileDto> {
|
|
5
|
+
private static _instance;
|
|
6
|
+
private readonly bucketName;
|
|
7
|
+
private readonly storageService;
|
|
8
|
+
private constructor();
|
|
9
|
+
static getInstance(): Promise<FilesClass>;
|
|
10
|
+
/**
|
|
11
|
+
* Deletes a file from the storage service and the database.
|
|
12
|
+
* @param file_id - The unique identifier of the file in the database.
|
|
13
|
+
* @returns The file that was deleted.
|
|
14
|
+
*/
|
|
15
|
+
deleteById(file_id: string): Promise<DeleteResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Retrieves the signed URL of a file from the storage service.
|
|
18
|
+
* @param params - Object containing either `file_id` or `key`.
|
|
19
|
+
* @param params.file_id - The unique identifier of the file in the database.
|
|
20
|
+
* @param params.key - The storage key of the file.
|
|
21
|
+
* @returns The signed URL of the file.
|
|
22
|
+
* @throws {Error} If neither `file_id` nor `key` is provided.
|
|
23
|
+
* @throws {HttpException} If `file_id` is provided but the file is not found.
|
|
24
|
+
*/
|
|
25
|
+
getFileUrl({ file_id, key, }: {
|
|
26
|
+
file_id?: string;
|
|
27
|
+
key?: string;
|
|
28
|
+
}): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Uploads a file to the storage service and inserts it into the database.
|
|
31
|
+
* @param file - The file to upload.
|
|
32
|
+
* @param createFileDto - The file type to create.
|
|
33
|
+
* @returns The file that was uploaded.
|
|
34
|
+
*/
|
|
35
|
+
upload(file: Buffer, createFileDto: CreateFileDto): Promise<InsertOneResult<File>>;
|
|
36
|
+
protected getCollectionIndexes(): IndexDescription[];
|
|
37
|
+
protected getCollectionName(): string;
|
|
38
|
+
protected getEnvName(): string;
|
|
39
|
+
}
|
|
40
|
+
export declare const files: FilesClass;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { StorageFactory } from '../../providers/index.js';
|
|
3
|
+
import { MongoCollectionClass } from '@tmlmobilidade/lib';
|
|
4
|
+
import { HttpStatus } from '@tmlmobilidade/lib';
|
|
5
|
+
import { HttpException } from '@tmlmobilidade/lib';
|
|
6
|
+
import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
7
|
+
import { generateRandomString } from '@tmlmobilidade/utils';
|
|
8
|
+
/* * */
|
|
9
|
+
class FilesClass extends MongoCollectionClass {
|
|
10
|
+
static _instance;
|
|
11
|
+
bucketName;
|
|
12
|
+
storageService;
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
switch (process.env.TML_INTERFACE_FILES_STORAGE_TYPE) {
|
|
16
|
+
case 'aws':
|
|
17
|
+
if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_BUCKET_NAME || !process.env.AWS_SECRET_ACCESS_KEY) {
|
|
18
|
+
throw new Error('AWS_ACCESS_KEY_ID, AWS_BUCKET_NAME, and AWS_SECRET_ACCESS_KEY must be set');
|
|
19
|
+
}
|
|
20
|
+
this.bucketName = process.env.AWS_BUCKET_NAME;
|
|
21
|
+
this.storageService = StorageFactory.create({
|
|
22
|
+
aws_config: {
|
|
23
|
+
access_key_id: process.env.AWS_ACCESS_KEY_ID,
|
|
24
|
+
bucket_name: process.env.AWS_BUCKET_NAME,
|
|
25
|
+
secret_access_key: process.env.AWS_SECRET_ACCESS_KEY,
|
|
26
|
+
},
|
|
27
|
+
type: 'aws',
|
|
28
|
+
});
|
|
29
|
+
break;
|
|
30
|
+
case 'cloudflare':
|
|
31
|
+
if (!process.env.CLOUDFLARE_ACCESS_KEY_ID || !process.env.CLOUDFLARE_BUCKET_NAME || !process.env.CLOUDFLARE_SECRET_ACCESS_KEY) {
|
|
32
|
+
throw new Error('CLOUDFLARE_ACCESS_KEY_ID, CLOUDFLARE_BUCKET_NAME, and CLOUDFLARE_SECRET_ACCESS_KEY must be set');
|
|
33
|
+
}
|
|
34
|
+
this.bucketName = process.env.CLOUDFLARE_BUCKET_NAME;
|
|
35
|
+
this.storageService = StorageFactory.create({
|
|
36
|
+
cloudflare_config: {
|
|
37
|
+
access_key_id: process.env.CLOUDFLARE_ACCESS_KEY_ID,
|
|
38
|
+
bucket_name: process.env.CLOUDFLARE_BUCKET_NAME,
|
|
39
|
+
endpoint: `https://${process.env.CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com`,
|
|
40
|
+
region: 'auto',
|
|
41
|
+
secret_access_key: process.env.CLOUDFLARE_SECRET_ACCESS_KEY,
|
|
42
|
+
},
|
|
43
|
+
type: 'cloudflare',
|
|
44
|
+
});
|
|
45
|
+
break;
|
|
46
|
+
default:
|
|
47
|
+
throw new Error(`Invalid storage type: ${process.env.TML_INTERFACE_FILES_STORAGE_TYPE}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
static async getInstance() {
|
|
51
|
+
if (!FilesClass._instance) {
|
|
52
|
+
const instance = new FilesClass();
|
|
53
|
+
await instance.connect();
|
|
54
|
+
FilesClass._instance = instance;
|
|
55
|
+
}
|
|
56
|
+
return FilesClass._instance;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Deletes a file from the storage service and the database.
|
|
60
|
+
* @param file_id - The unique identifier of the file in the database.
|
|
61
|
+
* @returns The file that was deleted.
|
|
62
|
+
*/
|
|
63
|
+
async deleteById(file_id) {
|
|
64
|
+
const file = await this.findOne({ _id: file_id });
|
|
65
|
+
if (!file) {
|
|
66
|
+
throw new HttpException(HttpStatus.NOT_FOUND, 'File not found');
|
|
67
|
+
}
|
|
68
|
+
await this.storageService.deleteFile(`${file.scope}/${file.resource_id}/${file._id}`);
|
|
69
|
+
return await super.deleteById(file_id);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Retrieves the signed URL of a file from the storage service.
|
|
73
|
+
* @param params - Object containing either `file_id` or `key`.
|
|
74
|
+
* @param params.file_id - The unique identifier of the file in the database.
|
|
75
|
+
* @param params.key - The storage key of the file.
|
|
76
|
+
* @returns The signed URL of the file.
|
|
77
|
+
* @throws {Error} If neither `file_id` nor `key` is provided.
|
|
78
|
+
* @throws {HttpException} If `file_id` is provided but the file is not found.
|
|
79
|
+
*/
|
|
80
|
+
async getFileUrl({ file_id, key, }) {
|
|
81
|
+
if (!file_id && !key) {
|
|
82
|
+
throw new Error('Either "file_id" or "key" must be provided');
|
|
83
|
+
}
|
|
84
|
+
// If `file_id` is provided, fetch the file and use its key
|
|
85
|
+
if (file_id) {
|
|
86
|
+
const file = await this.findOne({ _id: file_id });
|
|
87
|
+
if (!file) {
|
|
88
|
+
throw new HttpException(HttpStatus.NOT_FOUND, 'File not found');
|
|
89
|
+
}
|
|
90
|
+
key = `${file.scope}/${file.resource_id}/${file._id}`; // Use the file's storage key
|
|
91
|
+
}
|
|
92
|
+
// Check if key exists
|
|
93
|
+
const keyExists = await this.storageService.fileExists(key);
|
|
94
|
+
if (!keyExists) {
|
|
95
|
+
throw new HttpException(HttpStatus.NOT_FOUND, `Key ${key} does not exist in bucket ${this.bucketName}`);
|
|
96
|
+
}
|
|
97
|
+
// At this point, `key` must exist
|
|
98
|
+
return this.storageService.getFileUrl(key);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Uploads a file to the storage service and inserts it into the database.
|
|
102
|
+
* @param file - The file to upload.
|
|
103
|
+
* @param createFileDto - The file type to create.
|
|
104
|
+
* @returns The file that was uploaded.
|
|
105
|
+
*/
|
|
106
|
+
async upload(file, createFileDto) {
|
|
107
|
+
const _id = generateRandomString({ length: 5 });
|
|
108
|
+
await this.storageService.uploadFile(`${createFileDto.scope}/${createFileDto.resource_id}/${_id}`, file);
|
|
109
|
+
return await this.insertOne({ ...createFileDto, _id });
|
|
110
|
+
}
|
|
111
|
+
getCollectionIndexes() {
|
|
112
|
+
return [
|
|
113
|
+
{ background: true, key: { created_by: 1 } },
|
|
114
|
+
{ background: true, key: { updated_by: 1 } },
|
|
115
|
+
{ background: true, key: { name: 1 } },
|
|
116
|
+
{ background: true, key: { type: 1 } },
|
|
117
|
+
{ background: true, key: { created_at: -1 } },
|
|
118
|
+
{ background: true, key: { updated_at: -1 } },
|
|
119
|
+
];
|
|
120
|
+
}
|
|
121
|
+
getCollectionName() {
|
|
122
|
+
return 'files';
|
|
123
|
+
}
|
|
124
|
+
getEnvName() {
|
|
125
|
+
return 'TML_INTERFACE_FILES';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/* * */
|
|
129
|
+
export const files = AsyncSingletonProxy(FilesClass);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MongoCollectionClass } from '@tmlmobilidade/lib';
|
|
2
|
+
import { CreateHashedShapeDto, HashedShape, UpdateHashedShapeDto } from '@tmlmobilidade/types';
|
|
3
|
+
import { IndexDescription } from 'mongodb';
|
|
4
|
+
declare class HashedShapesClass extends MongoCollectionClass<HashedShape, CreateHashedShapeDto, UpdateHashedShapeDto> {
|
|
5
|
+
private static _instance;
|
|
6
|
+
private constructor();
|
|
7
|
+
static getInstance(): Promise<HashedShapesClass>;
|
|
8
|
+
protected getCollectionIndexes(): IndexDescription[];
|
|
9
|
+
protected getCollectionName(): string;
|
|
10
|
+
protected getEnvName(): string;
|
|
11
|
+
}
|
|
12
|
+
export declare const hashedShapes: HashedShapesClass;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { MongoCollectionClass } from '@tmlmobilidade/lib';
|
|
3
|
+
import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
4
|
+
/* * */
|
|
5
|
+
class HashedShapesClass extends MongoCollectionClass {
|
|
6
|
+
static _instance;
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
static async getInstance() {
|
|
11
|
+
if (!HashedShapesClass._instance) {
|
|
12
|
+
const instance = new HashedShapesClass();
|
|
13
|
+
await instance.connect();
|
|
14
|
+
HashedShapesClass._instance = instance;
|
|
15
|
+
}
|
|
16
|
+
return HashedShapesClass._instance;
|
|
17
|
+
}
|
|
18
|
+
getCollectionIndexes() {
|
|
19
|
+
return [
|
|
20
|
+
{ background: true, key: { agency_id: 1 } },
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
getCollectionName() {
|
|
24
|
+
return 'hashed_shapes';
|
|
25
|
+
}
|
|
26
|
+
getEnvName() {
|
|
27
|
+
return 'TML_INTERFACE_HASHED_SHAPES';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/* * */
|
|
31
|
+
export const hashedShapes = AsyncSingletonProxy(HashedShapesClass);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MongoCollectionClass } from '@tmlmobilidade/lib';
|
|
2
|
+
import { CreateHashedTripDto, HashedTrip, UpdateHashedTripDto } from '@tmlmobilidade/types';
|
|
3
|
+
import { IndexDescription } from 'mongodb';
|
|
4
|
+
declare class HashedTripsClass extends MongoCollectionClass<HashedTrip, CreateHashedTripDto, UpdateHashedTripDto> {
|
|
5
|
+
private static _instance;
|
|
6
|
+
private constructor();
|
|
7
|
+
static getInstance(): Promise<HashedTripsClass>;
|
|
8
|
+
protected getCollectionIndexes(): IndexDescription[];
|
|
9
|
+
protected getCollectionName(): string;
|
|
10
|
+
protected getEnvName(): string;
|
|
11
|
+
}
|
|
12
|
+
export declare const hashedTrips: HashedTripsClass;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { MongoCollectionClass } from '@tmlmobilidade/lib';
|
|
3
|
+
import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
4
|
+
/* * */
|
|
5
|
+
class HashedTripsClass extends MongoCollectionClass {
|
|
6
|
+
static _instance;
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
static async getInstance() {
|
|
11
|
+
if (!HashedTripsClass._instance) {
|
|
12
|
+
const instance = new HashedTripsClass();
|
|
13
|
+
await instance.connect();
|
|
14
|
+
HashedTripsClass._instance = instance;
|
|
15
|
+
}
|
|
16
|
+
return HashedTripsClass._instance;
|
|
17
|
+
}
|
|
18
|
+
getCollectionIndexes() {
|
|
19
|
+
return [
|
|
20
|
+
{ background: true, key: { agency_id: 1 } },
|
|
21
|
+
{ background: true, key: { line_id: 1 } },
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
getCollectionName() {
|
|
25
|
+
return 'hashed_trips';
|
|
26
|
+
}
|
|
27
|
+
getEnvName() {
|
|
28
|
+
return 'TML_INTERFACE_HASHED_TRIPS';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/* * */
|
|
32
|
+
export const hashedTrips = AsyncSingletonProxy(HashedTripsClass);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from './agencies/agencies.interface.js';
|
|
2
|
+
export * from './alerts/alerts.interface.js';
|
|
3
|
+
export * from './apex-t11/apex-t11.interface.js';
|
|
4
|
+
export * from './apex-t19/apex-t19.interface.js';
|
|
5
|
+
export * from './auth/roles.interface.js';
|
|
6
|
+
export * from './auth/sessions.interface.js';
|
|
7
|
+
export * from './auth/users.interface.js';
|
|
8
|
+
export * from './auth/verification-tokens.interface.js';
|
|
9
|
+
export * from './files/files.interface.js';
|
|
10
|
+
export * from './hashed-shapes/hashed-shapes.interface.js';
|
|
11
|
+
export * from './hashed-trips/hashed-trips.interface.js';
|
|
12
|
+
export * from './localities/localities.interface.js';
|
|
13
|
+
export * from './municipalities/municipalities.interface.js';
|
|
14
|
+
export * from './organizations/organizations.interface.js';
|
|
15
|
+
export * from './plans/plans.interface.js';
|
|
16
|
+
export * from './rides/rides.interface.js';
|
|
17
|
+
export * from './stops/stops.interface.js';
|
|
18
|
+
export * from './vehicle-events/vehicle-events.interface.js';
|
|
19
|
+
export * from './zones/zones.interface.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
export * from './agencies/agencies.interface.js';
|
|
3
|
+
export * from './alerts/alerts.interface.js';
|
|
4
|
+
export * from './apex-t11/apex-t11.interface.js';
|
|
5
|
+
export * from './apex-t19/apex-t19.interface.js';
|
|
6
|
+
export * from './auth/roles.interface.js';
|
|
7
|
+
export * from './auth/sessions.interface.js';
|
|
8
|
+
export * from './auth/users.interface.js';
|
|
9
|
+
export * from './auth/verification-tokens.interface.js';
|
|
10
|
+
export * from './files/files.interface.js';
|
|
11
|
+
export * from './hashed-shapes/hashed-shapes.interface.js';
|
|
12
|
+
export * from './hashed-trips/hashed-trips.interface.js';
|
|
13
|
+
export * from './localities/localities.interface.js';
|
|
14
|
+
export * from './municipalities/municipalities.interface.js';
|
|
15
|
+
export * from './organizations/organizations.interface.js';
|
|
16
|
+
export * from './plans/plans.interface.js';
|
|
17
|
+
export * from './rides/rides.interface.js';
|
|
18
|
+
export * from './stops/stops.interface.js';
|
|
19
|
+
export * from './vehicle-events/vehicle-events.interface.js';
|
|
20
|
+
export * from './zones/zones.interface.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { MongoCollectionClass } from '@tmlmobilidade/lib';
|
|
2
|
+
import { CreateLocalityDto, Locality, UpdateLocalityDto } from '@tmlmobilidade/types';
|
|
3
|
+
import { IndexDescription } from 'mongodb';
|
|
4
|
+
declare class LocalitiesClass extends MongoCollectionClass<Locality, CreateLocalityDto, UpdateLocalityDto> {
|
|
5
|
+
private static _instance;
|
|
6
|
+
private constructor();
|
|
7
|
+
static getInstance(): Promise<LocalitiesClass>;
|
|
8
|
+
/**
|
|
9
|
+
* Finds a locality by its code
|
|
10
|
+
*
|
|
11
|
+
* @param code - The code of the locality to find
|
|
12
|
+
* @returns A promise that resolves to the matching locality document or null if not found
|
|
13
|
+
*/
|
|
14
|
+
findByCode(code: string): Promise<import("mongodb").WithId<Locality> | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Updates a locality by its code
|
|
17
|
+
*
|
|
18
|
+
* @param code - The code of the locality to update
|
|
19
|
+
* @param fields - The fields to update
|
|
20
|
+
* @returns A promise that resolves to the result of the update operation
|
|
21
|
+
*/
|
|
22
|
+
updateByCode(code: string, fields: Partial<Locality>): Promise<import("mongodb").UpdateResult<Locality>>;
|
|
23
|
+
protected getCollectionIndexes(): IndexDescription[];
|
|
24
|
+
protected getCollectionName(): string;
|
|
25
|
+
protected getEnvName(): string;
|
|
26
|
+
}
|
|
27
|
+
export declare const localities: LocalitiesClass;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { MongoCollectionClass } from '@tmlmobilidade/lib';
|
|
2
|
+
import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
3
|
+
class LocalitiesClass extends MongoCollectionClass {
|
|
4
|
+
static _instance;
|
|
5
|
+
constructor() {
|
|
6
|
+
super();
|
|
7
|
+
}
|
|
8
|
+
static async getInstance() {
|
|
9
|
+
if (!LocalitiesClass._instance) {
|
|
10
|
+
const instance = new LocalitiesClass();
|
|
11
|
+
await instance.connect();
|
|
12
|
+
LocalitiesClass._instance = instance;
|
|
13
|
+
}
|
|
14
|
+
return LocalitiesClass._instance;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Finds a locality by its code
|
|
18
|
+
*
|
|
19
|
+
* @param code - The code of the locality to find
|
|
20
|
+
* @returns A promise that resolves to the matching locality document or null if not found
|
|
21
|
+
*/
|
|
22
|
+
async findByCode(code) {
|
|
23
|
+
return this.mongoCollection.findOne({ code });
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Updates a locality by its code
|
|
27
|
+
*
|
|
28
|
+
* @param code - The code of the locality to update
|
|
29
|
+
* @param fields - The fields to update
|
|
30
|
+
* @returns A promise that resolves to the result of the update operation
|
|
31
|
+
*/
|
|
32
|
+
async updateByCode(code, fields) {
|
|
33
|
+
return this.mongoCollection.updateOne({ code }, { $set: fields });
|
|
34
|
+
}
|
|
35
|
+
getCollectionIndexes() {
|
|
36
|
+
return [
|
|
37
|
+
{ background: true, key: { code: 1 }, unique: true },
|
|
38
|
+
{ background: true, key: { name: 1 } },
|
|
39
|
+
{ background: true, key: { prefix: 1 } },
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
getCollectionName() {
|
|
43
|
+
return 'localities';
|
|
44
|
+
}
|
|
45
|
+
getEnvName() {
|
|
46
|
+
return 'TML_INTERFACE_LOCALITIES';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export const localities = AsyncSingletonProxy(LocalitiesClass);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { MongoCollectionClass } from '@tmlmobilidade/lib';
|
|
2
|
+
import { CreateMunicipalityDto, Municipality, UpdateMunicipalityDto } from '@tmlmobilidade/types';
|
|
3
|
+
import { IndexDescription } from 'mongodb';
|
|
4
|
+
declare class MunicipalitiesClass extends MongoCollectionClass<Municipality, CreateMunicipalityDto, UpdateMunicipalityDto> {
|
|
5
|
+
private static _instance;
|
|
6
|
+
private constructor();
|
|
7
|
+
static getInstance(): Promise<MunicipalitiesClass>;
|
|
8
|
+
/**
|
|
9
|
+
* Finds a municipality by its code
|
|
10
|
+
*
|
|
11
|
+
* @param code - The code of the municipality to find
|
|
12
|
+
* @returns A promise that resolves to the matching municipality document or null if not found
|
|
13
|
+
*/
|
|
14
|
+
findByCode(code: string): Promise<import("mongodb").WithId<Municipality> | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Updates a municipality by its code
|
|
17
|
+
*
|
|
18
|
+
* @param code - The code of the municipality to update
|
|
19
|
+
* @param fields - The fields to update
|
|
20
|
+
* @returns A promise that resolves to the result of the update operation
|
|
21
|
+
*/
|
|
22
|
+
updateByCode(code: string, fields: Partial<Municipality>): Promise<import("mongodb").UpdateResult<Municipality>>;
|
|
23
|
+
protected getCollectionIndexes(): IndexDescription[];
|
|
24
|
+
protected getCollectionName(): string;
|
|
25
|
+
protected getEnvName(): string;
|
|
26
|
+
}
|
|
27
|
+
export declare const municipalities: MunicipalitiesClass;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { MongoCollectionClass } from '@tmlmobilidade/lib';
|
|
2
|
+
import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
3
|
+
class MunicipalitiesClass extends MongoCollectionClass {
|
|
4
|
+
static _instance;
|
|
5
|
+
constructor() {
|
|
6
|
+
super();
|
|
7
|
+
}
|
|
8
|
+
static async getInstance() {
|
|
9
|
+
if (!MunicipalitiesClass._instance) {
|
|
10
|
+
const instance = new MunicipalitiesClass();
|
|
11
|
+
await instance.connect();
|
|
12
|
+
MunicipalitiesClass._instance = instance;
|
|
13
|
+
}
|
|
14
|
+
return MunicipalitiesClass._instance;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Finds a municipality by its code
|
|
18
|
+
*
|
|
19
|
+
* @param code - The code of the municipality to find
|
|
20
|
+
* @returns A promise that resolves to the matching municipality document or null if not found
|
|
21
|
+
*/
|
|
22
|
+
async findByCode(code) {
|
|
23
|
+
return this.mongoCollection.findOne({ code });
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Updates a municipality by its code
|
|
27
|
+
*
|
|
28
|
+
* @param code - The code of the municipality to update
|
|
29
|
+
* @param fields - The fields to update
|
|
30
|
+
* @returns A promise that resolves to the result of the update operation
|
|
31
|
+
*/
|
|
32
|
+
async updateByCode(code, fields) {
|
|
33
|
+
return this.mongoCollection.updateOne({ code }, { $set: fields });
|
|
34
|
+
}
|
|
35
|
+
getCollectionIndexes() {
|
|
36
|
+
return [
|
|
37
|
+
{ background: true, key: { code: 1 }, unique: true },
|
|
38
|
+
{ background: true, key: { name: 1 } },
|
|
39
|
+
{ background: true, key: { prefix: 1 } },
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
getCollectionName() {
|
|
43
|
+
return 'municipalities';
|
|
44
|
+
}
|
|
45
|
+
getEnvName() {
|
|
46
|
+
return 'TML_INTERFACE_MUNICIPALITIES';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export const municipalities = AsyncSingletonProxy(MunicipalitiesClass);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { MongoCollectionClass } from '@tmlmobilidade/lib';
|
|
2
|
+
import { CreateOrganizationDto, Organization, UpdateOrganizationDto } from '@tmlmobilidade/types';
|
|
3
|
+
import { IndexDescription, UpdateResult } from 'mongodb';
|
|
4
|
+
declare class OrganizationsClass extends MongoCollectionClass<Organization, CreateOrganizationDto, UpdateOrganizationDto> {
|
|
5
|
+
private static _instance;
|
|
6
|
+
private constructor();
|
|
7
|
+
static getInstance(): Promise<OrganizationsClass>;
|
|
8
|
+
/**
|
|
9
|
+
* Finds an organization by its code
|
|
10
|
+
*
|
|
11
|
+
* @param code - The code of the organization to find
|
|
12
|
+
* @returns A promise that resolves to the matching organization document or null if not found
|
|
13
|
+
*/
|
|
14
|
+
findByCode(code: string): Promise<import("mongodb").WithId<{
|
|
15
|
+
_id: string;
|
|
16
|
+
code: string;
|
|
17
|
+
name: string;
|
|
18
|
+
created_at?: (number & {
|
|
19
|
+
__brand: "UnixTimestamp";
|
|
20
|
+
} & import("zod").BRAND<"UnixTimestamp">) | null | undefined;
|
|
21
|
+
updated_at?: (number & {
|
|
22
|
+
__brand: "UnixTimestamp";
|
|
23
|
+
} & import("zod").BRAND<"UnixTimestamp">) | null | undefined;
|
|
24
|
+
}> | null>;
|
|
25
|
+
/**
|
|
26
|
+
* Updates an organization by its code
|
|
27
|
+
*
|
|
28
|
+
* @param code - The code of the organization to update
|
|
29
|
+
* @param fields - The fields to update
|
|
30
|
+
* @returns A promise that resolves to the result of the update operation
|
|
31
|
+
*/
|
|
32
|
+
updateByCode(code: string, fields: Partial<Organization>): Promise<UpdateResult<{
|
|
33
|
+
_id: string;
|
|
34
|
+
code: string;
|
|
35
|
+
name: string;
|
|
36
|
+
created_at?: (number & {
|
|
37
|
+
__brand: "UnixTimestamp";
|
|
38
|
+
} & import("zod").BRAND<"UnixTimestamp">) | null | undefined;
|
|
39
|
+
updated_at?: (number & {
|
|
40
|
+
__brand: "UnixTimestamp";
|
|
41
|
+
} & import("zod").BRAND<"UnixTimestamp">) | null | undefined;
|
|
42
|
+
}>>;
|
|
43
|
+
/**
|
|
44
|
+
* Disable Update Many
|
|
45
|
+
*/
|
|
46
|
+
updateMany(): Promise<UpdateResult<Organization>>;
|
|
47
|
+
protected getCollectionIndexes(): IndexDescription[];
|
|
48
|
+
protected getCollectionName(): string;
|
|
49
|
+
protected getEnvName(): string;
|
|
50
|
+
}
|
|
51
|
+
export declare const organizations: OrganizationsClass;
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { MongoCollectionClass } from '@tmlmobilidade/lib';
|
|
2
|
+
import { HttpException, HttpStatus } from '@tmlmobilidade/lib';
|
|
3
|
+
import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
4
|
+
class OrganizationsClass extends MongoCollectionClass {
|
|
5
|
+
static _instance;
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
}
|
|
9
|
+
static async getInstance() {
|
|
10
|
+
if (!OrganizationsClass._instance) {
|
|
11
|
+
const instance = new OrganizationsClass();
|
|
12
|
+
await instance.connect();
|
|
13
|
+
OrganizationsClass._instance = instance;
|
|
14
|
+
}
|
|
15
|
+
return OrganizationsClass._instance;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Finds an organization by its code
|
|
19
|
+
*
|
|
20
|
+
* @param code - The code of the organization to find
|
|
21
|
+
* @returns A promise that resolves to the matching organization document or null if not found
|
|
22
|
+
*/
|
|
23
|
+
async findByCode(code) {
|
|
24
|
+
return this.mongoCollection.findOne({ code });
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Updates an organization by its code
|
|
28
|
+
*
|
|
29
|
+
* @param code - The code of the organization to update
|
|
30
|
+
* @param fields - The fields to update
|
|
31
|
+
* @returns A promise that resolves to the result of the update operation
|
|
32
|
+
*/
|
|
33
|
+
async updateByCode(code, fields) {
|
|
34
|
+
return this.mongoCollection.updateOne({ code }, { $set: fields });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Disable Update Many
|
|
38
|
+
*/
|
|
39
|
+
async updateMany() {
|
|
40
|
+
throw new HttpException(HttpStatus.METHOD_NOT_ALLOWED, 'Method not allowed for organizations');
|
|
41
|
+
}
|
|
42
|
+
getCollectionIndexes() {
|
|
43
|
+
return [
|
|
44
|
+
{ background: true, key: { name: 1 }, unique: true },
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
getCollectionName() {
|
|
48
|
+
return 'organizations';
|
|
49
|
+
}
|
|
50
|
+
getEnvName() {
|
|
51
|
+
return 'TML_INTERFACE_ORGANIZATIONS';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export const organizations = AsyncSingletonProxy(OrganizationsClass);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MongoCollectionClass } from '@tmlmobilidade/lib';
|
|
2
|
+
import { CreatePlanDto, Plan, UpdatePlanDto } from '@tmlmobilidade/types';
|
|
3
|
+
import { IndexDescription } from 'mongodb';
|
|
4
|
+
declare class PlansClass extends MongoCollectionClass<Plan, CreatePlanDto, UpdatePlanDto> {
|
|
5
|
+
private static _instance;
|
|
6
|
+
private constructor();
|
|
7
|
+
static getInstance(): Promise<PlansClass>;
|
|
8
|
+
/**
|
|
9
|
+
* Finds Plan documents by agency ID.
|
|
10
|
+
*
|
|
11
|
+
* @param id - The agency ID to search for
|
|
12
|
+
* @returns A promise that resolves to an array of matching documents
|
|
13
|
+
*/
|
|
14
|
+
findByAgencyId(id: string): Promise<import("mongodb").WithId<Plan>[]>;
|
|
15
|
+
protected getCollectionIndexes(): IndexDescription[];
|
|
16
|
+
protected getCollectionName(): string;
|
|
17
|
+
protected getEnvName(): string;
|
|
18
|
+
}
|
|
19
|
+
export declare const plans: PlansClass;
|
|
20
|
+
export {};
|