Skip to content

Commit

Permalink
fix(inventory): allow deletion from inventory
Browse files Browse the repository at this point in the history
This commit removes the foreign key constraints from the inventory_log
to allow deletion from the inventory.  It also fixes the http headers
sent twice error in the error handler.

Closes #4147.
  • Loading branch information
jniles committed Feb 3, 2020
1 parent de2e791 commit 789e1b6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
19 changes: 11 additions & 8 deletions server/controllers/inventory/index.js
Expand Up @@ -208,15 +208,18 @@ function getInventoryItemsById(req, res, next) {


/**
* DELETE /inventory/:uuid
* delete an inventory group
* DELETE /inventory/metadata/:uuid
*
* @description
* Delete an inventory item from the database
*/
function deleteInventory(req, res, next) {

core.remove(req.params.uuid)
.then(res.sendStatus(204))
.catch(error => core.errorHandler(error, req, res, next))
.done();
async function deleteInventory(req, res, next) {
try {
await core.remove(req.params.uuid);
res.sendStatus(204);
} catch (err) {
core.errorHandler(err, req, res, next);
}
}

// ======================= inventory group =============================
Expand Down
7 changes: 3 additions & 4 deletions server/controllers/inventory/inventory/core.js
Expand Up @@ -227,11 +227,10 @@ function getItemsMetadata(params) {
}


// This function helps to delete an invetory

// This function helps to delete an inventory
function remove(_uuid) {
const sql = `DELETE FROM inventory WHERE uuid = HUID(?)`;
return db.exec(sql, _uuid);
const sql = `DELETE FROM inventory WHERE uuid = ?`;
return db.exec(sql, db.bid(_uuid));
}

/**
Expand Down
3 changes: 3 additions & 0 deletions server/models/migrations/next/migrate.sql
Expand Up @@ -2,3 +2,6 @@ DROP TABLE department;

DELETE FROM role_unit WHERE unit_id = 215;
DELETE FROM unit WHERE id = 215;

ALTER TABLE inventory_log DROP FOREIGN KEY `inventory_log_ibfk_1`;

1 change: 0 additions & 1 deletion server/models/schema.sql
Expand Up @@ -2345,7 +2345,6 @@ CREATE TABLE `inventory_log` (
PRIMARY KEY (`uuid`),
KEY `inventory_uuid` (`inventory_uuid`),
KEY `user_id` (`user_id`),
FOREIGN KEY (`inventory_uuid`) REFERENCES `inventory` (`uuid`),
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 DEFAULT COLLATE = utf8mb4_unicode_ci;

Expand Down

0 comments on commit 789e1b6

Please sign in to comment.