@vulog/aima-booking 1.1.98 → 1.1.99
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/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +40 -2
- package/dist/index.mjs +38 -1
- package/package.json +3 -3
- package/src/index.ts +1 -0
- package/src/updateScheduleBooking.test.ts +96 -0
- package/src/updateScheduleBooking.ts +53 -0
package/dist/index.d.mts
CHANGED
|
@@ -200,4 +200,6 @@ declare const allocateVehicle: (client: Client, bookingRequestId: UUID, vehicleI
|
|
|
200
200
|
|
|
201
201
|
declare const deallocateVehicle: (client: Client, bookingRequestId: UUID, vehicleId: UUID) => Promise<SATBookingRequest>;
|
|
202
202
|
|
|
203
|
-
|
|
203
|
+
declare const updateScheduleBooking: (client: Client, bookingRequestId: string, updateData: Record<string, unknown>) => Promise<SATBookingRequest>;
|
|
204
|
+
|
|
205
|
+
export { type BaseBookingRequest, type BookingRequest, type BookingRequestFilters, type BookingRequestStatus, type CustomPrice, type DayOpeningHours, type Days, type GeoInfo, type Include, type IncludeStation, type OpeningHours, type PaymentReceipts, type SATBookingRequest, type SATBookingRequestStatus, type Service, type ServiceInfo, type ServiceType, type Station, type Timetable, allocateVehicle, deallocateVehicle, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getSATBookingRequests, getScheduleBookingRequests, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests, updateScheduleBooking };
|
package/dist/index.d.ts
CHANGED
|
@@ -200,4 +200,6 @@ declare const allocateVehicle: (client: Client, bookingRequestId: UUID, vehicleI
|
|
|
200
200
|
|
|
201
201
|
declare const deallocateVehicle: (client: Client, bookingRequestId: UUID, vehicleId: UUID) => Promise<SATBookingRequest>;
|
|
202
202
|
|
|
203
|
-
|
|
203
|
+
declare const updateScheduleBooking: (client: Client, bookingRequestId: string, updateData: Record<string, unknown>) => Promise<SATBookingRequest>;
|
|
204
|
+
|
|
205
|
+
export { type BaseBookingRequest, type BookingRequest, type BookingRequestFilters, type BookingRequestStatus, type CustomPrice, type DayOpeningHours, type Days, type GeoInfo, type Include, type IncludeStation, type OpeningHours, type PaymentReceipts, type SATBookingRequest, type SATBookingRequestStatus, type Service, type ServiceInfo, type ServiceType, type Station, type Timetable, allocateVehicle, deallocateVehicle, getBookingRequestById, getBookingRequestByTrip, getBookingRequests, getSATBookingRequests, getScheduleBookingRequests, getStationById, getStations, getSubscriptionBookingRequestById, getSubscriptionBookingRequests, updateScheduleBooking };
|
package/dist/index.js
CHANGED
|
@@ -40,7 +40,8 @@ __export(index_exports, {
|
|
|
40
40
|
getStationById: () => getStationById,
|
|
41
41
|
getStations: () => getStations,
|
|
42
42
|
getSubscriptionBookingRequestById: () => getSubscriptionBookingRequestById,
|
|
43
|
-
getSubscriptionBookingRequests: () => getSubscriptionBookingRequests
|
|
43
|
+
getSubscriptionBookingRequests: () => getSubscriptionBookingRequests,
|
|
44
|
+
updateScheduleBooking: () => updateScheduleBooking
|
|
44
45
|
});
|
|
45
46
|
module.exports = __toCommonJS(index_exports);
|
|
46
47
|
|
|
@@ -458,6 +459,42 @@ var deallocateVehicle = async (client, bookingRequestId, vehicleId) => {
|
|
|
458
459
|
`boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/vehicles/${vehicleId}`
|
|
459
460
|
).then(({ data }) => data);
|
|
460
461
|
};
|
|
462
|
+
|
|
463
|
+
// src/updateScheduleBooking.ts
|
|
464
|
+
var import_zod8 = __toESM(require("zod"));
|
|
465
|
+
var schema = import_zod8.default.object({
|
|
466
|
+
id: import_zod8.default.string(),
|
|
467
|
+
startDate: import_zod8.default.string().refine((date) => !Number.isNaN(Date.parse(date)), {
|
|
468
|
+
message: "Invalid date"
|
|
469
|
+
}).optional(),
|
|
470
|
+
latitude: import_zod8.default.number().min(-90).max(90).optional(),
|
|
471
|
+
longitude: import_zod8.default.number().min(-180).max(180).optional(),
|
|
472
|
+
radius: import_zod8.default.number().min(0).optional(),
|
|
473
|
+
userId: import_zod8.default.string().optional(),
|
|
474
|
+
status: import_zod8.default.enum(["CONFIRMED", "CANCELLED", "PENDING"]).optional(),
|
|
475
|
+
cityId: import_zod8.default.string().optional(),
|
|
476
|
+
profileId: import_zod8.default.string().optional(),
|
|
477
|
+
serviceId: import_zod8.default.string().optional(),
|
|
478
|
+
warning: import_zod8.default.string().optional(),
|
|
479
|
+
modelId: import_zod8.default.number().optional(),
|
|
480
|
+
notes: import_zod8.default.string().optional(),
|
|
481
|
+
bookingReferenceId: import_zod8.default.string().optional(),
|
|
482
|
+
plannedReturnDate: import_zod8.default.string().refine((date) => !Number.isNaN(Date.parse(date)), {
|
|
483
|
+
message: "Invalid date"
|
|
484
|
+
}).optional()
|
|
485
|
+
});
|
|
486
|
+
var updateScheduleBooking = async (client, bookingRequestId, updateData) => {
|
|
487
|
+
const result = schema.safeParse({ id: bookingRequestId, ...updateData });
|
|
488
|
+
if (!result.success) {
|
|
489
|
+
throw new TypeError("Invalid args", {
|
|
490
|
+
cause: result.error.issues
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
return client.post(
|
|
494
|
+
`/boapi/proxy/user/scheduleATrip/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}`,
|
|
495
|
+
updateData
|
|
496
|
+
).then(({ data }) => data);
|
|
497
|
+
};
|
|
461
498
|
// Annotate the CommonJS export names for ESM import in node:
|
|
462
499
|
0 && (module.exports = {
|
|
463
500
|
allocateVehicle,
|
|
@@ -470,5 +507,6 @@ var deallocateVehicle = async (client, bookingRequestId, vehicleId) => {
|
|
|
470
507
|
getStationById,
|
|
471
508
|
getStations,
|
|
472
509
|
getSubscriptionBookingRequestById,
|
|
473
|
-
getSubscriptionBookingRequests
|
|
510
|
+
getSubscriptionBookingRequests,
|
|
511
|
+
updateScheduleBooking
|
|
474
512
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -412,6 +412,42 @@ var deallocateVehicle = async (client, bookingRequestId, vehicleId) => {
|
|
|
412
412
|
`boapi/proxy/user/scheduledBooking/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}/vehicles/${vehicleId}`
|
|
413
413
|
).then(({ data }) => data);
|
|
414
414
|
};
|
|
415
|
+
|
|
416
|
+
// src/updateScheduleBooking.ts
|
|
417
|
+
import z8 from "zod";
|
|
418
|
+
var schema = z8.object({
|
|
419
|
+
id: z8.string(),
|
|
420
|
+
startDate: z8.string().refine((date) => !Number.isNaN(Date.parse(date)), {
|
|
421
|
+
message: "Invalid date"
|
|
422
|
+
}).optional(),
|
|
423
|
+
latitude: z8.number().min(-90).max(90).optional(),
|
|
424
|
+
longitude: z8.number().min(-180).max(180).optional(),
|
|
425
|
+
radius: z8.number().min(0).optional(),
|
|
426
|
+
userId: z8.string().optional(),
|
|
427
|
+
status: z8.enum(["CONFIRMED", "CANCELLED", "PENDING"]).optional(),
|
|
428
|
+
cityId: z8.string().optional(),
|
|
429
|
+
profileId: z8.string().optional(),
|
|
430
|
+
serviceId: z8.string().optional(),
|
|
431
|
+
warning: z8.string().optional(),
|
|
432
|
+
modelId: z8.number().optional(),
|
|
433
|
+
notes: z8.string().optional(),
|
|
434
|
+
bookingReferenceId: z8.string().optional(),
|
|
435
|
+
plannedReturnDate: z8.string().refine((date) => !Number.isNaN(Date.parse(date)), {
|
|
436
|
+
message: "Invalid date"
|
|
437
|
+
}).optional()
|
|
438
|
+
});
|
|
439
|
+
var updateScheduleBooking = async (client, bookingRequestId, updateData) => {
|
|
440
|
+
const result = schema.safeParse({ id: bookingRequestId, ...updateData });
|
|
441
|
+
if (!result.success) {
|
|
442
|
+
throw new TypeError("Invalid args", {
|
|
443
|
+
cause: result.error.issues
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
return client.post(
|
|
447
|
+
`/boapi/proxy/user/scheduleATrip/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}`,
|
|
448
|
+
updateData
|
|
449
|
+
).then(({ data }) => data);
|
|
450
|
+
};
|
|
415
451
|
export {
|
|
416
452
|
allocateVehicle,
|
|
417
453
|
deallocateVehicle,
|
|
@@ -423,5 +459,6 @@ export {
|
|
|
423
459
|
getStationById,
|
|
424
460
|
getStations,
|
|
425
461
|
getSubscriptionBookingRequestById,
|
|
426
|
-
getSubscriptionBookingRequests
|
|
462
|
+
getSubscriptionBookingRequests,
|
|
463
|
+
updateScheduleBooking
|
|
427
464
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-booking",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.99",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"author": "Vulog",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@vulog/aima-client": "1.1.
|
|
23
|
-
"@vulog/aima-core": "1.1.
|
|
22
|
+
"@vulog/aima-client": "1.1.99",
|
|
23
|
+
"@vulog/aima-core": "1.1.99"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"es-toolkit": "^1.39.9",
|
package/src/index.ts
CHANGED
|
@@ -10,3 +10,4 @@ export { getStationById } from './getStation';
|
|
|
10
10
|
export type { IncludeStation } from './getStation';
|
|
11
11
|
export { allocateVehicle } from './allocateVehicle';
|
|
12
12
|
export { deallocateVehicle } from './deallocateVehicle';
|
|
13
|
+
export { updateScheduleBooking } from './updateScheduleBooking';
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { updateScheduleBooking } from './updateScheduleBooking';
|
|
2
|
+
import { describe, expect, test, beforeEach, vi } from 'vitest';
|
|
3
|
+
import { Client } from '@vulog/aima-client';
|
|
4
|
+
|
|
5
|
+
describe('updateScheduleBooking', () => {
|
|
6
|
+
const postMock = vi.fn();
|
|
7
|
+
const client = {
|
|
8
|
+
post: postMock,
|
|
9
|
+
clientOptions: {
|
|
10
|
+
fleetId: 'FLEET_ID',
|
|
11
|
+
},
|
|
12
|
+
} as unknown as Client;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
postMock.mockReset();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('should return invalid args', async () => {
|
|
19
|
+
const bookingId = 'BOOKING_ID';
|
|
20
|
+
const updateData = {
|
|
21
|
+
startDate: 'INVALID_DATE', // Invalid date format
|
|
22
|
+
latitude: 91, // Invalid latitude (should be between -90 and 90)
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// expect to throw error if invalid args are provided
|
|
26
|
+
await expect(updateScheduleBooking(client, bookingId, updateData)).rejects.toThrow('Invalid args');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('should update schedule booking successfully', async () => {
|
|
30
|
+
const bookingId = 'booking-123';
|
|
31
|
+
const updateData = {
|
|
32
|
+
startDate: '2024-12-01T10:00:00Z',
|
|
33
|
+
latitude: 48.8566,
|
|
34
|
+
longitude: 2.3522,
|
|
35
|
+
radius: 1000,
|
|
36
|
+
status: 'CONFIRMED' as const,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const mockResponse = {
|
|
40
|
+
id: bookingId,
|
|
41
|
+
startDate: updateData.startDate,
|
|
42
|
+
latitude: updateData.latitude,
|
|
43
|
+
longitude: updateData.longitude,
|
|
44
|
+
status: 'CONFIRMED',
|
|
45
|
+
// other properties of the updated booking
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
postMock.mockResolvedValueOnce({
|
|
49
|
+
data: mockResponse,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const result = await updateScheduleBooking(client, bookingId, updateData);
|
|
53
|
+
expect(result).toEqual(mockResponse);
|
|
54
|
+
expect(postMock).toHaveBeenCalledWith(
|
|
55
|
+
`/boapi/proxy/user/scheduleATrip/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingId}`,
|
|
56
|
+
updateData
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('should update booking with minimal data', async () => {
|
|
61
|
+
const bookingId = 'booking-456';
|
|
62
|
+
const updateData = {
|
|
63
|
+
status: 'CANCELLED' as const,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const mockResponse = {
|
|
67
|
+
id: bookingId,
|
|
68
|
+
status: 'CANCELLED',
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
postMock.mockResolvedValueOnce({
|
|
72
|
+
data: mockResponse,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const result = await updateScheduleBooking(client, bookingId, updateData);
|
|
76
|
+
expect(result).toEqual(mockResponse);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('should validate invalid longitude', async () => {
|
|
80
|
+
const bookingId = 'booking-123';
|
|
81
|
+
const updateData = {
|
|
82
|
+
longitude: 200, // Invalid longitude (should be between -180 and 180)
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
await expect(updateScheduleBooking(client, bookingId, updateData)).rejects.toThrow('Invalid args');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('should validate negative radius', async () => {
|
|
89
|
+
const bookingId = 'booking-123';
|
|
90
|
+
const updateData = {
|
|
91
|
+
radius: -100, // Invalid radius (should be >= 0)
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
await expect(updateScheduleBooking(client, bookingId, updateData)).rejects.toThrow('Invalid args');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// https://java-sta.vulog.com/boapi/proxy/user/scheduleATrip/fleets/LEO-CAMTR/bookingrequests/a8068642-d164-4a7f-b73b-a1019e919db3
|
|
2
|
+
|
|
3
|
+
import { Client } from '@vulog/aima-client';
|
|
4
|
+
import z from 'zod';
|
|
5
|
+
|
|
6
|
+
import { SATBookingRequest } from './types';
|
|
7
|
+
|
|
8
|
+
const schema = z.object({
|
|
9
|
+
id: z.string(),
|
|
10
|
+
startDate: z
|
|
11
|
+
.string()
|
|
12
|
+
.refine((date) => !Number.isNaN(Date.parse(date)), {
|
|
13
|
+
message: 'Invalid date',
|
|
14
|
+
})
|
|
15
|
+
.optional(),
|
|
16
|
+
latitude: z.number().min(-90).max(90).optional(),
|
|
17
|
+
longitude: z.number().min(-180).max(180).optional(),
|
|
18
|
+
radius: z.number().min(0).optional(),
|
|
19
|
+
userId: z.string().optional(),
|
|
20
|
+
status: z.enum(['CONFIRMED', 'CANCELLED', 'PENDING']).optional(),
|
|
21
|
+
cityId: z.string().optional(),
|
|
22
|
+
profileId: z.string().optional(),
|
|
23
|
+
serviceId: z.string().optional(),
|
|
24
|
+
warning: z.string().optional(),
|
|
25
|
+
modelId: z.number().optional(),
|
|
26
|
+
notes: z.string().optional(),
|
|
27
|
+
bookingReferenceId: z.string().optional(),
|
|
28
|
+
plannedReturnDate: z
|
|
29
|
+
.string()
|
|
30
|
+
.refine((date) => !Number.isNaN(Date.parse(date)), {
|
|
31
|
+
message: 'Invalid date',
|
|
32
|
+
})
|
|
33
|
+
.optional(),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const updateScheduleBooking = async (
|
|
37
|
+
client: Client,
|
|
38
|
+
bookingRequestId: string,
|
|
39
|
+
updateData: Record<string, unknown>
|
|
40
|
+
): Promise<SATBookingRequest> => {
|
|
41
|
+
const result = schema.safeParse({ id: bookingRequestId, ...updateData });
|
|
42
|
+
if (!result.success) {
|
|
43
|
+
throw new TypeError('Invalid args', {
|
|
44
|
+
cause: result.error.issues,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return client
|
|
48
|
+
.post<SATBookingRequest>(
|
|
49
|
+
`/boapi/proxy/user/scheduleATrip/fleets/${client.clientOptions.fleetId}/bookingrequests/${bookingRequestId}`,
|
|
50
|
+
updateData
|
|
51
|
+
)
|
|
52
|
+
.then(({ data }) => data);
|
|
53
|
+
};
|