@tmlmobilidade/controllers 20260409.1552.16 → 20260410.1133.41

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.
@@ -16,6 +16,13 @@ export declare class RidesSharedController {
16
16
  * @param reply The Fastify reply object.
17
17
  */
18
18
  static getRideById<S extends Permission['scope']>(request: FastifyRequest, reply: FastifyReply<RideNormalized>, scope: S, action: ActionsOf<S>): Promise<never>;
19
+ /**
20
+ * Get a Ride by multiple IDs.
21
+ * @param request The Fastify request object.
22
+ * @param reply The Fastify reply object.
23
+ */
24
+ n: any;
25
+ static getRideByIds<S extends Permission['scope']>(request: FastifyRequest, reply: FastifyReply<RideNormalized[]>, scope: S, action: ActionsOf<S>): Promise<never>;
19
26
  /**
20
27
  * WebSocket event handler.
21
28
  * @param socket The WebSocket object.
@@ -17,7 +17,6 @@ export class RidesSharedController {
17
17
  //
18
18
  // Validate the request query parameters
19
19
  const parsedQuery = GetRidesBatchQuerySchema.parse(request.query);
20
- console.log('RidesSharedController.getBatch - parsedQuery:', parsedQuery);
21
20
  //
22
21
  // Detect which agency_ids the user has access to,
23
22
  // based on their permissions. If none, return an empty array.
@@ -101,6 +100,33 @@ export class RidesSharedController {
101
100
  }
102
101
  //
103
102
  }
103
+ /**
104
+ * Get a Ride by multiple IDs.
105
+ * @param request The Fastify request object.
106
+ * @param reply The Fastify reply object.
107
+ */
108
+ n;
109
+ static async getRideByIds(request, reply, scope, action) {
110
+ //
111
+ //
112
+ // Detect which agency_ids the user has access to,
113
+ // based on their permissions. If none, return an empty array.
114
+ const ridesPermission = PermissionCatalog.get(request.permissions, scope, action);
115
+ if (!ridesPermission['resources']?.agency_ids?.length)
116
+ return reply.send({ data: null, error: null, statusCode: HTTP_STATUS.OK });
117
+ const allowAllAgencies = ridesPermission['resources'].agency_ids.includes(PermissionCatalog.ALLOW_ALL_FLAG);
118
+ //
119
+ // If search is provided, immediately try to find the ride by ID.
120
+ // If found, return it as the only result. This optimizes
121
+ // for the common case of searching by ride ID.
122
+ const ids = request.query['ids']?.split(',') ?? [];
123
+ const foundRidesByIds = await rides.findMany({
124
+ _id: { $in: ids },
125
+ ...(allowAllAgencies ? {} : { agency_id: { $in: ridesPermission['resources'].agency_ids } }),
126
+ });
127
+ return reply.send({ data: foundRidesByIds.map(ride => normalizeRide(ride)), error: null, statusCode: HTTP_STATUS.OK });
128
+ //
129
+ }
104
130
  /**
105
131
  * WebSocket event handler.
106
132
  * @param socket The WebSocket object.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/controllers",
3
- "version": "20260409.1552.16",
3
+ "version": "20260410.1133.41",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"