Added createUser 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/responses/500BackendError"
},
"510": {
- "description": "Email already used"
+ "$ref": "#/components/responses/EmailAlreadyUsed"
},
"520": {
"description": "End-user License Agreement has not been accepted"
"$ref": "#/components/responses/500BackendError"
}
}
+ },
+ "post": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Create a User",
+ "tags": [
+ "Users"
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/User"
+ }
+ }
+ }
+ },
+ "responses": {
+ "201": {
+ "description": "Retrieved user",
+ "content": {
+ "application/json": {
+ "example": {
+ "id": "###",
+ "status": "Success"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/500BackendError"
+ },
+ "510": {
+ "$ref": "#/components/responses/EmailAlreadyUsed"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
+ }
}
},
"/api/users/{id}": {
"500BackendError": {
"description": "Unexpected Backend error, checks the Logs"
},
+ "EmailAlreadyUsed": {
+ "description": "Email already used"
+ },
"NoBadgeError": {
"description": "User doesn't have any badge"
},
"chargingRateUnit",
"chargingSchedulePeriod"
]
+ },
+ "User": {
+ "type": "object",
+ "required": [""],
+ "properties": {
+ "costCenter": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string",
+ "example": "Demo"
+ },
+ "firstName": {
+ "type": "string",
+ "example": "User"
+ },
+ "iNumber": {
+ "type": "string",
+ "example": "1234567"
+ },
+ "image": {
+ "type": "string"
+ },
+ "mobile": {
+ "type": "string",
+ "example": "0000000000"
+ },
+ "locale": {
+ "type": "string"
+ },
+ "address": {
+ "$ref": "#/components/schemas/Address"
+ },
+ "passwords": {
+ "type": "object",
+ "properties": {
+ "password": {
+ "type": "string",
+ "example": "DeM*Us$r1"
+ }
+ }
+ },
+ "phone": {
+ "type": "string",
+ "example": "0000000000"
+ },
+ "email": {
+ "type": "string",
+ "example": "user.demo2@sap.com"
+ },
+ "issuer": {
+ "type": "boolean"
+ },
+ "notifcationsActive": {
+ "type": "boolean"
+ },
+ "status": {
+ "type": "string",
+ "enum": ["P", "A", "I", "B", "L"]
+ },
+ "plateID": {
+ "type": "string",
+ "example": "DEMO"
+ },
+ "role": {
+ "type": "string",
+ "enum": ["S", "A", "B", "D"],
+ "example": "B"
+ },
+ "notifications": {
+ "$ref": "#/components/schemas/Notifications"
+ }
+ }
+ },
+ "Notifications": {
+ "type": "object",
+ "properties": {
+ "sendSessionStarted": {
+ "type": "boolean"
+ },
+ "sendOptimalChargeReached": {
+ "type": "boolean"
+ },
+ "sendEndOfCharge": {
+ "type": "boolean"
+ },
+ "sendEndOfSession": {
+ "type": "boolean"
+ },
+ "sendUserAccountStatusChanged": {
+ "type": "boolean"
+ },
+ "sendSessionNotStarted": {
+ "type": "boolean"
+ },
+ "sendCarCatalogSynchronizationFailed": {
+ "type": "boolean"
+ },
+ "sendUserAccountInactivity": {
+ "type": "boolean"
+ },
+ "sendPreparingSessionNotStarted": {
+ "type": "boolean"
+ },
+ "sendBillingSynchronizationFailed": {
+ "type": "boolean"
+ },
+ "sendBillingNewInvoice": {
+ "type": "boolean"
+ },
+ "sendNewRegisteredUser": {
+ "type": "boolean"
+ },
+ "sendUnknownUserBadged": {
+ "type": "boolean"
+ },
+ "sendChargingStationStatusError": {
+ "type": "boolean"
+ },
+ "sendChargingStationRegistered": {
+ "type": "boolean"
+ },
+ "sendOcpiPatchStatusError": {
+ "type": "boolean"
+ },
+ "sendSmtpError": {
+ "type": "boolean"
+ },
+ "sendOfflineChargingStations": {
+ "type": "boolean"
+ },
+ "sendEndUserErrorNotification": {
+ "type": "boolean"
+ },
+ "sendComputeAndApplyChargingProfilesFailed": {
+ "type": "boolean"
+ },
+ "sendAccountVerificationNotification": {
+ "type": "boolean"
+ },
+ "sendAdminAccountVerificationNotification": {
+ "type": "boolean"
+ }
+ }
}
},
"parameters": {

MODIFY
src/server/rest/v1/router/api/UserRouter.ts
src/server/rest/v1/router/api/UserRouter.ts
@@ -22,6 +22,10 @@ export default class UserRouter {
this.router.get(`/${ServerRoute.REST_USERS}`, async (req: Request, res: Response, next: NextFunction) => {
await RouterUtils.handleServerAction(UserService.handleGetUsers.bind(this), ServerAction.USERS, req, res, next);
});
+
+ this.router.post(`/${ServerRoute.REST_USERS}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(UserService.handleCreateUser.bind(this), ServerAction.USER_CREATE, req, res, next);
+ });
}
protected buildRouteUser(): void {

MODIFY
src/storage/mongodb/UserStorage.ts
src/storage/mongodb/UserStorage.ts
@@ -64,11 +64,11 @@ export default class UserStorage {
await global.database.getCollection<Eula>(tenantID, 'eulas')
.insertOne(eula);
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'getEndUserLicenseAgreement', uniqueTimerID, eula);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'getEndUserLicenseAgreement', uniqueTimerID, eula);
return eula;
}
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'getEndUserLicenseAgreement', uniqueTimerID, eulaMDB);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'getEndUserLicenseAgreement', uniqueTimerID, eulaMDB);
return eulaMDB;
}
// Create default
@@ -82,7 +82,7 @@ export default class UserStorage {
// Create
await global.database.getCollection<Eula>(tenantID, 'eulas').insertOne(eula);
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'getEndUserLicenseAgreement', uniqueTimerID, eula);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'getEndUserLicenseAgreement', uniqueTimerID, eula);
// Return
return eula;
}
@@ -132,7 +132,7 @@ export default class UserStorage {
const userImageMDB = await global.database.getCollection<{ _id: ObjectID; image: string }>(tenantID, 'userimages')
.findOne({ _id: Utils.convertToObjectID(id) });
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'getUserImage', uniqueTimerID, userImageMDB);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'getUserImage', uniqueTimerID, userImageMDB);
return {
id: id, image: (userImageMDB ? userImageMDB.image : null)
};
@@ -155,7 +155,7 @@ export default class UserStorage {
}
}
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'removeSitesFromUser', uniqueTimerID, siteIDs);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'removeSitesFromUser', uniqueTimerID, siteIDs);
}
public static async addSitesToUser(tenantID: string, userID: string, siteIDs: string[]): Promise<void> {
@@ -179,7 +179,7 @@ export default class UserStorage {
await global.database.getCollection<User>(tenantID, 'siteusers').insertMany(siteUsersMDB);
}
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'addSitesToUser', uniqueTimerID, siteIDs);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'addSitesToUser', uniqueTimerID, siteIDs);
}
public static async saveUser(tenantID: string, userToSave: Partial<User>, saveImage = false): Promise<string> {
@@ -268,7 +268,7 @@ export default class UserStorage {
await UserStorage.saveUserImage(tenantID, userMDB._id.toHexString(), userToSave.image);
}
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'saveUser', uniqueTimerID, userMDB);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveUser', uniqueTimerID, userMDB);
return userMDB._id.toHexString();
}
@@ -290,7 +290,7 @@ export default class UserStorage {
{ upsert: true, returnOriginal: false }
);
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'saveImportedUser', uniqueTimerID, userMDB);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveImportedUser', uniqueTimerID, userMDB);
}
public static async saveUserPassword(tenantID: string, userID: string,
@@ -307,7 +307,7 @@ export default class UserStorage {
{ '_id': Utils.convertToObjectID(userID) },
{ $set: params });
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserPassword', uniqueTimerID);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserPassword', uniqueTimerID);
}
public static async saveUserStatus(tenantID: string, userID: string, status: UserStatus): Promise<void> {
@@ -320,7 +320,7 @@ export default class UserStorage {
{ '_id': Utils.convertToObjectID(userID) },
{ $set: { status } });
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserStatus', uniqueTimerID);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserStatus', uniqueTimerID);
}
public static async saveUserLastSelectedCarID(tenantID: string, userID: string, lastSelectedCarID: string): Promise<void> {
@@ -333,7 +333,7 @@ export default class UserStorage {
{ '_id': Utils.convertToObjectID(userID) },
{ $set: { lastSelectedCarID } });
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserStatus', uniqueTimerID);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserStatus', uniqueTimerID);
}
public static async saveUserMobileToken(tenantID: string, userID: string,
@@ -347,7 +347,7 @@ export default class UserStorage {
{ '_id': Utils.convertToObjectID(userID) },
{ $set: params });
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserMobileToken', uniqueTimerID);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserMobileToken', uniqueTimerID);
}
public static async saveUserMobilePhone(tenantID: string, userID: string,
@@ -361,7 +361,7 @@ export default class UserStorage {
{ '_id': Utils.convertToObjectID(userID) },
{ $set: params });
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserMobilePhone', uniqueTimerID);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserMobilePhone', uniqueTimerID);
}
public static async saveUserRole(tenantID: string, userID: string, role: string): Promise<void> {
@@ -374,7 +374,7 @@ export default class UserStorage {
{ '_id': Utils.convertToObjectID(userID) },
{ $set: { role } });
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserRole', uniqueTimerID);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserRole', uniqueTimerID);
}
public static async saveUserEULA(tenantID: string, userID: string,
@@ -388,7 +388,7 @@ export default class UserStorage {
{ '_id': Utils.convertToObjectID(userID) },
{ $set: params });
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserRole', uniqueTimerID, params);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserRole', uniqueTimerID, params);
}
public static async saveUserAccountVerification(tenantID: string, userID: string,
@@ -402,7 +402,7 @@ export default class UserStorage {
{ '_id': Utils.convertToObjectID(userID) },
{ $set: params });
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserAccountVerification', uniqueTimerID, params);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserAccountVerification', uniqueTimerID, params);
}
public static async saveUserAdminData(tenantID: string, userID: string,
@@ -428,7 +428,7 @@ export default class UserStorage {
{ '_id': Utils.convertToObjectID(userID) },
{ $set: updatedUserMDB });
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserAdminData', uniqueTimerID, params);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserAdminData', uniqueTimerID, params);
}
public static async saveUserBillingData(tenantID: string, userID: string, billingData: BillingUserData): Promise<void> {
@@ -450,7 +450,7 @@ export default class UserStorage {
{ '_id': Utils.convertToObjectID(userID) },
{ $set: updatedUserMDB });
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserBillingData', uniqueTimerID, billingData);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserBillingData', uniqueTimerID, billingData);
}
public static async saveUserImage(tenantID: string, userID: string, userImageToSave: string): Promise<void> {
@@ -474,7 +474,7 @@ export default class UserStorage {
{ $set: { image: userImageToSave } },
{ upsert: true, returnOriginal: false });
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserImage', uniqueTimerID, userImageToSave);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'saveUserImage', uniqueTimerID, userImageToSave);
}
public static async getUsers(tenantID: string,
@@ -626,7 +626,7 @@ export default class UserStorage {
// Check if only the total count is requested
if (dbParams.onlyRecordCount) {
// Return only the count
- Logging.traceEnd(tenantID, MODULE_NAME, 'getUsers', uniqueTimerID, usersCountMDB);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'getUsers', uniqueTimerID, usersCountMDB);
return {
count: (usersCountMDB.length > 0 ? usersCountMDB[0].count : 0),
result: []
@@ -662,7 +662,7 @@ export default class UserStorage {
})
.toArray();
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'getUsers', uniqueTimerID, usersMDB);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'getUsers', uniqueTimerID, usersMDB);
// Ok
return {
count: (usersCountMDB.length > 0 ?
@@ -721,7 +721,7 @@ export default class UserStorage {
// Check if only the total count is requested
if (dbParams.onlyRecordCount) {
// Return only the count
- Logging.traceEnd(tenantID, MODULE_NAME, 'getUsersImport', uniqueTimerID, usersImportCountMDB);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'getUsersImport', uniqueTimerID, usersImportCountMDB);
return {
count: (usersImportCountMDB.length > 0 ? usersImportCountMDB[0].count : 0),
result: []
@@ -759,7 +759,7 @@ export default class UserStorage {
})
.toArray();
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'getUsersImport', uniqueTimerID, usersImportMDB);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'getUsersImport', uniqueTimerID, usersImportMDB);
// Ok
return {
count: (usersImportCountMDB.length > 0 ?
@@ -859,7 +859,7 @@ export default class UserStorage {
})
.toArray();
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'getUsers', uniqueTimerID, usersMDB);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'getUsers', uniqueTimerID, usersMDB);
// Ok
return {
count: usersMDB.length,
@@ -885,7 +885,7 @@ export default class UserStorage {
await global.database.getCollection<any>(tenantID, 'users')
.findOneAndDelete({ '_id': Utils.convertToObjectID(id) });
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'deleteUser', uniqueTimerID, { id });
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'deleteUser', uniqueTimerID, { id });
}
public static async getUserSites(tenantID: string,
@@ -943,7 +943,7 @@ export default class UserStorage {
.toArray();
// Check if only the total count is requested
if (dbParams.onlyRecordCount) {
- Logging.traceEnd(tenantID, MODULE_NAME, 'getUserSites', uniqueTimerID, sitesCountMDB);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'getUserSites', uniqueTimerID, sitesCountMDB);
return {
count: (sitesCountMDB.length > 0 ? sitesCountMDB[0].count : 0),
result: []
@@ -979,7 +979,7 @@ export default class UserStorage {
allowDiskUse: true
}).toArray();
// Debug
- Logging.traceEnd(tenantID, MODULE_NAME, 'getUserSites', uniqueTimerID, siteUsersMDB);
+ await Logging.traceEnd(tenantID, MODULE_NAME, 'getUserSites', uniqueTimerID, siteUsersMDB);
// Ok
return {
count: (sitesCountMDB.length > 0 ?
@@ -1106,7 +1106,7 @@ export default class UserStorage {
}
);
// Debug
- Logging.traceEnd(Constants.DEFAULT_TENANT, MODULE_NAME, 'getEndUserLicenseAgreementFromFile', uniqueTimerID, eulaText);
+ await Logging.traceEnd(Constants.DEFAULT_TENANT, MODULE_NAME, 'getEndUserLicenseAgreementFromFile', uniqueTimerID, eulaText);
return eulaText;
}
}

Added createUser endpoint + doc