Added getUser endpoint + doc
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
{
"$ref": "#/components/parameters/Issuer"
},
- {
- "$ref": "#/components/parameters/WithTag"
- },
{
"$ref": "#/components/parameters/Search"
},
"$ref": "#/components/parameters/SiteID"
},
{
- "$ref": "#/components/parameters/Role"
- },
- {
- "$ref": "#/components/parameters/Status"
- },
- {
- "$ref": "#/components/parameters/UserErrorType"
+ "in": "query",
+ "name": "Role",
+ "required": false,
+ "description": "Role attribute",
+ "schema": {
+ "type": "string",
+ "enum": [
+ "S",
+ "A",
+ "B",
+ "D"
+ ]
+ }
},
{
- "$ref": "#/components/parameters/ExcludeSiteID"
+ "in": "query",
+ "name": "Status",
+ "description": "Status attribute",
+ "schema": {
+ "type": "string",
+ "enum": [
+ "P",
+ "A",
+ "I",
+ "B",
+ "L"
+ ]
+ }
},
{
- "$ref": "#/components/parameters/TagID"
+ "in": "query",
+ "name": "ExcludeSiteID",
+ "required": false,
+ "description": "Site ID to exclude",
+ "schema": {
+ "type": "string"
+ }
},
{
"in": "query",
}
}
}
+ },
+ "/api/users/{id}": {
+ "get": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Retrieve a User",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/UserIDPath"
+ },
+ {
+ "$ref": "#/components/parameters/ProjectFields"
+ }
+ ],
+ "tags": [
+ "Users"
+ ],
+ "responses": {
+ "200": {
+ "description": "Retrieved user",
+ "content": {
+ "application/json": {
+ "example": {
+ "address": {
+ "address1": "",
+ "address2": "",
+ "postalCode": "",
+ "city": "",
+ "department": "",
+ "region": "",
+ "country": "",
+ "coordinates": []
+ },
+ "costCenter": null,
+ "deleted": false,
+ "email": "###",
+ "firstName": "###",
+ "iNumber": null,
+ "locale": "fr_FR",
+ "mobile": null,
+ "name": "###",
+ "phone": null,
+ "role": "A",
+ "status": "A",
+ "notifications": {
+ "sendSessionStarted": false,
+ "sendOptimalChargeReached": false,
+ "sendEndOfCharge": false,
+ "sendEndOfSession": false,
+ "sendUserAccountStatusChanged": false,
+ "sendNewRegisteredUser": false,
+ "sendUnknownUserBadged": false,
+ "sendChargingStationStatusError": true,
+ "sendChargingStationRegistered": false,
+ "sendOcpiPatchStatusError": false,
+ "sendSmtpError": false,
+ "sendUserAccountInactivity": false,
+ "sendPreparingSessionNotStarted": false,
+ "sendOfflineChargingStations": false,
+ "sendBillingSynchronizationFailed": false,
+ "sendSessionNotStarted": false,
+ "sendCarCatalogSynchronizationFailed": false,
+ "sendEndUserErrorNotification": true,
+ "sendComputeAndApplyChargingProfilesFailed": false,
+ "sendBillingNewInvoice": false,
+ "sendAccountVerificationNotification": false,
+ "sendAdminAccountVerificationNotification": true
+ },
+ "notificationsActive": true,
+ "plateID": "###",
+ "issuer": true,
+ "id": "###"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/500BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
+ }
+ }
}
},
"components": {
},
"NotSupportedError": {
"description": "Feature not supported"
+ },
+ "ResourceDoesNotExists": {
+ "description": "Resource does not exist"
}
},
"schemas": {
"type": "string"
}
},
+ "UserIDPath": {
+ "in": "path",
+ "name": "id",
+ "description": "User ID",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ },
"ChargingStationID": {
"in": "query",
"name": "ChargingStationID",
"WithSite": {
"in": "query",
"name": "WithSite",
+ "required": false,
"description": "With site attribute",
"schema": {
"type": "boolean"
}
- },
- "WithTag": {
- "in": "query",
- "name": "WithTag",
- "description": "With tag attribute",
- "schema": {
- "type": "boolean"
- }
- },
- "Role": {
- "in": "query",
- "name": "Role",
- "description": "Role attribute",
- "schema": {
- "type": "string",
- "enum": [
- "S",
- "A",
- "B",
- "D"
- ]
- }
- },
- "Status": {
- "in": "query",
- "name": "Status",
- "description": "Status attribute",
- "schema": {
- "type": "string",
- "enum": [
- "P",
- "A",
- "I",
- "B",
- "L"
- ]
- }
- },
- "UserErrorType": {
- "in": "query",
- "name": "ErrorType",
- "description": "Error type",
- "schema": {
- "type": "string",
- "enum": [
- "inactive_user",
- "unassigned_user",
- "inactive_user_account",
- "failed_billing_synchro",
- "no_billing_data"
- ]
- }
- },
- "ExcludeSiteID": {
- "in": "query",
- "name": "ExcludeSiteID",
- "description": "Site ID to exclude",
- "schema": {
- "type": "string"
- }
}
}
}

MODIFY
src/server/rest/v1/router/api/UserRouter.ts
src/server/rest/v1/router/api/UserRouter.ts
@@ -3,9 +3,7 @@ import { ServerAction, ServerRoute } from '../../../../../types/Server';
import express, { NextFunction, Request, Response } from 'express';
import RouterUtils from '../RouterUtils';
-import TenantService from '../../service/TenantService';
import UserService from '../../service/UserService';
-import sanitize from 'mongo-sanitize';
export default class UserRouter {
private router: express.Router;
@@ -16,6 +14,7 @@ export default class UserRouter {
public buildRoutes(): express.Router {
this.buildRouteUsers();
+ this.buildRouteUser();
return this.router;
}
@@ -24,4 +23,11 @@ export default class UserRouter {
await RouterUtils.handleServerAction(UserService.handleGetUsers.bind(this), ServerAction.USERS, req, res, next);
});
}
+
+ protected buildRouteUser(): void {
+ this.router.get(`/${ServerRoute.REST_USER}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(UserService.handleGetUser.bind(this), ServerAction.USER, req, res, next);
+ });
+ }
}

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -200,7 +200,7 @@ export default class UserService {
await UserStorage.removeSitesFromUser(req.user.tenantID, filteredRequest.userID, filteredRequest.siteIDs);
}
// Log
- Logging.logSecurityInfo({
+ await Logging.logSecurityInfo({
tenantID: req.user.tenantID,
user: req.user, module: MODULE_NAME, method: 'handleAssignSitesToUser',
message: 'User\'s Sites have been assigned successfully', action: action
@@ -376,7 +376,7 @@ export default class UserService {
}
}
} catch (error) {
- Logging.logError({
+ await Logging.logError({
tenantID: req.user.tenantID,
module: MODULE_NAME,
method: 'handleUpdateTag',
@@ -392,7 +392,7 @@ export default class UserService {
try {
await billingImpl.deleteUser(user);
} catch (error) {
- Logging.logError({
+ await Logging.logError({
tenantID: req.user.tenantID,
action: action,
module: MODULE_NAME, method: 'handleDeleteUser',
@@ -405,7 +405,7 @@ export default class UserService {
// Delete Connections
await ConnectionStorage.deleteConnectionByUserId(req.user.tenantID, user.id);
// Log
- Logging.logSecurityInfo({
+ await Logging.logSecurityInfo({
tenantID: req.user.tenantID,
user: req.user, actionOnUser: user,
module: MODULE_NAME, method: 'handleDeleteUser',
@@ -506,7 +506,7 @@ export default class UserService {
const billingUser = await billingImpl.updateUser(user);
await UserStorage.saveUserBillingData(req.user.tenantID, user.id, billingUser.billingData);
} catch (error) {
- Logging.logError({
+ await Logging.logError({
tenantID: req.user.tenantID,
action: action,
module: MODULE_NAME, method: 'handleUpdateUser',
@@ -548,7 +548,7 @@ export default class UserService {
}
}
// Log
- Logging.logSecurityInfo({
+ await Logging.logSecurityInfo({
tenantID: req.user.tenantID,
user: req.user, actionOnUser: user,
module: MODULE_NAME, method: 'handleUpdateUser',
@@ -623,7 +623,7 @@ export default class UserService {
mobileLastChangedOn: new Date()
});
// Log
- Logging.logSecurityInfo({
+ await Logging.logSecurityInfo({
tenantID: req.user.tenantID,
user: user,
module: MODULE_NAME, method: 'handleUpdateUserMobileToken',

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -443,6 +443,7 @@ export enum ServerRoute {
REST_TRANSACTIONS = 'transactions',
REST_USERS = 'users',
+ REST_USER = 'users/:id',
REST_PING = 'ping',

Added getUser endpoint + doc