mirror of
https://github.com/wassname/talk.git
synced 2026-06-28 20:41:01 +08:00
Cleaned up some routes
This commit is contained in:
@@ -102,15 +102,13 @@ router.put('/password/reset', (req, res, next) => {
|
||||
|
||||
UsersService
|
||||
.verifyPasswordResetToken(token)
|
||||
.then(user => {
|
||||
.then((user) => {
|
||||
return UsersService.changePassword(user.id, password);
|
||||
})
|
||||
.then(() => {
|
||||
res.status(204).end();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
|
||||
.catch(() => {
|
||||
next(authorization.ErrNotAuthorized);
|
||||
});
|
||||
});
|
||||
@@ -121,12 +119,8 @@ router.put('/username', authorization.needed(), (req, res, next) => {
|
||||
.then(() => {
|
||||
res.status(204).end();
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.code === 11000) {
|
||||
next(errors.ErrUsernameTaken);
|
||||
} else {
|
||||
next(error);
|
||||
}
|
||||
.catch((err) => {
|
||||
next(err);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -79,7 +79,8 @@ router.get('/:asset_id', (req, res, next) => {
|
||||
.findById(req.params.asset_id)
|
||||
.then((asset) => {
|
||||
if (!asset) {
|
||||
return res.status(404).end();
|
||||
res.status(404).end();
|
||||
return;
|
||||
}
|
||||
|
||||
res.json(asset);
|
||||
@@ -97,15 +98,17 @@ router.post('/:asset_id/scrape', (req, res, next) => {
|
||||
.findById(req.params.asset_id)
|
||||
.then((asset) => {
|
||||
if (!asset) {
|
||||
return res.status(404).end();
|
||||
res.status(404).end();
|
||||
return;
|
||||
}
|
||||
|
||||
return scraper.create(asset);
|
||||
})
|
||||
.then((job) => {
|
||||
return scraper
|
||||
.create(asset)
|
||||
.then((job) => {
|
||||
|
||||
// Send the job back for monitoring.
|
||||
res.status(201).json(job);
|
||||
// Send the job back for monitoring.
|
||||
res.status(201).json(job);
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
next(err);
|
||||
@@ -117,8 +120,12 @@ router.put('/:asset_id/settings', (req, res, next) => {
|
||||
// Override the settings for the asset.
|
||||
AssetsService
|
||||
.overrideSettings(req.params.asset_id, req.body)
|
||||
.then(() => res.status(204).end())
|
||||
.catch((err) => next(err));
|
||||
.then(() => {
|
||||
res.status(204).end();
|
||||
})
|
||||
.catch((err) => {
|
||||
next(err);
|
||||
});
|
||||
});
|
||||
|
||||
router.put('/:asset_id/status', (req, res, next) => {
|
||||
|
||||
@@ -5,7 +5,8 @@ const router = express.Router();
|
||||
|
||||
router.get('/', (req, res, next) => {
|
||||
SettingsService
|
||||
.retrieve().then((settings) => {
|
||||
.retrieve()
|
||||
.then((settings) => {
|
||||
res.json(settings);
|
||||
})
|
||||
.catch((err) => {
|
||||
|
||||
@@ -43,7 +43,7 @@ router.post('/', (req, res, next) => {
|
||||
res.status(204).end();
|
||||
})
|
||||
.catch((err) => {
|
||||
return next(err);
|
||||
next(err);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -152,7 +152,7 @@ router.post('/:user_id/actions', authorization.needed(), (req, res, next) => {
|
||||
.then((action) => {
|
||||
|
||||
// Set the user status to "pending" for review by moderators
|
||||
if (action_type.slice(0, 4) === 'FLAG') {
|
||||
if (action_type === 'FLAG') {
|
||||
return UsersService.setStatus(req.params.user_id, 'PENDING')
|
||||
.then(() => action);
|
||||
} else {
|
||||
|
||||
+14
-3
@@ -686,9 +686,20 @@ module.exports = class UsersService {
|
||||
canEditName: false,
|
||||
status: 'PENDING'
|
||||
}
|
||||
}).then((result) => {
|
||||
return result.nModified > 0 ? result :
|
||||
Promise.reject(errors.ErrPermissionUpdateUsername);
|
||||
})
|
||||
.then((result) => {
|
||||
if (result.nModified <= 0) {
|
||||
return Promise.reject(errors.ErrPermissionUpdateUsername);
|
||||
}
|
||||
|
||||
return result;
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.code === 11000) {
|
||||
throw errors.ErrUsernameTaken;
|
||||
}
|
||||
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user