Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Merge pull request #2785 from sap-labs-france/improve-default-car-tag…
Browse files Browse the repository at this point in the history
…-endpoint

Add new projected fields to Get User Default Tag Car endpoint
  • Loading branch information
LucasBrazi06 authored Sep 6, 2021
2 parents d69eaf4 + 9937d98 commit ec0e018
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/server/rest/v1/service/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Car, CarType } from '../../../../types/Car';
import { DataResult, UserDataResult } from '../../../../types/DataResult';
import { HTTPAuthError, HTTPError } from '../../../../types/HTTPError';
import { NextFunction, Request, Response } from 'express';
import Tenant, { TenantComponents } from '../../../../types/Tenant';
import User, { ImportedUser, UserRequiredImportProperties } from '../../../../types/User';

import AppAuthError from '../../../../exception/AppAuthError';
Expand All @@ -31,8 +32,6 @@ import { ServerAction } from '../../../../types/Server';
import SiteStorage from '../../../../storage/mongodb/SiteStorage';
import { StartTransactionErrorCode } from '../../../../types/Transaction';
import TagStorage from '../../../../storage/mongodb/TagStorage';
import Tenant from '../../../../types/Tenant';
import { TenantComponents } from '../../../../types/Tenant';
import { UserInErrorType } from '../../../../types/InError';
import UserNotifications from '../../../../types/UserNotifications';
import UserStorage from '../../../../storage/mongodb/UserStorage';
Expand Down Expand Up @@ -60,24 +59,24 @@ export default class UserService {
// Get the default Tag
let tag = await TagStorage.getDefaultUserTag(req.tenant, user.id, {
issuer: true
}, ['visualID', 'description', 'active']);
}, ['visualID', 'description', 'active', 'default']);
if (!tag) {
// Get the first active Tag
tag = await TagStorage.getFirstActiveUserTag(req.tenant, user.id, {
issuer: true
}, ['visualID', 'description', 'active']);
}, ['visualID', 'description', 'active', 'default']);
}
// Handle Car
let car: Car;
if (Utils.isComponentActiveFromToken(req.user, TenantComponents.CAR)) {
// Get the default Car
car = await CarStorage.getDefaultUserCar(req.tenant, filteredRequest.UserID, {},
['id', 'type', 'licensePlate', 'carCatalog.vehicleMake', 'carCatalog.vehicleModel', 'carCatalog.vehicleModelVersion']
['id', 'type', 'licensePlate', 'carCatalog.vehicleMake', 'carCatalog.vehicleModel', 'carCatalog.vehicleModelVersion', 'carCatalog.image', 'carCatalog.batteryCapacityFull', 'carCatalog.fastChargePowerMax', 'converter.powerWatts', 'converter.numberOfPhases', 'default']
);
if (!car) {
// Get the first available car
car = await CarStorage.getFirstAvailableUserCar(req.tenant, filteredRequest.UserID,
['id', 'type', 'licensePlate', 'carCatalog.vehicleMake', 'carCatalog.vehicleModel', 'carCatalog.vehicleModelVersion']
['id', 'type', 'licensePlate', 'carCatalog.vehicleMake', 'carCatalog.vehicleModel', 'carCatalog.vehicleModelVersion', 'carCatalog.image', 'carCatalog.batteryCapacityFull', 'carCatalog.fastChargePowerMax', 'converter.powerWatts', 'converter.numberOfPhases', 'default']
);
}
}
Expand Down Expand Up @@ -489,7 +488,7 @@ export default class UserService {
user.importedBy = importedBy;
user.importedOn = importedOn;
user.importedData = {
'autoActivateUserAtImport' : UtilsSecurity.filterBoolean(req.headers.autoactivateuseratimport)
'autoActivateUserAtImport': UtilsSecurity.filterBoolean(req.headers.autoactivateuseratimport)
};
// Import
const importSuccess = await UserService.processUser(action, req, user, usersToBeImported);
Expand Down

0 comments on commit ec0e018

Please sign in to comment.