Aligned getCar call with extra params
MODIFY
src/server/rest/service/CarService.ts
src/server/rest/service/CarService.ts
@@ -308,7 +308,7 @@ export default class CarService {
});
}
// Check Car
- const car = await CarStorage.getCar(req.user.tenantID, filteredRequest.id, true);
+ const car = await CarStorage.getCar(req.user.tenantID, filteredRequest.id, { withUsers: true });
UtilsService.assertObjectExists(action, car, `Car ID '${filteredRequest.id}' does not exist`,
MODULE_NAME, 'handleUpdateCar', req.user);
// Check Owner if Basic
@@ -436,7 +436,7 @@ export default class CarService {
const filteredRequest = CarSecurity.filterCarRequest(req.query);
UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleGetCar', req.user);
// Get the car
- const car = await CarStorage.getCar(req.user.tenantID, filteredRequest.ID, true);
+ const car = await CarStorage.getCar(req.user.tenantID, filteredRequest.ID, { withUsers: true });
if (Authorizations.isBasic(req.user)) {
const userCar = car.usersCar.find((userCarToFind) => userCarToFind.userID.toString() === req.user.id);
if (userCar) {

MODIFY
src/storage/mongodb/CarStorage.ts
src/storage/mongodb/CarStorage.ts
@@ -626,12 +626,13 @@ export default class CarStorage {
return actionsDone;
}
- public static async getCar(tenantID: string, carID: string = Constants.UNKNOWN_STRING_ID, withUsers?: boolean, projectFields?: string[]): Promise<Car> {
+ public static async getCar(tenantID: string, carID: string = Constants.UNKNOWN_STRING_ID,
+ params?: { withUsers?: boolean }, projectFields?: string[]): Promise<Car> {
// Debug
const uniqueTimerID = Logging.traceStart(MODULE_NAME, 'getCar');
// Query single Car
const carsMDB = await CarStorage.getCars(tenantID,
- { carIDs: [carID], withUsers: withUsers },
+ { carIDs: [carID], ...params },
Constants.DB_PARAMS_SINGLE_RECORD, projectFields);
Logging.traceEnd(MODULE_NAME, 'getCar', uniqueTimerID, { carID });
return carsMDB.count > 0 ? carsMDB.result[0] : null;

Aligned getCar call with extra params