Aligned storage schemas handling
RENAME
src/assets/schemas/authorization/authorization-role.json
src/assets/storage/schemas/authorization/authorization-role-save.json
{
- "$id": "authorization-role",
+ "$id": "authorization-role-save",
"type": "object",
"properties": {
"$extend": {

RENAME
src/assets/schemas/car/car-catalog.json
src/assets/storage/schemas/car/car-catalog-save.json
{
- "$id": "car-catalog",
+ "$id": "car-catalog-save",
"title": "Validate the Car Catalog",
"type": "object",
"properties": {

RENAME
src/assets/schemas/configuration/configuration.json
src/assets/storage/schemas/configuration/configuration-save.json
{
- "$id": "config",
+ "$id": "configuration-save",
"title": "e-Mobility Configuration",
"type": "object",
"properties": {

MODIFY
src/authorization/AuthorizationsManager.ts
src/authorization/AuthorizationsManager.ts
@@ -19,7 +19,7 @@ export default class AuthorizationsManager {
const role = AUTHORIZATION_DEFINITION[roleName];
try {
// Validate the role
- AUTHORIZATION_DEFINITION[roleName] = AuthorizationValidatorStorage.getInstance().validateAuthorizationDefinitionRole(role);
+ AUTHORIZATION_DEFINITION[roleName] = AuthorizationValidatorStorage.getInstance().validateAuthorizationDefinitionRoleSave(role);
} catch (error) {
Logging.logConsoleError(error.stack);
throw new BackendError({

MODIFY
src/storage/mongodb/CarStorage.ts
src/storage/mongodb/CarStorage.ts
@@ -134,27 +134,21 @@ export default class CarStorage {
};
}
- public static async saveCarCatalog(carToSave: CarCatalog): Promise<number> {
+ public static async saveCarCatalog(carCatalogToSave: CarCatalog): Promise<number> {
const startTime = Logging.traceDatabaseRequestStart();
// Validate
- const carCatalog = CarValidatorStorage.getInstance().validateCarCatalog(carToSave);
- // Properties to save
- const carMDB: any = {
- _id: carToSave.id,
- ...carCatalog,
- };
- // Remove ID
- delete carMDB.id;
+ const carCatalogMDB = CarValidatorStorage.getInstance().validateCarCatalogSave(carCatalogToSave);
+ DatabaseUtils.switchIDToMongoDBID(carCatalogMDB);
// Add Last Changed/Created props
- DatabaseUtils.addLastChangedCreatedProps(carMDB, carToSave);
+ DatabaseUtils.addLastChangedCreatedProps(carCatalogMDB, carCatalogToSave);
// Modify and return the modified document
await global.database.getCollection<any>(Constants.DEFAULT_TENANT_ID, 'carcatalogs').findOneAndReplace(
- { _id: Utils.convertToInt(carToSave.id) },
- carMDB,
+ { _id: carCatalogMDB['_id'] },
+ carCatalogMDB,
{ upsert: true }
);
- await Logging.traceDatabaseRequestEnd(Constants.DEFAULT_TENANT_OBJECT, MODULE_NAME, 'saveCarCatalog', startTime, carMDB);
- return carToSave.id;
+ await Logging.traceDatabaseRequestEnd(Constants.DEFAULT_TENANT_OBJECT, MODULE_NAME, 'saveCarCatalog', startTime, carCatalogMDB);
+ return carCatalogMDB['_id'];
}
public static async saveCarCatalogImage(id: number, carImageToSave: string): Promise<void> {

MODIFY
src/storage/mongodb/PerformanceStorage.ts
src/storage/mongodb/PerformanceStorage.ts
@@ -26,14 +26,13 @@ export default class PerformanceStorage {
public static async updatePerformanceRecord(performanceRecord: PerformanceRecord): Promise<void> {
// // Validate
- // performanceRecord = PerformanceValidatorStorage.getInstance().validatePerformance(performanceRecord);
+ // const performanceRecordMDB = PerformanceValidatorStorage.getInstance().validatePerformance(performanceRecord);
// // Convert to ObjectID
- // performanceRecord['_id'] = DatabaseUtils.convertToObjectID(performanceRecord.id);
- // delete performanceRecord.id;
+ // DatabaseUtils.switchIDToMongoDBID(performanceRecordMDB);
// // Update
// await global.database.getCollection(Constants.DEFAULT_TENANT, 'performances').findOneAndUpdate(
- // { _id: performanceRecord['_id'] },
- // { $set: performanceRecord },
+ // { _id: performanceRecordMDB['_id'] },
+ // { $set: performanceRecordMDB },
// { upsert: true, returnDocument: 'after' }
// );
}

MODIFY
src/storage/validator/AuthorizationValidatorStorage.ts
src/storage/validator/AuthorizationValidatorStorage.ts
@@ -6,7 +6,7 @@ import global from '../../types/GlobalType';
export default class AuthorizationValidatorStorage extends SchemaValidator {
private static instance: AuthorizationValidatorStorage | null = null;
- private authorizationRole: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/schemas/authorization/authorization-role.json`, 'utf8'));
+ private authorizationRoleSave: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/storage/schemas/authorization/authorization-role-save.json`, 'utf8'));
private constructor() {
super('AuthorizationValidatorStorage', {
@@ -26,7 +26,7 @@ export default class AuthorizationValidatorStorage extends SchemaValidator {
return AuthorizationValidatorStorage.instance;
}
- public validateAuthorizationDefinitionRole(data: any): AuthorizationDefinitionRole {
- return this.validate(this.authorizationRole, data);
+ public validateAuthorizationDefinitionRoleSave(data: any): AuthorizationDefinitionRole {
+ return this.validate(this.authorizationRoleSave, data, true);
}
}

MODIFY
src/storage/validator/CarValidatorStorage.ts
src/storage/validator/CarValidatorStorage.ts
@@ -6,7 +6,7 @@ import global from '../../types/GlobalType';
export default class CarValidatorStorage extends SchemaValidator {
private static instance: CarValidatorStorage | null = null;
- private carCatalog: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/schemas/car/car-catalog.json`, 'utf8'));
+ private carCatalogSave: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/storage/schemas/car/car-catalog-save.json`, 'utf8'));
private constructor() {
super('CarValidatorStorage', {
@@ -26,7 +26,7 @@ export default class CarValidatorStorage extends SchemaValidator {
return CarValidatorStorage.instance;
}
- public validateCarCatalog(data: any): ChargingStationTemplate {
- return this.validate(this.carCatalog, data);
+ public validateCarCatalogSave(data: any): ChargingStationTemplate {
+ return this.validate(this.carCatalogSave, data, true);
}
}

MODIFY
src/storage/validator/ConfigurationValidatorStorage.ts
src/storage/validator/ConfigurationValidatorStorage.ts
@@ -6,7 +6,7 @@ import global from '../../types/GlobalType';
export default class ConfigurationValidatorStorage extends SchemaValidator {
private static instance: ConfigurationValidatorStorage | null = null;
- private configuration: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/schemas/configuration/configuration.json`, 'utf8'));
+ private configurationSave: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/storage/schemas/configuration/configuration-save.json`, 'utf8'));
private constructor() {
super('ConfigurationValidatorStorage', {
@@ -26,7 +26,7 @@ export default class ConfigurationValidatorStorage extends SchemaValidator {
return ConfigurationValidatorStorage.instance;
}
- public validateConfiguration(data: any): Configuration {
- return this.validate(this.configuration, data);
+ public validateConfigurationSave(data: any): Configuration {
+ return this.validate(this.configurationSave, data);
}
}

MODIFY
src/utils/Configuration.ts
src/utils/Configuration.ts
@@ -295,7 +295,7 @@ export default class Configuration {
fs.readFileSync(`${global.appRoot}/assets/config.json`, 'utf8')) as ConfigurationData;
}
// Validate
- Configuration.config = ConfigurationValidatorStorage.getInstance().validateConfiguration(configuration);
+ Configuration.config = ConfigurationValidatorStorage.getInstance().validateConfigurationSave(configuration);
}
return Configuration.config;
}

Aligned storage schemas handling