Skip to content
This repository has been archived by the owner on Sep 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #23 from UTSCCSCC01/CON-66
Browse files Browse the repository at this point in the history
Fix /api/devices/getAllDevices
  • Loading branch information
UnsAbbasi2022 authored Aug 7, 2022
2 parents 2de0e96 + fe9ddfe commit 6eb57f5
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions Orchestra/backend/user-device/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,15 @@ app.post('/api/devices/addDevice', (req, res) => {
//Migrate to post?
//Technically we building a resource.
app.get('/api/devices/getAllDevices', (req, res) => {

/*
Add error checking, ie is userID not blank/defined.
*/

Device.find({ userId: req.query.userId })
.populate("name")
.sort({ created: -1, name: 1 })
.exec((error, devicesData) => {
if (error) return res.status(400).send(error);
return res.status(200).json({ success: true, devicesData });
});
const req_userId = (req.body.userId).trim();
let query = {userId: req_userId};
let selection = {_id: 0, deviceId: 1, name: 1}
Device.find(query)
.select(selection)
.exec((error, deviceData) => {
if (error) return res.status(400).send(error);
return res.status(200).json({ success: true, deviceData });
});
});

// Gets one device from the DB
Expand Down

0 comments on commit 6eb57f5

Please sign in to comment.