mirror of
https://github.com/wassname/talk.git
synced 2026-08-14 12:50:17 +08:00
replaced eslint:recommended with prettier
This commit is contained in:
+10
-16
@@ -3,28 +3,23 @@ const SettingsService = require('./settings');
|
||||
const MigrationService = require('./migration');
|
||||
const SettingsModel = require('../models/setting');
|
||||
const errors = require('../errors');
|
||||
const {
|
||||
INSTALL_LOCK
|
||||
} = require('../config');
|
||||
const { INSTALL_LOCK } = require('../config');
|
||||
|
||||
/**
|
||||
* This service is used when we want to setup the application. It is consumed by
|
||||
* the dynamic setup endpoint and by the cli-setup tool.
|
||||
*/
|
||||
module.exports = class SetupService {
|
||||
|
||||
/**
|
||||
* This returns a promise which resolves if the setup is available.
|
||||
*/
|
||||
static async isAvailable() {
|
||||
|
||||
// Check if we have an install lock present.
|
||||
if (INSTALL_LOCK) {
|
||||
throw errors.ErrInstallLock;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
// Get the current settings, we are expecing an error here.
|
||||
await SettingsService.retrieve();
|
||||
|
||||
@@ -32,7 +27,6 @@ module.exports = class SetupService {
|
||||
// application is already setup. Error out here.
|
||||
throw errors.ErrSettingsInit;
|
||||
} catch (e) {
|
||||
|
||||
// If the error is `not init`, then we're good, otherwise, it's something
|
||||
// else.
|
||||
if (e !== errors.ErrSettingsNotInit) {
|
||||
@@ -47,8 +41,7 @@ module.exports = class SetupService {
|
||||
/**
|
||||
* This verifies that the current input for the setup is valid.
|
||||
*/
|
||||
static validate({settings, user: {email, username, password}}) {
|
||||
|
||||
static validate({ settings, user: { email, username, password } }) {
|
||||
// Verify the email address of the user.
|
||||
if (!email) {
|
||||
return Promise.reject(errors.ErrMissingEmail);
|
||||
@@ -61,17 +54,19 @@ module.exports = class SetupService {
|
||||
return Promise.all([
|
||||
UsersService.isValidUsername(username, false),
|
||||
UsersService.isValidPassword(password),
|
||||
settingsModel.validate()
|
||||
settingsModel.validate(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will perform the setup.
|
||||
*/
|
||||
static async setup({settings, user: {email, password, username}}) {
|
||||
|
||||
static async setup({ settings, user: { email, password, username } }) {
|
||||
// Validate the settings first.
|
||||
await SetupService.validate({settings, user: {email, password, username}});
|
||||
await SetupService.validate({
|
||||
settings,
|
||||
user: { email, password, username },
|
||||
});
|
||||
|
||||
// Get the migrations to run.
|
||||
let migrations = await MigrationService.listPending();
|
||||
@@ -89,13 +84,12 @@ module.exports = class SetupService {
|
||||
// Grant them administrative privileges and confirm the email account.
|
||||
await Promise.all([
|
||||
UsersService.setRole(user.id, 'ADMIN'),
|
||||
UsersService.confirmEmail(user.id, email)
|
||||
UsersService.confirmEmail(user.id, email),
|
||||
]);
|
||||
|
||||
return {
|
||||
settings,
|
||||
user
|
||||
user,
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user