diff --git a/backend/src/v5/processors/teamspaces/projects/models/drawings/calibrations.js b/backend/src/v5/processors/teamspaces/projects/models/drawings/calibrations.js index 8e10f1ce4e..9fc4d9a22d 100644 --- a/backend/src/v5/processors/teamspaces/projects/models/drawings/calibrations.js +++ b/backend/src/v5/processors/teamspaces/projects/models/drawings/calibrations.js @@ -118,10 +118,12 @@ Calibrations.getCalibrationStatusForAllRevs = async (teamspace, project, drawing Calibrations.addCalibration = async (teamspace, project, drawing, revision, createdBy, calibration) => { const existingCalibration = await getCalibration(teamspace, project, drawing, revision, { _id: 1 }); - await addCalibration(teamspace, project, drawing, revision, createdBy, - deleteIfUndefined({ ...calibration, verticalRange: undefined, units: undefined })); - await updateModelSettings(teamspace, project, drawing, - { calibration: { verticalRange: calibration.verticalRange, units: calibration.units } }); + const { verticalRange, units, ...calibrationData } = calibration; + + await Promise.all([ + addCalibration(teamspace, project, drawing, revision, createdBy, { ...calibrationData, units }), + updateModelSettings(teamspace, project, drawing, { calibration: { verticalRange, units } }), + ]); if (!existingCalibration) { publish(events.REVISION_UPDATED, { diff --git a/backend/tests/v5/unit/processors/teamspaces/projects/models/drawings/calibrations.test.js b/backend/tests/v5/unit/processors/teamspaces/projects/models/drawings/calibrations.test.js index 175b598057..b628f1513b 100644 --- a/backend/tests/v5/unit/processors/teamspaces/projects/models/drawings/calibrations.test.js +++ b/backend/tests/v5/unit/processors/teamspaces/projects/models/drawings/calibrations.test.js @@ -307,12 +307,14 @@ const testAddCalibration = () => { await Calibrations.addCalibration(teamspace, project, drawing, revision, createdBy, calibration); + const { verticalRange, units, ...calibrationData } = calibration; + expect(CalibrationsModel.addCalibration).toHaveBeenCalledTimes(1); expect(CalibrationsModel.addCalibration).toHaveBeenCalledWith(teamspace, project, drawing, revision, - createdBy, deleteIfUndefined({ ...calibration, verticalRange: undefined, units: undefined })); + createdBy, { ...calibrationData, units }); expect(ModelSettingsModel.updateModelSettings).toHaveBeenCalledTimes(1); expect(ModelSettingsModel.updateModelSettings).toHaveBeenCalledWith(teamspace, project, drawing, - { calibration: { verticalRange: calibration.verticalRange, units: calibration.units } }); + { calibration: { verticalRange, units } }); expect(CalibrationsModel.getCalibration).toHaveBeenCalledTimes(1); expect(CalibrationsModel.getCalibration).toHaveBeenCalledWith(teamspace, project, drawing, revision, { _id: 1 }); @@ -324,12 +326,14 @@ const testAddCalibration = () => { await Calibrations.addCalibration(teamspace, project, drawing, revision, createdBy, calibration); + const { verticalRange, units, ...calibrationData } = calibration; + expect(CalibrationsModel.addCalibration).toHaveBeenCalledTimes(1); expect(CalibrationsModel.addCalibration).toHaveBeenCalledWith(teamspace, project, drawing, revision, - createdBy, deleteIfUndefined({ ...calibration, verticalRange: undefined, units: undefined })); + createdBy, { ...calibrationData, units }); expect(ModelSettingsModel.updateModelSettings).toHaveBeenCalledTimes(1); expect(ModelSettingsModel.updateModelSettings).toHaveBeenCalledWith(teamspace, project, drawing, - { calibration: { verticalRange: calibration.verticalRange, units: calibration.units } }); + { calibration: { verticalRange, units } }); expect(CalibrationsModel.getCalibration).toHaveBeenCalledTimes(1); expect(CalibrationsModel.getCalibration).toHaveBeenCalledWith(teamspace, project, drawing, revision, { _id: 1 });