Skip to content
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

Entries and treatments clean db admin tools #4090

Closed
Closed
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
759dd40
Add clean treatments admin tool.
Nov 21, 2018
cd459fa
Fix clean treatments status html id name
Nov 21, 2018
b429eef
Return status to treatments delete by query
Nov 21, 2018
9123de4
Add clean entries db admin tool
Nov 21, 2018
15cbfea
Correct delete query fields for entries db
Nov 21, 2018
ff04394
Make devicestatus delete consistent with entries
Nov 21, 2018
769b66a
cleanup devicestatus delete
Nov 21, 2018
44baf2e
Add isId to api/devicestatus
Nov 21, 2018
c6e2056
Set query options correctly for devicestatus
Nov 21, 2018
098f372
Use dateString for devicestatus date field
Nov 21, 2018
4f10e03
Fix devicestatus default date field
Nov 21, 2018
71efc5e
Fix devicestatus delete query handling
Nov 21, 2018
41d9d8a
No 'model' concept for devicestatus
Nov 21, 2018
d1b5c56
initialize query find by id correctly for devicestatus delete
Nov 21, 2018
af3e01a
Match devicestatus api indention
Nov 21, 2018
69b73df
Make treatments delete match devicestatus
Nov 21, 2018
ada17c8
Remove old treatments id api path
Nov 21, 2018
50952de
Add entries support for delete query
Nov 21, 2018
b448906
Remove unused function.
Nov 22, 2018
7a01c40
Removed unused function.
Nov 22, 2018
1734ec1
Add API updates for new delete options.
Dec 2, 2018
440807e
Reload data when entries or treatments are deleted
Dec 7, 2018
9b59845
Add new strings to language.js
Dec 10, 2018
8136633
Prevent deleting entries or treatments more recent than 2 days ago
Dec 10, 2018
d9527d3
Add unit test for removing old devicestatus records
Dec 10, 2018
a34167a
Fix codacy finding
Dec 10, 2018
83bd1a7
Add unit test for cleantreatmentsdb.js
Dec 10, 2018
d3368e5
Add unit test for cleanentriesdb.js
Dec 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make treatments delete match devicestatus
  • Loading branch information
Jeremy Cunningham committed Dec 7, 2018
commit 69b73dfc5e3fe8e9e6dcf06c7421751db2c202a8
48 changes: 38 additions & 10 deletions lib/api/treatments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,52 @@ function configure(app, wares, ctx) {
});
});

// delete record that match query
api.delete('/treatments/', ctx.authorization.isPermitted('api:treatments:delete'), function(req, res) {
/**
* @function delete_records
* Delete treatments. The query logic works the same way as find/list. This
* endpoint uses same search logic to remove records from the database.
*/
function delete_records(req, res, next) {
var query = req.query;
if (!query.count) {
query.count = 10
}

console.log('Delete treatments records with query: ', query);
console.log('Delete records with query: ', query);

// remove using the query
ctx.treatments.remove(query, function(err, stat) {
if (err) {
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
console.log('Error saving treatment');
console.log(err);
} else {
res.json(stat);
console.log('treatments records deleted');
console.log('treatments delete error: ', err);
return next(err);
}
// yield some information about success of operation
res.json(stat);

console.log('treatments records deleted');

return next();
});
});
}

api.delete('/treatments/:id', ctx.authorization.isPermitted('api:treatments:delete'), function(req, res, next) {
if (!req.query.find) {
req.query.find = {
_id: req.params.id
};
} else {
req.query.find._id = req.params.id;
}

if (req.query.find._id === '*') {
// match any record id
delete req.query.find._id;
}
next();
}, delete_records);

// delete record that match query
api.delete('/treatments/', ctx.authorization.isPermitted('api:treatments:delete'), delete_records);

// update record
api.put('/treatments/', ctx.authorization.isPermitted('api:treatments:update'), function(req, res) {
Expand Down