Added new setup endpoint

This commit is contained in:
Wyatt Johnson
2017-02-07 10:02:23 -07:00
parent f47638ae07
commit cdc81c4fc5
4 changed files with 53 additions and 27 deletions
+33
View File
@@ -9,6 +9,39 @@ const errors = require('../errors');
*/
module.exports = class SetupService {
/**
* This returns a promise which resolves if the setup is available.
*/
static isAvailable() {
// Check if we have an install lock present.
if (process.env.TALK_INSTALL_LOCK === 'TRUE') {
return Promise.reject(errors.ErrInstallLock);
}
// Get the current settings, we are expecing an error here.
return SettingsService
.retrieve()
.then(() => {
// We should NOT have gotten a settings object, this means that the
// application is already setup. Error out here.
return Promise.reject(errors.ErrSettingsInit);
})
.catch((err) => {
// If the error is `not init`, then we're good, otherwise, it's something
// else.
if (err !== errors.ErrSettingsNotInit) {
return Promise.reject(err);
}
// Allow the request to keep going here.
return;
});
}
/**
* This verifies that the current input for the setup is valid.
*/