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