Renamed User Send Error type
MODIFY
src/server/rest/service/NotificationService.ts
src/server/rest/service/NotificationService.ts
@@ -55,14 +55,16 @@ export default class NotificationService {
}
// Filter
const filteredRequest = NotificationSecurity.filterEndUserReportErrorRequest(req.body);
+ // Check if Notification is valid
+ Utils.checkIfEndUserErrorNotificationValid(filteredRequest, req);
// Get the User
const user = await UserStorage.getUser(req.user.tenantID, req.user.id);
UtilsService.assertObjectExists(action, user, `User '${req.user.id}' does not exist`,
MODULE_NAME, 'handleEndUserReportError', req.user);
// Save mobile number
- if (filteredRequest.phone && (user.mobile !== filteredRequest.phone)) {
- user.mobile = filteredRequest.phone;
- await UserStorage.saveUserMobilePhone(req.user.tenantID, user.id, { mobile: filteredRequest.phone });
+ if (filteredRequest.mobile && (user.mobile !== filteredRequest.mobile)) {
+ user.mobile = filteredRequest.mobile;
+ await UserStorage.saveUserMobilePhone(req.user.tenantID, user.id, { mobile: filteredRequest.mobile });
}
// Set
const endUserErrorNotification: EndUserErrorNotification = {
@@ -70,12 +72,10 @@ export default class NotificationService {
email: user.email,
phone: user.mobile,
name: Utils.buildUserFullName(user, false, false),
- errorTitle: filteredRequest.errorTitle,
- errorDescription: filteredRequest.errorDescription,
+ errorTitle: filteredRequest.subject,
+ errorDescription: filteredRequest.description,
evseDashboardURL: Utils.buildEvseURL(),
};
- // Check if Notification is valid
- Utils.checkIfEndUserErrorNotificationValid(filteredRequest, req);
// Send Notification
await NotificationHandler.sendEndUserErrorNotification(req.user.tenantID, endUserErrorNotification);
// Ok

MODIFY
src/server/rest/service/security/NotificationSecurity.ts
src/server/rest/service/security/NotificationSecurity.ts
@@ -21,9 +21,9 @@ export default class NotificationSecurity {
static filterEndUserReportErrorRequest(request: any): HttpEndUserReportErrorRequest {
const filteredRequest: HttpEndUserReportErrorRequest = {
- errorTitle: sanitize(request.errorTitle),
- errorDescription: sanitize(request.errorDescription),
- phone: sanitize(request.phone),
+ subject: sanitize(request.subject),
+ description: sanitize(request.description),
+ mobile: sanitize(request.mobile),
};
return filteredRequest;
}

MODIFY
src/types/requests/HttpNotificationRequest.ts
src/types/requests/HttpNotificationRequest.ts
@@ -7,7 +7,7 @@ export interface HttpNotificationRequest extends HttpDatabaseRequest {
}
export interface HttpEndUserReportErrorRequest {
- errorTitle: string;
- errorDescription: string;
- phone: string;
+ subject: string;
+ description: string;
+ mobile: string;
}

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -426,11 +426,11 @@ export default class Utils {
public static async normalizeAndCheckSOAPParams(headers: any, req: any): Promise<void> {
// Normalize
- Utils._normalizeOneSOAPParam(headers, 'chargeBoxIdentity');
- Utils._normalizeOneSOAPParam(headers, 'Action');
- Utils._normalizeOneSOAPParam(headers, 'To');
- Utils._normalizeOneSOAPParam(headers, 'From.Address');
- Utils._normalizeOneSOAPParam(headers, 'ReplyTo.Address');
+ Utils.normalizeOneSOAPParam(headers, 'chargeBoxIdentity');
+ Utils.normalizeOneSOAPParam(headers, 'Action');
+ Utils.normalizeOneSOAPParam(headers, 'To');
+ Utils.normalizeOneSOAPParam(headers, 'From.Address');
+ Utils.normalizeOneSOAPParam(headers, 'ReplyTo.Address');
// Parse the request (lower case for fucking charging station DBT URL registration)
const urlParts = url.parse(decodeURIComponent(req.url.toLowerCase()), true);
const tenantID = urlParts.query.tenantid as string;
@@ -1769,7 +1769,7 @@ export default class Utils {
actionOnUser: filteredRequest.id
});
}
- if (req.method === 'POST' && !Utils._isUserEmailValid(filteredRequest.email)) {
+ if (req.method === 'POST' && !Utils.isUserEmailValid(filteredRequest.email)) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
@@ -1791,7 +1791,7 @@ export default class Utils {
actionOnUser: filteredRequest.id
});
}
- if (filteredRequest.phone && !Utils._isPhoneValid(filteredRequest.phone)) {
+ if (filteredRequest.phone && !Utils.isPhoneValid(filteredRequest.phone)) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
@@ -1802,7 +1802,7 @@ export default class Utils {
actionOnUser: filteredRequest.id
});
}
- if (filteredRequest.mobile && !Utils._isPhoneValid(filteredRequest.mobile)) {
+ if (filteredRequest.mobile && !Utils.isPhoneValid(filteredRequest.mobile)) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
@@ -1814,7 +1814,7 @@ export default class Utils {
});
}
if (filteredRequest.tags) {
- if (!Utils._areTagsValid(filteredRequest.tags)) {
+ if (!Utils.areTagsValid(filteredRequest.tags)) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
@@ -1826,7 +1826,7 @@ export default class Utils {
});
}
}
- if (filteredRequest.plateID && !Utils._isPlateIDValid(filteredRequest.plateID)) {
+ if (filteredRequest.plateID && !Utils.isPlateIDValid(filteredRequest.plateID)) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
@@ -2010,7 +2010,7 @@ export default class Utils {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
- message: 'Vin Car is mandatory',
+ message: 'Car Vin is mandatory',
module: MODULE_NAME, method: 'checkIfCarValid',
user: req.user.id
});
@@ -2024,7 +2024,7 @@ export default class Utils {
user: req.user.id
});
}
- if (!Utils._isPlateIDValid(car.licensePlate)) {
+ if (!Utils.isPlateIDValid(car.licensePlate)) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
@@ -2067,7 +2067,7 @@ export default class Utils {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
- message: 'Car CarConverter is mandatory',
+ message: 'Car Converter is mandatory',
module: MODULE_NAME, method: 'checkIfCarValid',
user: req.user.id
});
@@ -2076,7 +2076,7 @@ export default class Utils {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
- message: 'Car CarConverter amperage per phase is mandatory',
+ message: 'Car Converter amperage per phase is mandatory',
module: MODULE_NAME, method: 'checkIfCarValid',
user: req.user.id
});
@@ -2085,7 +2085,7 @@ export default class Utils {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
- message: 'Car CarConverter number of phases is mandatory',
+ message: 'Car Converter number of phases is mandatory',
module: MODULE_NAME, method: 'checkIfCarValid',
user: req.user.id
});
@@ -2094,7 +2094,7 @@ export default class Utils {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
- message: 'Car CarConverter power is mandatory',
+ message: 'Car Converter power is mandatory',
module: MODULE_NAME, method: 'checkIfCarValid',
user: req.user.id
});
@@ -2103,7 +2103,7 @@ export default class Utils {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
- message: 'Car CarConverter type is mandatory',
+ message: 'Car Converter type is mandatory',
module: MODULE_NAME, method: 'checkIfCarValid',
user: req.user.id
});
@@ -2111,16 +2111,25 @@ export default class Utils {
}
public static checkIfEndUserErrorNotificationValid(endUserErrorNotificationValid: HttpEndUserReportErrorRequest, req: Request): void {
- if (!endUserErrorNotificationValid.errorTitle || !endUserErrorNotificationValid.errorDescription) {
+ if (!endUserErrorNotificationValid.subject) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
- message: 'Error Title and Description are mandatory.',
+ message: 'Subject is mandatory.',
module: MODULE_NAME, method: 'checkIfEndUserErrorNotificationValid',
user: req.user.id
});
}
- if (!this._isPhoneValid(endUserErrorNotificationValid.phone)) {
+ if (!endUserErrorNotificationValid.description) {
+ throw new AppError({
+ source: Constants.CENTRAL_SERVER,
+ errorCode: HTTPError.GENERAL_ERROR,
+ message: 'Description is mandatory.',
+ module: MODULE_NAME, method: 'checkIfEndUserErrorNotificationValid',
+ user: req.user.id
+ });
+ }
+ if (endUserErrorNotificationValid.mobile && !this.isPhoneValid(endUserErrorNotificationValid.mobile)) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
@@ -2131,23 +2140,23 @@ export default class Utils {
}
}
- private static _isUserEmailValid(email: string): boolean {
- return validator.isEmail(email);
+ private static isPhoneValid(phone: string): boolean {
+ return /^\+?([0-9] ?){9,14}[0-9]$/.test(phone);
}
- private static _areTagsValid(tags: Tag[]): boolean {
- return tags.filter((tag) => /^[A-Za-z0-9,]*$/.test(tag.id)).length === tags.length;
+ private static isUserEmailValid(email: string): boolean {
+ return validator.isEmail(email);
}
- private static _isPhoneValid(phone: string): boolean {
- return /^\+?([0-9] ?){9,14}[0-9]$/.test(phone);
+ private static areTagsValid(tags: Tag[]): boolean {
+ return tags.filter((tag) => /^[A-Za-z0-9,]*$/.test(tag.id)).length === tags.length;
}
- private static _isPlateIDValid(plateID): boolean {
+ private static isPlateIDValid(plateID): boolean {
return /^[A-Z0-9- ]*$/.test(plateID);
}
- private static _normalizeOneSOAPParam(headers: any, name: string) {
+ private static normalizeOneSOAPParam(headers: any, name: string) {
const val = _.get(headers, name);
if (val && val.$value) {
_.set(headers, name, val.$value);

Renamed User Send Error type