-
Notifications
You must be signed in to change notification settings - Fork 438
Conversion Deletions Involving Suffix Units #1470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
ae0d360
ee25eb4
db0d3ea
f4adba2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ const { getConnection } = require('../db'); | |
| const Conversion = require('../models/Conversion'); | ||
| const { success, failure } = require('./response'); | ||
| const validate = require('jsonschema').validate; | ||
| const Unit = require('../models/Unit'); | ||
| const { removeAdditionalConversionsAndUnits } = require('../services/graph/handleSuffixUnits'); | ||
|
|
||
| const router = express.Router(); | ||
|
|
||
|
|
@@ -175,6 +177,18 @@ router.post('/delete', async (req, res) => { | |
| } else { | ||
| const conn = getConnection(); | ||
| try { | ||
| // Get the source and destination units for the conversion | ||
| const source = await Unit.getById(req.body.sourceId, conn); | ||
| const dest = await Unit.getById(req.body.destinationId, conn); | ||
| // Check if the source or the destination is a suffix unit | ||
| if (source.typeOfUnit === 'suffix') { | ||
| log.info('Suffix unit is used in conversion deletion as source.'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think both these messages would be clearer in the logs if the actual conversion information was given. For example, stating the source and destination of the conversion, maybe with the the arrow that is common in other displays of a conversion. |
||
| await removeAdditionalConversionsAndUnits(source, conn); | ||
| } | ||
| if (dest.typeOfUnit === 'suffix') { | ||
| log.info('Suffix unit is used in conversion deletion as destination.'); | ||
| await removeAdditionalConversionsAndUnits(dest, conn); | ||
| } | ||
| // Don't worry about checking if the conversion already exists | ||
| // Just try to delete it to save the extra database call, since the database will return an error anyway if the row does not exist | ||
| await Conversion.delete(req.body.sourceId, req.body.destinationId, conn); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -243,6 +243,11 @@ router.post('/delete', async (req, res) => { | |
| } else { | ||
| const conn = getConnection(); | ||
| try { | ||
| const unit = await Unit.getById(req.body.id, conn); | ||
| if (unit.typeOfUnit === 'suffix') { | ||
| log.info('Deleting a suffix unit. Now deleting associated units and conversions.'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same idea so put in the name of the unit that is being deleted. |
||
| await removeAdditionalConversionsAndUnits(unit, conn); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I cannot easily put a comment in removeAdditionalConversionsAndUnit so I'm putting the comment here. I think it would be a good idea to log each items removed in that function. Thus, the ones in the route are in overview log msg and the ones in the function log as each is removed. |
||
| } | ||
| // Don't worry about checking if the unit already exists | ||
| // Just try to delete it to save the extra database call, since the database will return an error anyway if the row does not exist | ||
| await Unit.delete(req.body.id, conn); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the text have units/conversions switched for the two fr keys?