@tmlmobilidade/controllers 20260130.1448.57 → 20260201.1128.44
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/rides/rides.d.ts +6 -0
- package/dist/rides/rides.js +36 -0
- package/package.json +3 -1
package/dist/rides/rides.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type FastifyReply, type FastifyRequest } from '@tmlmobilidade/fastify';
|
|
2
2
|
import { type ActionsOf, type GetRidesBatchQuery, type Permission, type RideNormalized } from '@tmlmobilidade/types';
|
|
3
|
+
import { type WebSocket } from 'ws';
|
|
3
4
|
export declare class RidesSharedController {
|
|
4
5
|
/**
|
|
5
6
|
* Gets a batch of Rides built with an aggregation pipeline.
|
|
@@ -15,4 +16,9 @@ export declare class RidesSharedController {
|
|
|
15
16
|
* @param reply The Fastify reply object.
|
|
16
17
|
*/
|
|
17
18
|
static getRideById<S extends Permission['scope']>(request: FastifyRequest, reply: FastifyReply<RideNormalized>, scope: S, action: ActionsOf<S>): Promise<never>;
|
|
19
|
+
/**
|
|
20
|
+
* WebSocket event handler.
|
|
21
|
+
* @param socket The WebSocket object.
|
|
22
|
+
*/
|
|
23
|
+
static websocket(socket: WebSocket): void;
|
|
18
24
|
}
|
package/dist/rides/rides.js
CHANGED
|
@@ -41,7 +41,12 @@ export class RidesSharedController {
|
|
|
41
41
|
// Get the rides batch using native MongoDB cursor
|
|
42
42
|
// with batchSize to prevent memory issues
|
|
43
43
|
const pipeline = ridesBatchAggregationPipeline({
|
|
44
|
+
acceptance_status: parsedQuery.acceptance_status,
|
|
44
45
|
agency_ids: parsedQuery.agency_ids?.filter(id => allowAllAgencies || ridesPermission['resources'].agency_ids.includes(id)) ?? [],
|
|
46
|
+
analysis_ended_at_last_stop_grade: parsedQuery.analysis_ended_at_last_stop_grade,
|
|
47
|
+
analysis_expected_apex_validation_interval: parsedQuery.analysis_expected_apex_validation_interval,
|
|
48
|
+
analysis_simple_three_vehicle_events_grade: parsedQuery.analysis_simple_three_vehicle_events_grade,
|
|
49
|
+
analysis_transaction_sequentiality: parsedQuery.analysis_transaction_sequentiality,
|
|
45
50
|
date_end: parsedQuery.date_end,
|
|
46
51
|
date_start: parsedQuery.date_start,
|
|
47
52
|
delay_statuses: parsedQuery.delay_statuses,
|
|
@@ -95,4 +100,35 @@ export class RidesSharedController {
|
|
|
95
100
|
}
|
|
96
101
|
//
|
|
97
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* WebSocket event handler.
|
|
105
|
+
* @param socket The WebSocket object.
|
|
106
|
+
*/
|
|
107
|
+
static websocket(socket) {
|
|
108
|
+
socket.on('message', async () => {
|
|
109
|
+
//
|
|
110
|
+
//
|
|
111
|
+
// Connect to and prepare Rides database collection.
|
|
112
|
+
const ridesCollection = await rides.getCollection();
|
|
113
|
+
//
|
|
114
|
+
// Start a watch service for the database
|
|
115
|
+
// and send updates to the client as they occur.
|
|
116
|
+
ridesCollection
|
|
117
|
+
.watch([], { fullDocument: 'updateLookup' })
|
|
118
|
+
.on('change', (databaseOperation) => {
|
|
119
|
+
if (typeof databaseOperation['fullDocument'] === 'undefined') {
|
|
120
|
+
console.log('Undefined document:', databaseOperation);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const normalizedRide = normalizeRide(databaseOperation['fullDocument']);
|
|
124
|
+
const message = {
|
|
125
|
+
data: normalizedRide,
|
|
126
|
+
error: null,
|
|
127
|
+
statusCode: HttpStatus.OK,
|
|
128
|
+
};
|
|
129
|
+
socket.send(JSON.stringify(message));
|
|
130
|
+
});
|
|
131
|
+
//
|
|
132
|
+
});
|
|
133
|
+
}
|
|
98
134
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmlmobilidade/controllers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "20260201.1128.44",
|
|
4
4
|
"author": {
|
|
5
5
|
"email": "iso@tmlmobilidade.pt",
|
|
6
6
|
"name": "TML-ISO"
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"watch": "tsc-watch --onSuccess 'resolve-tspaths'"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"@fastify/websocket": "11.2.0",
|
|
39
40
|
"@tmlmobilidade/consts": "*",
|
|
40
41
|
"@tmlmobilidade/fastify": "*",
|
|
41
42
|
"@tmlmobilidade/interfaces": "*",
|
|
@@ -47,6 +48,7 @@
|
|
|
47
48
|
"@tmlmobilidade/tsconfig": "*",
|
|
48
49
|
"@tmlmobilidade/types": "*",
|
|
49
50
|
"@types/node": "25.1.0",
|
|
51
|
+
"@types/ws": "8.18.1",
|
|
50
52
|
"resolve-tspaths": "0.8.23",
|
|
51
53
|
"tsc-watch": "7.2.0",
|
|
52
54
|
"typescript": "5.9.3"
|