Use Prettier JS (#5017)

* Adds prettier

* Run lint before tests
This commit is contained in:
Florent Vilmart
2018-09-01 13:58:06 -04:00
committed by GitHub
parent 189cd259ee
commit d83a0b6808
240 changed files with 41098 additions and 29020 deletions

View File

@@ -1,14 +1,18 @@
import { Parse } from 'parse/node';
import PromiseRouter from '../PromiseRouter';
import * as middleware from "../middlewares";
import { Parse } from 'parse/node';
import PromiseRouter from '../PromiseRouter';
import * as middleware from '../middlewares';
export class HooksRouter extends PromiseRouter {
createHook(aHook, config) {
return config.hooksController.createHook(aHook).then((hook) => ({response: hook}));
return config.hooksController
.createHook(aHook)
.then(hook => ({ response: hook }));
}
updateHook(aHook, config) {
return config.hooksController.updateHook(aHook).then((hook) => ({response: hook}));
return config.hooksController
.updateHook(aHook)
.then(hook => ({ response: hook }));
}
handlePost(req) {
@@ -18,67 +22,84 @@ export class HooksRouter extends PromiseRouter {
handleGetFunctions(req) {
var hooksController = req.config.hooksController;
if (req.params.functionName) {
return hooksController.getFunction(req.params.functionName).then((foundFunction) => {
if (!foundFunction) {
throw new Parse.Error(143, `no function named: ${req.params.functionName} is defined`);
}
return Promise.resolve({response: foundFunction});
});
return hooksController
.getFunction(req.params.functionName)
.then(foundFunction => {
if (!foundFunction) {
throw new Parse.Error(
143,
`no function named: ${req.params.functionName} is defined`
);
}
return Promise.resolve({ response: foundFunction });
});
}
return hooksController.getFunctions().then((functions) => {
return { response: functions || [] };
}, (err) => {
throw err;
});
return hooksController.getFunctions().then(
functions => {
return { response: functions || [] };
},
err => {
throw err;
}
);
}
handleGetTriggers(req) {
var hooksController = req.config.hooksController;
if (req.params.className && req.params.triggerName) {
return hooksController.getTrigger(req.params.className, req.params.triggerName).then((foundTrigger) => {
if (!foundTrigger) {
throw new Parse.Error(143,`class ${req.params.className} does not exist`);
}
return Promise.resolve({response: foundTrigger});
});
return hooksController
.getTrigger(req.params.className, req.params.triggerName)
.then(foundTrigger => {
if (!foundTrigger) {
throw new Parse.Error(
143,
`class ${req.params.className} does not exist`
);
}
return Promise.resolve({ response: foundTrigger });
});
}
return hooksController.getTriggers().then((triggers) => ({ response: triggers || [] }));
return hooksController
.getTriggers()
.then(triggers => ({ response: triggers || [] }));
}
handleDelete(req) {
var hooksController = req.config.hooksController;
if (req.params.functionName) {
return hooksController.deleteFunction(req.params.functionName).then(() => ({response: {}}))
return hooksController
.deleteFunction(req.params.functionName)
.then(() => ({ response: {} }));
} else if (req.params.className && req.params.triggerName) {
return hooksController.deleteTrigger(req.params.className, req.params.triggerName).then(() => ({response: {}}))
return hooksController
.deleteTrigger(req.params.className, req.params.triggerName)
.then(() => ({ response: {} }));
}
return Promise.resolve({response: {}});
return Promise.resolve({ response: {} });
}
handleUpdate(req) {
var hook;
if (req.params.functionName && req.body.url) {
hook = {}
hook = {};
hook.functionName = req.params.functionName;
hook.url = req.body.url;
} else if (req.params.className && req.params.triggerName && req.body.url) {
hook = {}
hook = {};
hook.className = req.params.className;
hook.triggerName = req.params.triggerName;
hook.url = req.body.url
hook.url = req.body.url;
} else {
throw new Parse.Error(143, "invalid hook declaration");
throw new Parse.Error(143, 'invalid hook declaration');
}
return this.updateHook(hook, req.config);
}
handlePut(req) {
var body = req.body;
if (body.__op == "Delete") {
if (body.__op == 'Delete') {
return this.handleDelete(req);
} else {
return this.handleUpdate(req);
@@ -86,14 +107,54 @@ export class HooksRouter extends PromiseRouter {
}
mountRoutes() {
this.route('GET', '/hooks/functions', middleware.promiseEnforceMasterKeyAccess, this.handleGetFunctions.bind(this));
this.route('GET', '/hooks/triggers', middleware.promiseEnforceMasterKeyAccess, this.handleGetTriggers.bind(this));
this.route('GET', '/hooks/functions/:functionName', middleware.promiseEnforceMasterKeyAccess, this.handleGetFunctions.bind(this));
this.route('GET', '/hooks/triggers/:className/:triggerName', middleware.promiseEnforceMasterKeyAccess, this.handleGetTriggers.bind(this));
this.route('POST', '/hooks/functions', middleware.promiseEnforceMasterKeyAccess, this.handlePost.bind(this));
this.route('POST', '/hooks/triggers', middleware.promiseEnforceMasterKeyAccess, this.handlePost.bind(this));
this.route('PUT', '/hooks/functions/:functionName', middleware.promiseEnforceMasterKeyAccess, this.handlePut.bind(this));
this.route('PUT', '/hooks/triggers/:className/:triggerName', middleware.promiseEnforceMasterKeyAccess, this.handlePut.bind(this));
this.route(
'GET',
'/hooks/functions',
middleware.promiseEnforceMasterKeyAccess,
this.handleGetFunctions.bind(this)
);
this.route(
'GET',
'/hooks/triggers',
middleware.promiseEnforceMasterKeyAccess,
this.handleGetTriggers.bind(this)
);
this.route(
'GET',
'/hooks/functions/:functionName',
middleware.promiseEnforceMasterKeyAccess,
this.handleGetFunctions.bind(this)
);
this.route(
'GET',
'/hooks/triggers/:className/:triggerName',
middleware.promiseEnforceMasterKeyAccess,
this.handleGetTriggers.bind(this)
);
this.route(
'POST',
'/hooks/functions',
middleware.promiseEnforceMasterKeyAccess,
this.handlePost.bind(this)
);
this.route(
'POST',
'/hooks/triggers',
middleware.promiseEnforceMasterKeyAccess,
this.handlePost.bind(this)
);
this.route(
'PUT',
'/hooks/functions/:functionName',
middleware.promiseEnforceMasterKeyAccess,
this.handlePut.bind(this)
);
this.route(
'PUT',
'/hooks/triggers/:className/:triggerName',
middleware.promiseEnforceMasterKeyAccess,
this.handlePut.bind(this)
);
}
}