space: fix space object updating and fix background update response

This commit is contained in:
mntmn
2020-09-22 15:39:50 +02:00
parent 81a45bb0bd
commit 137d17269a

View File

@@ -290,8 +290,12 @@ router.put('/:id', function(req, res) {
db.Space.update(newAttr, {where: { db.Space.update(newAttr, {where: {
"_id": space._id "_id": space._id
}}).then(space => { }}).then(rows => {
res.distributeUpdate("Space", space); db.Space.findOne({ where: {
"_id": space._id
}}).then(space => {
res.distributeUpdate("Space", space);
});
}); });
}); });
@@ -310,7 +314,7 @@ router.post('/:id/background', function(req, res, next) {
if (space.background_uri) { if (space.background_uri) {
var oldPath = url.parse(req.space.background_uri).pathname; var oldPath = url.parse(req.space.background_uri).pathname;
uploader.removeFile(oldPath, function(err) { uploader.removeFile(oldPath, function(err) {
console.error("removed old bg error:", err); console.error("remove old background error:", err);
}); });
} }
@@ -318,13 +322,18 @@ router.post('/:id/background', function(req, res, next) {
background_uri: backgroundUrl background_uri: backgroundUrl
}, { }, {
where: { "_id": space._id } where: { "_id": space._id }
}, function(rows) { }).then(rows => {
fs.unlink(localFilePath, function(err) { fs.unlink(localFilePath, function(err) {
if (err) { if (err) {
console.error(err); console.error(err);
res.status(400).json(err); res.status(400).json(err);
} else { } else {
res.status(200).json(space); db.Space.findOne({ where: {
"_id": space._id
}}).then(space => {
console.log("========== space update:", space);
res.distributeUpdate("Space", space);
});
} }
}); });
}); });