404 when updating tags of non-existing devices
This commit is contained in:
1 parent
a0ad6ec3f1
commit
ea956fbc9c
1 file changed
+16
-2
+16
-2
@@ -226,17 +226,31 @@ async function handler(
|
||||
const deviceId = decodeURIComponent(r[1]);
|
||||
const tag = decodeURIComponent(r[2]);
|
||||
if (request.method === "POST") {
|
||||
await collections.devices.updateOne(
|
||||
const updateRes = await collections.devices.updateOne(
|
||||
{ _id: deviceId },
|
||||
{ $addToSet: { _tags: tag } }
|
||||
);
|
||||
|
||||
if (!updateRes.matchedCount) {
|
||||
response.writeHead(404);
|
||||
response.end("No such device");
|
||||
return;
|
||||
}
|
||||
|
||||
response.writeHead(200);
|
||||
response.end();
|
||||
} else if (request.method === "DELETE") {
|
||||
await collections.devices.updateOne(
|
||||
const updateRes = await collections.devices.updateOne(
|
||||
{ _id: deviceId },
|
||||
{ $pull: { _tags: tag } }
|
||||
);
|
||||
|
||||
if (!updateRes.matchedCount) {
|
||||
response.writeHead(404);
|
||||
response.end("No such device");
|
||||
return;
|
||||
}
|
||||
|
||||
response.writeHead(200);
|
||||
response.end();
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user