@tmlmobilidade/controllers 20260720.2249.10 → 20260723.1350.16
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/dist/exporter/exporter.js +12 -41
- package/dist/operation/hashed-trips/hashed-trips.js +4 -3
- package/dist/operation/lines/batch.js +2 -2
- package/dist/operation/rides/rides.js +6 -5
- package/dist/operation/rides/watch.js +2 -2
- package/dist/operation/stops/batch.js +2 -2
- package/package.json +3 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { HTTP_STATUS, HttpException } from '@tmlmobilidade/consts';
|
|
3
|
-
import {
|
|
3
|
+
import { goDb } from '@tmlmobilidade/go-interfaces-godb';
|
|
4
|
+
import { storageProvider } from '@tmlmobilidade/go-providers-storage';
|
|
4
5
|
import { Logger } from '@tmlmobilidade/logger';
|
|
5
6
|
/* * */
|
|
6
7
|
export class ExporterSharedController {
|
|
@@ -12,7 +13,7 @@ export class ExporterSharedController {
|
|
|
12
13
|
*/
|
|
13
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
15
|
static async create(request, reply) {
|
|
15
|
-
const fileExportData = await
|
|
16
|
+
const fileExportData = await goDb.core.exports.insertOne({ ...request.body, created_by: request.me._id, updated_by: request.me._id });
|
|
16
17
|
return reply.send({ data: fileExportData, error: null, statusCode: HTTP_STATUS.CREATED });
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
@@ -21,52 +22,22 @@ export class ExporterSharedController {
|
|
|
21
22
|
* @param reply The reply object
|
|
22
23
|
*/
|
|
23
24
|
static async download(request, reply) {
|
|
25
|
+
//
|
|
24
26
|
const { id } = request.params;
|
|
25
|
-
const
|
|
27
|
+
const context = { action: 'download', feature: 'exporter', request, value: id };
|
|
28
|
+
// Find file export by ID
|
|
29
|
+
const fileExport = await goDb.core.exports.findById(id);
|
|
26
30
|
if (!fileExport) {
|
|
27
31
|
const error = new HttpException(HTTP_STATUS.NOT_FOUND, 'File export not found');
|
|
28
|
-
Logger.issue({
|
|
29
|
-
context: {
|
|
30
|
-
action: 'download',
|
|
31
|
-
feature: 'exporter',
|
|
32
|
-
request,
|
|
33
|
-
value: id,
|
|
34
|
-
},
|
|
35
|
-
level: 'error',
|
|
36
|
-
messageOrError: error,
|
|
37
|
-
});
|
|
32
|
+
Logger.issue({ context, level: 'error', messageOrError: error });
|
|
38
33
|
throw error;
|
|
39
34
|
}
|
|
40
|
-
// Retrieve file data from
|
|
41
|
-
const foundFileData = await
|
|
42
|
-
if (!foundFileData) {
|
|
43
|
-
const error = new HttpException(HTTP_STATUS.NOT_FOUND, 'File not found');
|
|
44
|
-
Logger.issue({
|
|
45
|
-
context: {
|
|
46
|
-
action: 'download',
|
|
47
|
-
feature: 'exporter',
|
|
48
|
-
request,
|
|
49
|
-
value: id,
|
|
50
|
-
},
|
|
51
|
-
level: 'error',
|
|
52
|
-
messageOrError: error,
|
|
53
|
-
});
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
// Stream the file in the given URL to the client
|
|
35
|
+
// Retrieve file data from storage
|
|
36
|
+
const foundFileData = await storageProvider.findById(fileExport.file_id);
|
|
57
37
|
const storageServiceResponse = await fetch(foundFileData.url);
|
|
58
38
|
if (!storageServiceResponse.ok || !storageServiceResponse.body) {
|
|
59
39
|
const error = new HttpException(HTTP_STATUS.INTERNAL_SERVER_ERROR, 'Could not fetch file');
|
|
60
|
-
Logger.issue({
|
|
61
|
-
context: {
|
|
62
|
-
action: 'download',
|
|
63
|
-
feature: 'exporter',
|
|
64
|
-
request,
|
|
65
|
-
value: id,
|
|
66
|
-
},
|
|
67
|
-
level: 'error',
|
|
68
|
-
messageOrError: error,
|
|
69
|
-
});
|
|
40
|
+
Logger.issue({ context, level: 'error', messageOrError: error });
|
|
70
41
|
throw error;
|
|
71
42
|
}
|
|
72
43
|
// Set headers and pipe the response body to the client
|
|
@@ -88,7 +59,7 @@ export class ExporterSharedController {
|
|
|
88
59
|
const filters = {
|
|
89
60
|
created_by: request.me._id,
|
|
90
61
|
};
|
|
91
|
-
const allFileExport = await
|
|
62
|
+
const allFileExport = await goDb.core.exports.findMany(filters, { sort: { created_at: 1 } });
|
|
92
63
|
return reply.send({ data: allFileExport, error: null, statusCode: HTTP_STATUS.OK });
|
|
93
64
|
}
|
|
94
65
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { HTTP_STATUS } from '@tmlmobilidade/consts';
|
|
3
|
-
import {
|
|
3
|
+
import { goDb } from '@tmlmobilidade/go-interfaces-godb';
|
|
4
|
+
import { ridesBatchAggregationPipeline } from '@tmlmobilidade/interfaces';
|
|
4
5
|
import { Logger } from '@tmlmobilidade/logger';
|
|
5
6
|
import { GetRidesBatchQuerySchema, PermissionCatalog } from '@tmlmobilidade/types';
|
|
6
7
|
/* * */
|
|
@@ -57,13 +58,13 @@ export class HashedTripsSharedController {
|
|
|
57
58
|
pipeline.push({ $limit: 2000 }, { $project: { hashed_trip_id: 1 } }, { $sort: { start_time_scheduled: 1 } });
|
|
58
59
|
//
|
|
59
60
|
// Fetch the rides batch from the database
|
|
60
|
-
const ridesBatch = await rides.aggregate(pipeline);
|
|
61
|
+
const ridesBatch = await goDb.operation.rides.aggregate(pipeline);
|
|
61
62
|
Logger.info({ message: `HashedTripsSharedController.getBatch - ridesBatch count: ${ridesBatch?.length ?? 0}` });
|
|
62
63
|
//
|
|
63
64
|
// From the given batch of hashed_trip_ids,
|
|
64
65
|
// fetch the full HashedTrip documents with a single query.
|
|
65
66
|
const hashedTripIds = ridesBatch.map(ride => ride.hashed_trip_id);
|
|
66
|
-
const hashedTripsBatch = await hashedTrips.findMany({ _id: { $in: hashedTripIds } });
|
|
67
|
+
const hashedTripsBatch = await goDb.operation.hashedTrips.findMany({ _id: { $in: hashedTripIds } });
|
|
67
68
|
//
|
|
68
69
|
// Send the response
|
|
69
70
|
reply.send({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* * */
|
|
2
|
-
import {
|
|
2
|
+
import { goDb } from '@tmlmobilidade/go-interfaces-godb';
|
|
3
3
|
import { Logger } from '@tmlmobilidade/logger';
|
|
4
4
|
/* * */
|
|
5
5
|
export async function getOperationalLinesBatch(query) {
|
|
@@ -69,7 +69,7 @@ export async function getOperationalLinesBatch(query) {
|
|
|
69
69
|
},
|
|
70
70
|
},
|
|
71
71
|
];
|
|
72
|
-
const ridesCollection = await rides.getCollection();
|
|
72
|
+
const ridesCollection = await goDb.operation.rides.getCollection();
|
|
73
73
|
const pipelineResult = await ridesCollection
|
|
74
74
|
.aggregate(pipeline, { allowDiskUse: true })
|
|
75
75
|
.toArray();
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { ridesChangeStream } from './watch.js';
|
|
3
3
|
import { HTTP_STATUS } from '@tmlmobilidade/consts';
|
|
4
|
-
import {
|
|
4
|
+
import { goDb } from '@tmlmobilidade/go-interfaces-godb';
|
|
5
|
+
import { ridesBatchAggregationPipeline } from '@tmlmobilidade/interfaces';
|
|
5
6
|
import { Logger } from '@tmlmobilidade/logger';
|
|
6
7
|
import { normalizeRide } from '@tmlmobilidade/normalizers';
|
|
7
8
|
import { GetRidesBatchQuerySchema, PermissionCatalog } from '@tmlmobilidade/types';
|
|
@@ -40,7 +41,7 @@ export class RidesSharedController {
|
|
|
40
41
|
// If found, return it as the only result. This optimizes
|
|
41
42
|
// for the common case of searching by ride ID.
|
|
42
43
|
const searchQuery = parsedQuery.search?.trim() ?? '';
|
|
43
|
-
const foundRideById = await rides.findOne({
|
|
44
|
+
const foundRideById = await goDb.operation.rides.findOne({
|
|
44
45
|
_id: searchQuery,
|
|
45
46
|
...(allowAllAgencies ? {} : { agency_id: { $in: ridesPermission['resources'].agency_ids } }),
|
|
46
47
|
});
|
|
@@ -74,7 +75,7 @@ export class RidesSharedController {
|
|
|
74
75
|
pipeline.push({ $limit: 2000 }, { $sort: { start_time_scheduled: 1 } });
|
|
75
76
|
//
|
|
76
77
|
// Fetch the rides batch from the database
|
|
77
|
-
const ridesBatch = await rides.aggregate(pipeline);
|
|
78
|
+
const ridesBatch = await goDb.operation.rides.aggregate(pipeline);
|
|
78
79
|
//
|
|
79
80
|
// Send the response
|
|
80
81
|
reply.send({
|
|
@@ -113,7 +114,7 @@ export class RidesSharedController {
|
|
|
113
114
|
// If search is provided, immediately try to find the ride by ID.
|
|
114
115
|
// If found, return it as the only result. This optimizes
|
|
115
116
|
// for the common case of searching by ride ID.
|
|
116
|
-
const foundRideById = await rides.findOne({
|
|
117
|
+
const foundRideById = await goDb.operation.rides.findOne({
|
|
117
118
|
_id: request.params['id'],
|
|
118
119
|
...(allowAllAgencies ? {} : { agency_id: { $in: ridesPermission['resources'].agency_ids } }),
|
|
119
120
|
});
|
|
@@ -154,7 +155,7 @@ export class RidesSharedController {
|
|
|
154
155
|
// If found, return it as the only result. This optimizes
|
|
155
156
|
// for the common case of searching by ride ID.
|
|
156
157
|
const ids = request.query['ids']?.split(',') ?? [];
|
|
157
|
-
const foundRidesByIds = await rides.findMany({
|
|
158
|
+
const foundRidesByIds = await goDb.operation.rides.findMany({
|
|
158
159
|
_id: { $in: ids },
|
|
159
160
|
...(allowAllAgencies ? {} : { agency_id: { $in: ridesPermission['resources'].agency_ids } }),
|
|
160
161
|
});
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* - Reduced database load and network overhead
|
|
25
25
|
*/
|
|
26
26
|
import { HTTP_STATUS } from '@tmlmobilidade/consts';
|
|
27
|
-
import {
|
|
27
|
+
import { goDb } from '@tmlmobilidade/go-interfaces-godb';
|
|
28
28
|
import { normalizeRide } from '@tmlmobilidade/normalizers';
|
|
29
29
|
import { asyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
30
30
|
import EventEmitter from 'events';
|
|
@@ -89,7 +89,7 @@ class RidesChangeStreamManager {
|
|
|
89
89
|
async init() {
|
|
90
90
|
if (this.initialized)
|
|
91
91
|
return;
|
|
92
|
-
const ridesCollection = await rides.getCollection();
|
|
92
|
+
const ridesCollection = await goDb.operation.rides.getCollection();
|
|
93
93
|
// Watch all operations with full document updates
|
|
94
94
|
ridesCollection
|
|
95
95
|
.watch([], { fullDocument: 'updateLookup' })
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* * */
|
|
2
|
-
import {
|
|
2
|
+
import { goDb } from '@tmlmobilidade/go-interfaces-godb';
|
|
3
3
|
import { Logger } from '@tmlmobilidade/logger';
|
|
4
4
|
/* * */
|
|
5
5
|
export async function getOperationalStopsBatch(query) {
|
|
@@ -69,7 +69,7 @@ export async function getOperationalStopsBatch(query) {
|
|
|
69
69
|
},
|
|
70
70
|
},
|
|
71
71
|
];
|
|
72
|
-
const ridesCollection = await rides.getCollection();
|
|
72
|
+
const ridesCollection = await goDb.operation.rides.getCollection();
|
|
73
73
|
const pipelineResult = await ridesCollection
|
|
74
74
|
.aggregate(pipeline, { allowDiskUse: true })
|
|
75
75
|
.toArray();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmlmobilidade/controllers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "20260723.1350.16",
|
|
4
4
|
"author": {
|
|
5
5
|
"email": "iso@tmlmobilidade.pt",
|
|
6
6
|
"name": "TML-ISO"
|
|
@@ -38,7 +38,9 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@tmlmobilidade/consts": "*",
|
|
40
40
|
"@tmlmobilidade/fastify": "*",
|
|
41
|
+
"@tmlmobilidade/go-clients-mongo": "*",
|
|
41
42
|
"@tmlmobilidade/go-interfaces-godb": "*",
|
|
43
|
+
"@tmlmobilidade/go-providers-storage": "*",
|
|
42
44
|
"@tmlmobilidade/interfaces": "*",
|
|
43
45
|
"@tmlmobilidade/logger": "*",
|
|
44
46
|
"@tmlmobilidade/normalizers": "*",
|