Now takes both id and type because there is two different sets of id pools, and need to select the corrent one.

This commit is contained in:
2017-10-06 15:37:09 +02:00
parent 3c372aab92
commit 307a8352a3
2 changed files with 5 additions and 4 deletions

View File

@@ -22,7 +22,7 @@ class RequestRepository {
this.queries = { this.queries = {
'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?)", 'insertRequest': "INSERT INTO requests VALUES (?, ?, ?, ?, ?, ?, CURRENT_DATE, 'requested', ?)",
'fetchRequstedItems': "SELECT * FROM requests", 'fetchRequstedItems': "SELECT * FROM requests",
'updateRequestedById': "UPDATE requests SET status = ? WHERE id is ?", 'updateRequestedById': "UPDATE requests SET status = ? WHERE id is ? AND type is ?",
} }
} }
@@ -168,8 +168,8 @@ class RequestRepository {
return this.database.all(this.queries.fetchRequstedItems); return this.database.all(this.queries.fetchRequstedItems);
} }
updateRequestedById(id, status) { updateRequestedById(id, type, status) {
return this.database.run(this.queries.updateRequestedById, [status, id]); return this.database.run(this.queries.updateRequestedById, [status, id, type]);
} }
} }

View File

@@ -9,9 +9,10 @@ const requestRepository = new RequestRepository();
*/ */
function updateRequested(req, res) { function updateRequested(req, res) {
const id = req.params.requestId; const id = req.params.requestId;
const type = req.body.type;
const status = req.body.status; const status = req.body.status;
requestRepository.updateRequestedById(id, status) requestRepository.updateRequestedById(id, type, status)
.then(() => { .then(() => {
res.send({ success: true }); res.send({ success: true });
}) })