billing - REST - saveBillingSetting
MODIFY
src/server/rest/v1/service/BillingSettingService.ts
src/server/rest/v1/service/BillingSettingService.ts
@@ -62,8 +62,8 @@ export default class BillingSettingService {
// const newSettings = SettingSecurity.filterBillingSettingUpdateRequest(req);
// TODO - sanitize it
const settingID = req.params.id;
- const newSettings = req.body;
- UtilsService.assertIdIsProvided(action, newSettings.id, MODULE_NAME, 'handleUpdateSetting', req.user);
+ const newBillingSettings = req.body;
+ UtilsService.assertIdIsProvided(action, newBillingSettings.id, MODULE_NAME, 'handleUpdateSetting', req.user);
if (!await Authorizations.canUpdateSetting(req.user)) {
throw new AppAuthError({
errorCode: HTTPAuthError.FORBIDDEN,
@@ -73,10 +73,10 @@ export default class BillingSettingService {
});
}
// Update timestamp
- newSettings.lastChangedBy = { 'id': req.user.id };
- newSettings.lastChangedOn = new Date();
+ newBillingSettings.lastChangedBy = { 'id': req.user.id };
+ newBillingSettings.lastChangedOn = new Date();
// Let's save it
- const id = await BillingSettingStorage.saveBillingSetting(req.user.tenantID, settingID, newSettings as BillingSettings, true);
+ const id = await BillingSettingStorage.saveBillingSetting(req.user.tenantID, settingID, newBillingSettings as BillingSettings, true);
if (!id) {
res.sendStatus(StatusCodes.NOT_FOUND);
} else {

MODIFY
src/storage/mongodb/BillingSettingStorage.ts
src/storage/mongodb/BillingSettingStorage.ts
@@ -69,18 +69,17 @@ export default class BillingSettingStorage {
return null;
}
- public static async saveBillingSetting(tenantID: string, settingID: string, newSettings: Partial<BillingSettings>, encryptSensitiveData = false): Promise<string> {
+ public static async saveBillingSetting(tenantID: string, settingID: string, newBillingSettings: Partial<BillingSettings>, encryptSensitiveData = false): Promise<string> {
// Load previous settings
const settings = await SettingStorage.getSettings(tenantID, { settingID }, Constants.DB_PARAMS_SINGLE_RECORD);
if (settings?.result?.[0]?.content) {
// Build internal structure
const settingsToSave = settings.result[0];
if (encryptSensitiveData) {
- // TODO - MUST BE FIRST CONVERTED to the SETTING format
- await BillingSettingStorage.processSensitiveData(tenantID, settingsToSave, newSettings);
+ await BillingSettingStorage.processSensitiveData(tenantID, settingsToSave, newBillingSettings);
}
const { isTransactionBillingActivated, usersLastSynchronizedOn } = settingsToSave.content.billing;
- const { immediateBillingAllowed, periodicBillingAllowed, taxID } = newSettings.billing;
+ const { immediateBillingAllowed, periodicBillingAllowed, taxID } = newBillingSettings.billing;
// Common Properties
settingsToSave.content.billing = {
isTransactionBillingActivated,usersLastSynchronizedOn,
@@ -88,7 +87,7 @@ export default class BillingSettingStorage {
};
// STRIPE Properties
if (settingsToSave.content.type === BillingSettingsType.STRIPE) {
- settingsToSave.content.stripe = newSettings.stripe;
+ settingsToSave.content.stripe = newBillingSettings.stripe;
}
// Save
return SettingStorage.saveSettings(tenantID, settingsToSave);

billing - REST - saveBillingSetting