Add settings/appstore routes

This commit is contained in:
Johannes Zellner
2016-07-26 14:42:40 +02:00
parent 7361acbec5
commit 41e1afaf68
2 changed files with 32 additions and 0 deletions

View File

@@ -19,6 +19,9 @@ exports = module.exports = {
getTimeZone: getTimeZone,
setTimeZone: setTimeZone,
getAppstore: getAppstore,
setAppstore: setAppstore,
setCertificate: setCertificate,
setAdminCertificate: setAdminCertificate
};
@@ -162,6 +165,33 @@ function setBackupConfig(req, res, next) {
});
}
function getAppstore(req, res, next) {
settings.getAppstore(function (error, result) {
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, result));
});
}
function setAppstore(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (typeof req.body.userId !== 'string') return next(new HttpError(400, 'userId is required'));
if (typeof req.body.token !== 'string') return next(new HttpError(400, 'token is required'));
var options = {
userId: req.body.userId,
token: req.body.token
};
settings.setAppstore(options, function (error) {
if (error && error.reason === SettingsError.BAD_FIELD) return next(new HttpError(400, error.message));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200));
});
}
// default fallback cert
function setCertificate(req, res, next) {
assert.strictEqual(typeof req.body, 'object');