Fix typos / add default attribute to basic user in getCar
MODIFY
src/server/rest/CentralRestServerService.ts
src/server/rest/CentralRestServerService.ts
@@ -210,7 +210,7 @@ class RequestMapper {
[ServerAction.OCPI_ENDPOINT_UNREGISTER]: OCPIEndpointService.handleUnregisterOcpiEndpoint.bind(this),
[ServerAction.SYNCHRONIZE_CAR_CATALOGS]: CarService.handleSynchronizeCarCatalogs.bind(this),
[ServerAction.CAR_UPDATE]: CarService.handleUpdateCar.bind(this),
- [ServerAction.USER_CAR_UPDATE]: CarService.handleUpdateUsersCar.bind(this),
+ [ServerAction.USERS_CAR_UPDATE]: CarService.handleUpdateUsersCar.bind(this),
});
break;

MODIFY
src/server/rest/service/CarService.ts
src/server/rest/service/CarService.ts
@@ -289,8 +289,8 @@ export default class CarService {
public static async handleUpdateCar(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check if component is active
- UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ORGANIZATION,
- Action.UPDATE, Entity.SITE, MODULE_NAME, 'handleUpdateSite');
+ UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.CAR,
+ Action.UPDATE, Entity.CAR, MODULE_NAME, 'handleUpdateCar');
// Filter
const filteredRequest = CarSecurity.filterCarUpdateRequest(req.body);
// Check
@@ -404,9 +404,14 @@ export default class CarService {
}
const filteredRequest = CarSecurity.filterCarRequest(req.query);
UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleGetCar', req.user);
-
+ let car: Car;
+ if (Authorizations.isBasic(req.user)) {
+ car = await CarStorage.getCar(req.user.tenantID, filteredRequest.ID);
+ car.isDefault = (await CarStorage.getUserCarByCarUser(req.user.tenantID, filteredRequest.ID, req.user.id)).default;
+ } else {
// Get the car
- const car = await CarStorage.getCar(req.user.tenantID, filteredRequest.ID);
+ car = await CarStorage.getCar(req.user.tenantID, filteredRequest.ID);
+ }
// Return
res.json(CarSecurity.filterCarResponse(car, req.user));
@@ -444,7 +449,7 @@ export default class CarService {
public static async handleAssignUsersCar(action: Action, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check if component is active
- UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.CAR, Action.CREATE, Entity.USER_CAR,
+ UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.CAR, Action.CREATE, Entity.USERS_CARS,
MODULE_NAME, 'handleAssignUsersCar');
// Check auth
if (!Authorizations.canAssignUsersCar(req.user)) {
@@ -464,7 +469,7 @@ export default class CarService {
public static async handleUpdateUsersCar(action: Action, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check if component is active
- UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.CAR, Action.UPDATE, Entity.USER_CAR,
+ UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.CAR, Action.UPDATE, Entity.USERS_CARS,
MODULE_NAME, 'handleUpdateUsersCar');
// Check auth
if (!Authorizations.canUpdateUsersCar(req.user)) {

MODIFY
src/server/rest/service/security/CarSecurity.ts
src/server/rest/service/security/CarSecurity.ts
@@ -209,7 +209,9 @@ export default class CarSecurity {
vin: car.vin,
licensePlate: car.licensePlate,
carCatalogID: car.carCatalogID,
- type: car.type
+ type: car.type,
+ converterType: car.converterType,
+ isDefault: car.isDefault
};
}
if (car.users) {

MODIFY
src/storage/mongodb/CarStorage.ts
src/storage/mongodb/CarStorage.ts
@@ -547,7 +547,6 @@ export default class CarStorage {
public static async updateUsersCar(tenantID: string, carID: string, usersCarToSave: UserCar[]): Promise<ActionsResponse> {
// Debug
- const uniqueTimerID = Logging.traceStart(MODULE_NAME, 'updateUsersCar');
const actionsDone: ActionsResponse = {
inSuccess: 0,
inError: 0
@@ -569,7 +568,7 @@ export default class CarStorage {
try {
const userCarDB = await CarStorage.getUserCarByCarUser(tenantID, carID, userCar.userID);
if (userCarDB) {
- if (userCarDB.default !== userCar.default || !userCar.active) {
+ if (userCarDB.default !== userCar.default || !userCarDB.active) {
if (userCar.default) {
await CarStorage.clearDefaultUserCar(tenantID, userCar.userID);
}

MODIFY
src/types/Car.ts
src/types/Car.ts
@@ -138,6 +138,7 @@ export interface Car extends CreatedUpdatedProps {
users?: User[];
type?: CarType;
converterType?: string;
+ isDefault?: boolean;
}
export interface UserCar extends CreatedUpdatedProps {

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -62,7 +62,7 @@ export enum ServerAction {
CAR_MAKERS = 'CarMakers',
CAR_CREATE = 'CarCreate',
CAR_UPDATE = 'CarUpdate',
- USER_CAR_UPDATE = 'UserCarUpdate',
+ USERS_CAR_UPDATE = 'UsersCarUpdate',
CARS = 'Cars',
CAR = 'Car',
USERS_CAR = 'UsersCar',

Fix typos / add default attribute to basic user in getCar