mirror of
https://github.com/wassname/talk.git
synced 2026-07-07 21:18:57 +08:00
f488b0e02d
- Adjusted docs - Fixed issues with process terminating wrong
60 lines
1.3 KiB
JavaScript
60 lines
1.3 KiB
JavaScript
const express = require('express');
|
|
|
|
const errors = require('../../../errors');
|
|
|
|
const SetupService = require('../../../services/setup');
|
|
const SettingsService = require('../../../services/settings');
|
|
|
|
const router = express.Router();
|
|
|
|
router.post('/', (req, res, next) => {
|
|
|
|
// Check if we have an install lock present.
|
|
if (process.env.TALK_INSTALL_LOCK === 'TRUE') {
|
|
return next(errors.ErrInstallLock);
|
|
}
|
|
|
|
// Get the current settings, we are expecing an error here.
|
|
SettingsService
|
|
.retrieve()
|
|
.then(() => {
|
|
|
|
// We should NOT have gotten a settings object, this means that the
|
|
// application is already setup. Error out here.
|
|
return next(errors.ErrSettingsInit);
|
|
|
|
})
|
|
.catch((err) => {
|
|
|
|
// If the error is `not init`, then we're good, otherwise, it's something
|
|
// else.
|
|
if (err !== errors.ErrSettingsNotInit) {
|
|
return next(err);
|
|
}
|
|
|
|
// Allow the request to keep going here.
|
|
return next();
|
|
});
|
|
|
|
}, (req, res, next) => {
|
|
|
|
const {
|
|
settings,
|
|
user: {email, password, displayName}
|
|
} = req.body;
|
|
|
|
SetupService
|
|
.setup({settings, user: {email, password, displayName}})
|
|
.then(() => {
|
|
|
|
// We're setup!
|
|
res.status(204).end();
|
|
})
|
|
.catch((err) => {
|
|
return next(err);
|
|
});
|
|
|
|
});
|
|
|
|
module.exports = router;
|