@@ -72,7 +72,7 @@ export class AggregateRouter extends ClassesRouter {
|
||||
req.info.clientSDK,
|
||||
req.info.context
|
||||
)
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
for (const result of response.results) {
|
||||
if (typeof result === 'object') {
|
||||
UsersRouter.removeHiddenProperties(result);
|
||||
@@ -110,12 +110,12 @@ export class AggregateRouter extends ClassesRouter {
|
||||
static getPipeline(body) {
|
||||
let pipeline = body.pipeline || body;
|
||||
if (!Array.isArray(pipeline)) {
|
||||
pipeline = Object.keys(pipeline).map((key) => {
|
||||
pipeline = Object.keys(pipeline).map(key => {
|
||||
return { [key]: pipeline[key] };
|
||||
});
|
||||
}
|
||||
|
||||
return pipeline.map((stage) => {
|
||||
return pipeline.map(stage => {
|
||||
const keys = Object.keys(stage);
|
||||
if (keys.length != 1) {
|
||||
throw new Error(
|
||||
@@ -157,7 +157,7 @@ export class AggregateRouter extends ClassesRouter {
|
||||
'GET',
|
||||
'/aggregate/:className',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
(req) => {
|
||||
req => {
|
||||
return this.handleFind(req);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -24,8 +24,8 @@ export class AudiencesRouter extends ClassesRouter {
|
||||
req.info.clientSDK,
|
||||
req.info.context
|
||||
)
|
||||
.then((response) => {
|
||||
response.results.forEach((item) => {
|
||||
.then(response => {
|
||||
response.results.forEach(item => {
|
||||
item.query = JSON.parse(item.query);
|
||||
});
|
||||
|
||||
@@ -34,7 +34,7 @@ export class AudiencesRouter extends ClassesRouter {
|
||||
}
|
||||
|
||||
handleGet(req) {
|
||||
return super.handleGet(req).then((data) => {
|
||||
return super.handleGet(req).then(data => {
|
||||
data.response.query = JSON.parse(data.response.query);
|
||||
|
||||
return data;
|
||||
@@ -46,7 +46,7 @@ export class AudiencesRouter extends ClassesRouter {
|
||||
'GET',
|
||||
'/push_audiences',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
(req) => {
|
||||
req => {
|
||||
return this.handleFind(req);
|
||||
}
|
||||
);
|
||||
@@ -54,7 +54,7 @@ export class AudiencesRouter extends ClassesRouter {
|
||||
'GET',
|
||||
'/push_audiences/:objectId',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
(req) => {
|
||||
req => {
|
||||
return this.handleGet(req);
|
||||
}
|
||||
);
|
||||
@@ -62,7 +62,7 @@ export class AudiencesRouter extends ClassesRouter {
|
||||
'POST',
|
||||
'/push_audiences',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
(req) => {
|
||||
req => {
|
||||
return this.handleCreate(req);
|
||||
}
|
||||
);
|
||||
@@ -70,7 +70,7 @@ export class AudiencesRouter extends ClassesRouter {
|
||||
'PUT',
|
||||
'/push_audiences/:objectId',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
(req) => {
|
||||
req => {
|
||||
return this.handleUpdate(req);
|
||||
}
|
||||
);
|
||||
@@ -78,7 +78,7 @@ export class AudiencesRouter extends ClassesRouter {
|
||||
'DELETE',
|
||||
'/push_audiences/:objectId',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
(req) => {
|
||||
req => {
|
||||
return this.handleDelete(req);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -43,7 +43,7 @@ export class ClassesRouter extends PromiseRouter {
|
||||
req.info.clientSDK,
|
||||
req.info.context
|
||||
)
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
return { response: response };
|
||||
});
|
||||
}
|
||||
@@ -93,7 +93,7 @@ export class ClassesRouter extends PromiseRouter {
|
||||
options,
|
||||
req.info.clientSDK
|
||||
)
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
if (!response.results || response.results.length == 0) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
@@ -241,19 +241,19 @@ export class ClassesRouter extends PromiseRouter {
|
||||
}
|
||||
|
||||
mountRoutes() {
|
||||
this.route('GET', '/classes/:className', (req) => {
|
||||
this.route('GET', '/classes/:className', req => {
|
||||
return this.handleFind(req);
|
||||
});
|
||||
this.route('GET', '/classes/:className/:objectId', (req) => {
|
||||
this.route('GET', '/classes/:className/:objectId', req => {
|
||||
return this.handleGet(req);
|
||||
});
|
||||
this.route('POST', '/classes/:className', (req) => {
|
||||
this.route('POST', '/classes/:className', req => {
|
||||
return this.handleCreate(req);
|
||||
});
|
||||
this.route('PUT', '/classes/:className/:objectId', (req) => {
|
||||
this.route('PUT', '/classes/:className/:objectId', req => {
|
||||
return this.handleUpdate(req);
|
||||
});
|
||||
this.route('DELETE', '/classes/:className/:objectId', (req) => {
|
||||
this.route('DELETE', '/classes/:className/:objectId', req => {
|
||||
return this.handleDelete(req);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ export class CloudCodeRouter extends PromiseRouter {
|
||||
static getJobs(req) {
|
||||
return rest
|
||||
.find(req.config, req.auth, '_JobSchedule', {}, {})
|
||||
.then((scheduledJobs) => {
|
||||
.then(scheduledJobs => {
|
||||
return {
|
||||
response: scheduledJobs.results,
|
||||
};
|
||||
@@ -70,10 +70,10 @@ export class CloudCodeRouter extends PromiseRouter {
|
||||
const jobs = triggers.getJobs(config.applicationId) || {};
|
||||
return rest
|
||||
.find(req.config, req.auth, '_JobSchedule', {}, {})
|
||||
.then((scheduledJobs) => {
|
||||
.then(scheduledJobs => {
|
||||
return {
|
||||
response: {
|
||||
in_use: scheduledJobs.results.map((job) => job.jobName),
|
||||
in_use: scheduledJobs.results.map(job => job.jobName),
|
||||
jobs: Object.keys(jobs),
|
||||
},
|
||||
};
|
||||
@@ -107,7 +107,7 @@ export class CloudCodeRouter extends PromiseRouter {
|
||||
undefined,
|
||||
req.info.context
|
||||
)
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
return {
|
||||
response,
|
||||
};
|
||||
@@ -118,7 +118,7 @@ export class CloudCodeRouter extends PromiseRouter {
|
||||
const { objectId } = req.params;
|
||||
return rest
|
||||
.del(req.config, req.auth, '_JobSchedule', objectId, req.info.context)
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
return {
|
||||
response,
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ export class FeaturesRouter extends PromiseRouter {
|
||||
'GET',
|
||||
'/serverInfo',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
(req) => {
|
||||
req => {
|
||||
const { config } = req;
|
||||
const features = {
|
||||
globalConfig: {
|
||||
|
||||
@@ -8,22 +8,22 @@ import logger from '../logger';
|
||||
const triggers = require('../triggers');
|
||||
const http = require('http');
|
||||
|
||||
const downloadFileFromURI = (uri) => {
|
||||
const downloadFileFromURI = uri => {
|
||||
return new Promise((res, rej) => {
|
||||
http
|
||||
.get(uri, (response) => {
|
||||
.get(uri, response => {
|
||||
response.setDefaultEncoding('base64');
|
||||
let body = `data:${response.headers['content-type']};base64,`;
|
||||
response.on('data', (data) => (body += data));
|
||||
response.on('data', data => (body += data));
|
||||
response.on('end', () => res(body));
|
||||
})
|
||||
.on('error', (e) => {
|
||||
.on('error', e => {
|
||||
rej(`Error downloading file from ${uri}: ${e.message}`);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const addFileDataIfNeeded = async (file) => {
|
||||
const addFileDataIfNeeded = async file => {
|
||||
if (file._source.format === 'uri') {
|
||||
const base64 = await downloadFileFromURI(file._source.uri);
|
||||
file._previousSave = file;
|
||||
@@ -33,7 +33,7 @@ const addFileDataIfNeeded = async (file) => {
|
||||
return file;
|
||||
};
|
||||
|
||||
const errorMessageFromError = (e) => {
|
||||
const errorMessageFromError = e => {
|
||||
if (typeof e === 'string') {
|
||||
return e;
|
||||
} else if (e && e.message) {
|
||||
@@ -91,7 +91,7 @@ export class FilesRouter {
|
||||
} else {
|
||||
filesController
|
||||
.getFileData(config, filename)
|
||||
.then((data) => {
|
||||
.then(data => {
|
||||
res.status(200);
|
||||
res.set('Content-Type', contentType);
|
||||
res.set('Content-Length', data.length);
|
||||
|
||||
@@ -11,7 +11,7 @@ import { logger } from '../logger';
|
||||
|
||||
function parseObject(obj) {
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map((item) => {
|
||||
return obj.map(item => {
|
||||
return parseObject(item);
|
||||
});
|
||||
} else if (obj && obj.__type == 'Date') {
|
||||
@@ -68,7 +68,7 @@ export class FunctionsRouter extends PromiseRouter {
|
||||
message: jobHandler.setMessage.bind(jobHandler),
|
||||
};
|
||||
|
||||
return jobHandler.setRunning(jobName, params).then((jobStatus) => {
|
||||
return jobHandler.setRunning(jobName, params).then(jobStatus => {
|
||||
request.jobId = jobStatus.objectId;
|
||||
// run the function async
|
||||
process.nextTick(() => {
|
||||
@@ -77,10 +77,10 @@ export class FunctionsRouter extends PromiseRouter {
|
||||
return jobFunction(request);
|
||||
})
|
||||
.then(
|
||||
(result) => {
|
||||
result => {
|
||||
jobHandler.setSucceeded(result);
|
||||
},
|
||||
(error) => {
|
||||
error => {
|
||||
jobHandler.setFailed(error);
|
||||
}
|
||||
);
|
||||
@@ -166,7 +166,7 @@ export class FunctionsRouter extends PromiseRouter {
|
||||
req.auth && req.auth.user ? req.auth.user.id : undefined;
|
||||
const cleanInput = logger.truncateLogMessage(JSON.stringify(params));
|
||||
const { success, error, message } = FunctionsRouter.createResponseObject(
|
||||
(result) => {
|
||||
result => {
|
||||
try {
|
||||
const cleanResult = logger.truncateLogMessage(
|
||||
JSON.stringify(result.response.result)
|
||||
@@ -184,7 +184,7 @@ export class FunctionsRouter extends PromiseRouter {
|
||||
reject(e);
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
error => {
|
||||
try {
|
||||
logger.error(
|
||||
`Failed running cloud function ${functionName} for user ${userString} with:\n Input: ${cleanInput}\n Error: ` +
|
||||
|
||||
@@ -7,7 +7,7 @@ export class GlobalConfigRouter extends PromiseRouter {
|
||||
getGlobalConfig(req) {
|
||||
return req.config.database
|
||||
.find('_GlobalConfig', { objectId: '1' }, { limit: 1 })
|
||||
.then((results) => {
|
||||
.then(results => {
|
||||
if (results.length != 1) {
|
||||
// If there is no config in the database - return empty config.
|
||||
return { response: { params: {} } };
|
||||
@@ -51,14 +51,14 @@ export class GlobalConfigRouter extends PromiseRouter {
|
||||
}
|
||||
|
||||
mountRoutes() {
|
||||
this.route('GET', '/config', (req) => {
|
||||
this.route('GET', '/config', req => {
|
||||
return this.getGlobalConfig(req);
|
||||
});
|
||||
this.route(
|
||||
'PUT',
|
||||
'/config',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
(req) => {
|
||||
req => {
|
||||
return this.updateGlobalConfig(req);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -32,7 +32,7 @@ export class GraphQLRouter extends PromiseRouter {
|
||||
'GET',
|
||||
GraphQLConfigPath,
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
(req) => {
|
||||
req => {
|
||||
return this.getGraphQLConfig(req);
|
||||
}
|
||||
);
|
||||
@@ -40,7 +40,7 @@ export class GraphQLRouter extends PromiseRouter {
|
||||
'PUT',
|
||||
GraphQLConfigPath,
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
(req) => {
|
||||
req => {
|
||||
return this.updateGraphQLConfig(req);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -6,13 +6,13 @@ export class HooksRouter extends PromiseRouter {
|
||||
createHook(aHook, config) {
|
||||
return config.hooksController
|
||||
.createHook(aHook)
|
||||
.then((hook) => ({ response: hook }));
|
||||
.then(hook => ({ response: hook }));
|
||||
}
|
||||
|
||||
updateHook(aHook, config) {
|
||||
return config.hooksController
|
||||
.updateHook(aHook)
|
||||
.then((hook) => ({ response: hook }));
|
||||
.then(hook => ({ response: hook }));
|
||||
}
|
||||
|
||||
handlePost(req) {
|
||||
@@ -24,7 +24,7 @@ export class HooksRouter extends PromiseRouter {
|
||||
if (req.params.functionName) {
|
||||
return hooksController
|
||||
.getFunction(req.params.functionName)
|
||||
.then((foundFunction) => {
|
||||
.then(foundFunction => {
|
||||
if (!foundFunction) {
|
||||
throw new Parse.Error(
|
||||
143,
|
||||
@@ -36,10 +36,10 @@ export class HooksRouter extends PromiseRouter {
|
||||
}
|
||||
|
||||
return hooksController.getFunctions().then(
|
||||
(functions) => {
|
||||
functions => {
|
||||
return { response: functions || [] };
|
||||
},
|
||||
(err) => {
|
||||
err => {
|
||||
throw err;
|
||||
}
|
||||
);
|
||||
@@ -50,7 +50,7 @@ export class HooksRouter extends PromiseRouter {
|
||||
if (req.params.className && req.params.triggerName) {
|
||||
return hooksController
|
||||
.getTrigger(req.params.className, req.params.triggerName)
|
||||
.then((foundTrigger) => {
|
||||
.then(foundTrigger => {
|
||||
if (!foundTrigger) {
|
||||
throw new Parse.Error(
|
||||
143,
|
||||
@@ -63,7 +63,7 @@ export class HooksRouter extends PromiseRouter {
|
||||
|
||||
return hooksController
|
||||
.getTriggers()
|
||||
.then((triggers) => ({ response: triggers || [] }));
|
||||
.then(triggers => ({ response: triggers || [] }));
|
||||
}
|
||||
|
||||
handleDelete(req) {
|
||||
|
||||
@@ -32,7 +32,7 @@ function validateWithAppStore(url, receipt) {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}).then((httpResponse) => {
|
||||
}).then(httpResponse => {
|
||||
const body = httpResponse.data;
|
||||
if (body && body.status === 0) {
|
||||
// No need to pass anything, status is OK
|
||||
@@ -106,13 +106,13 @@ export class IAPValidationRouter extends PromiseRouter {
|
||||
() => {
|
||||
return successCallback();
|
||||
},
|
||||
(error) => {
|
||||
error => {
|
||||
if (error.status == 21007) {
|
||||
return validateWithAppStore(IAP_SANDBOX_URL, receipt).then(
|
||||
() => {
|
||||
return successCallback();
|
||||
},
|
||||
(error) => {
|
||||
error => {
|
||||
return errorCallback(error);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -24,25 +24,25 @@ export class InstallationsRouter extends ClassesRouter {
|
||||
req.info.clientSDK,
|
||||
req.info.context
|
||||
)
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
return { response: response };
|
||||
});
|
||||
}
|
||||
|
||||
mountRoutes() {
|
||||
this.route('GET', '/installations', (req) => {
|
||||
this.route('GET', '/installations', req => {
|
||||
return this.handleFind(req);
|
||||
});
|
||||
this.route('GET', '/installations/:objectId', (req) => {
|
||||
this.route('GET', '/installations/:objectId', req => {
|
||||
return this.handleGet(req);
|
||||
});
|
||||
this.route('POST', '/installations', (req) => {
|
||||
this.route('POST', '/installations', req => {
|
||||
return this.handleCreate(req);
|
||||
});
|
||||
this.route('PUT', '/installations/:objectId', (req) => {
|
||||
this.route('PUT', '/installations/:objectId', req => {
|
||||
return this.handleUpdate(req);
|
||||
});
|
||||
this.route('DELETE', '/installations/:objectId', (req) => {
|
||||
this.route('DELETE', '/installations/:objectId', req => {
|
||||
return this.handleDelete(req);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ export class LogsRouter extends PromiseRouter {
|
||||
'/scriptlog',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
this.validateRequest,
|
||||
(req) => {
|
||||
req => {
|
||||
return this.handleGET(req);
|
||||
}
|
||||
);
|
||||
@@ -50,7 +50,7 @@ export class LogsRouter extends PromiseRouter {
|
||||
level,
|
||||
};
|
||||
|
||||
return req.config.loggerController.getLogs(options).then((result) => {
|
||||
return req.config.loggerController.getLogs(options).then(result => {
|
||||
return Promise.resolve({
|
||||
response: result,
|
||||
});
|
||||
|
||||
@@ -191,14 +191,14 @@ export class PublicAPIRouter extends PromiseRouter {
|
||||
success: true,
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
err => {
|
||||
return Promise.resolve({
|
||||
success: false,
|
||||
err,
|
||||
});
|
||||
}
|
||||
)
|
||||
.then((result) => {
|
||||
.then(result => {
|
||||
const params = qs.stringify({
|
||||
username: username,
|
||||
token: token,
|
||||
@@ -277,10 +277,10 @@ export class PublicAPIRouter extends PromiseRouter {
|
||||
this.route(
|
||||
'GET',
|
||||
'/apps/:appId/verify_email',
|
||||
(req) => {
|
||||
req => {
|
||||
this.setConfig(req);
|
||||
},
|
||||
(req) => {
|
||||
req => {
|
||||
return this.verifyEmail(req);
|
||||
}
|
||||
);
|
||||
@@ -288,25 +288,25 @@ export class PublicAPIRouter extends PromiseRouter {
|
||||
this.route(
|
||||
'POST',
|
||||
'/apps/:appId/resend_verification_email',
|
||||
(req) => {
|
||||
req => {
|
||||
this.setConfig(req);
|
||||
},
|
||||
(req) => {
|
||||
req => {
|
||||
return this.resendVerificationEmail(req);
|
||||
}
|
||||
);
|
||||
|
||||
this.route('GET', '/apps/choose_password', (req) => {
|
||||
this.route('GET', '/apps/choose_password', req => {
|
||||
return this.changePassword(req);
|
||||
});
|
||||
|
||||
this.route(
|
||||
'POST',
|
||||
'/apps/:appId/request_password_reset',
|
||||
(req) => {
|
||||
req => {
|
||||
this.setConfig(req);
|
||||
},
|
||||
(req) => {
|
||||
req => {
|
||||
return this.resetPassword(req);
|
||||
}
|
||||
);
|
||||
@@ -314,10 +314,10 @@ export class PublicAPIRouter extends PromiseRouter {
|
||||
this.route(
|
||||
'GET',
|
||||
'/apps/:appId/request_password_reset',
|
||||
(req) => {
|
||||
req => {
|
||||
this.setConfig(req);
|
||||
},
|
||||
(req) => {
|
||||
req => {
|
||||
return this.requestResetPassword(req);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -21,7 +21,7 @@ export class PurgeRouter extends PromiseRouter {
|
||||
}
|
||||
return { response: {} };
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
if (!error || (error && error.code === Parse.Error.OBJECT_NOT_FOUND)) {
|
||||
return { response: {} };
|
||||
}
|
||||
@@ -34,7 +34,7 @@ export class PurgeRouter extends PromiseRouter {
|
||||
'DELETE',
|
||||
'/purge/:className',
|
||||
middleware.promiseEnforceMasterKeyAccess,
|
||||
(req) => {
|
||||
req => {
|
||||
return this.handlePurge(req);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -29,12 +29,12 @@ export class PushRouter extends PromiseRouter {
|
||||
|
||||
const where = PushRouter.getQueryCondition(req);
|
||||
let resolve;
|
||||
const promise = new Promise((_resolve) => {
|
||||
const promise = new Promise(_resolve => {
|
||||
resolve = _resolve;
|
||||
});
|
||||
let pushStatusId;
|
||||
pushController
|
||||
.sendPush(req.body, where, req.config, req.auth, (objectId) => {
|
||||
.sendPush(req.body, where, req.config, req.auth, objectId => {
|
||||
pushStatusId = objectId;
|
||||
resolve({
|
||||
headers: {
|
||||
@@ -45,7 +45,7 @@ export class PushRouter extends PromiseRouter {
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch(err => {
|
||||
req.config.loggerController.error(
|
||||
`_PushStatus ${pushStatusId}: error while sending push`,
|
||||
err
|
||||
|
||||
@@ -6,19 +6,19 @@ export class RolesRouter extends ClassesRouter {
|
||||
}
|
||||
|
||||
mountRoutes() {
|
||||
this.route('GET', '/roles', (req) => {
|
||||
this.route('GET', '/roles', req => {
|
||||
return this.handleFind(req);
|
||||
});
|
||||
this.route('GET', '/roles/:objectId', (req) => {
|
||||
this.route('GET', '/roles/:objectId', req => {
|
||||
return this.handleGet(req);
|
||||
});
|
||||
this.route('POST', '/roles', (req) => {
|
||||
this.route('POST', '/roles', req => {
|
||||
return this.handleCreate(req);
|
||||
});
|
||||
this.route('PUT', '/roles/:objectId', (req) => {
|
||||
this.route('PUT', '/roles/:objectId', req => {
|
||||
return this.handleUpdate(req);
|
||||
});
|
||||
this.route('DELETE', '/roles/:objectId', (req) => {
|
||||
this.route('DELETE', '/roles/:objectId', req => {
|
||||
return this.handleDelete(req);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,17 +16,17 @@ function classNameMismatchResponse(bodyClass, pathClass) {
|
||||
function getAllSchemas(req) {
|
||||
return req.config.database
|
||||
.loadSchema({ clearCache: true })
|
||||
.then((schemaController) => schemaController.getAllClasses(true))
|
||||
.then((schemas) => ({ response: { results: schemas } }));
|
||||
.then(schemaController => schemaController.getAllClasses(true))
|
||||
.then(schemas => ({ response: { results: schemas } }));
|
||||
}
|
||||
|
||||
function getOneSchema(req) {
|
||||
const className = req.params.className;
|
||||
return req.config.database
|
||||
.loadSchema({ clearCache: true })
|
||||
.then((schemaController) => schemaController.getOneSchema(className, true))
|
||||
.then((schema) => ({ response: schema }))
|
||||
.catch((error) => {
|
||||
.then(schemaController => schemaController.getOneSchema(className, true))
|
||||
.then(schema => ({ response: schema }))
|
||||
.catch(error => {
|
||||
if (error === undefined) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_CLASS_NAME,
|
||||
@@ -64,7 +64,7 @@ function createSchema(req) {
|
||||
|
||||
return req.config.database
|
||||
.loadSchema({ clearCache: true })
|
||||
.then((schema) =>
|
||||
.then(schema =>
|
||||
schema.addClassIfNotExists(
|
||||
className,
|
||||
req.body.fields,
|
||||
@@ -72,7 +72,7 @@ function createSchema(req) {
|
||||
req.body.indexes
|
||||
)
|
||||
)
|
||||
.then((schema) => ({ response: schema }));
|
||||
.then(schema => ({ response: schema }));
|
||||
}
|
||||
|
||||
function modifySchema(req) {
|
||||
@@ -91,7 +91,7 @@ function modifySchema(req) {
|
||||
|
||||
return req.config.database
|
||||
.loadSchema({ clearCache: true })
|
||||
.then((schema) =>
|
||||
.then(schema =>
|
||||
schema.updateClass(
|
||||
className,
|
||||
submittedFields,
|
||||
@@ -100,10 +100,10 @@ function modifySchema(req) {
|
||||
req.config.database
|
||||
)
|
||||
)
|
||||
.then((result) => ({ response: result }));
|
||||
.then(result => ({ response: result }));
|
||||
}
|
||||
|
||||
const deleteSchema = (req) => {
|
||||
const deleteSchema = req => {
|
||||
if (req.auth.isReadOnly) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OPERATION_FORBIDDEN,
|
||||
|
||||
@@ -26,7 +26,7 @@ export class SessionsRouter extends ClassesRouter {
|
||||
req.info.clientSDK,
|
||||
req.info.context
|
||||
)
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
if (!response.results || response.results.length == 0) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_SESSION_TOKEN,
|
||||
@@ -74,25 +74,25 @@ export class SessionsRouter extends ClassesRouter {
|
||||
}
|
||||
|
||||
mountRoutes() {
|
||||
this.route('GET', '/sessions/me', (req) => {
|
||||
this.route('GET', '/sessions/me', req => {
|
||||
return this.handleMe(req);
|
||||
});
|
||||
this.route('GET', '/sessions', (req) => {
|
||||
this.route('GET', '/sessions', req => {
|
||||
return this.handleFind(req);
|
||||
});
|
||||
this.route('GET', '/sessions/:objectId', (req) => {
|
||||
this.route('GET', '/sessions/:objectId', req => {
|
||||
return this.handleGet(req);
|
||||
});
|
||||
this.route('POST', '/sessions', (req) => {
|
||||
this.route('POST', '/sessions', req => {
|
||||
return this.handleCreate(req);
|
||||
});
|
||||
this.route('PUT', '/sessions/:objectId', (req) => {
|
||||
this.route('PUT', '/sessions/:objectId', req => {
|
||||
return this.handleUpdate(req);
|
||||
});
|
||||
this.route('DELETE', '/sessions/:objectId', (req) => {
|
||||
this.route('DELETE', '/sessions/:objectId', req => {
|
||||
return this.handleDelete(req);
|
||||
});
|
||||
this.route('POST', '/upgradeToRevocableSession', (req) => {
|
||||
this.route('POST', '/upgradeToRevocableSession', req => {
|
||||
return this.handleUpdateToRevocableSession(req);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
}
|
||||
return req.config.database
|
||||
.find('_User', query)
|
||||
.then((results) => {
|
||||
.then(results => {
|
||||
if (!results.length) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
@@ -96,14 +96,14 @@ export class UsersRouter extends ClassesRouter {
|
||||
req.config.loggerController.warn(
|
||||
"There is a user which email is the same as another user's username, logging in based on username"
|
||||
);
|
||||
user = results.filter((user) => user.username === username)[0];
|
||||
user = results.filter(user => user.username === username)[0];
|
||||
} else {
|
||||
user = results[0];
|
||||
}
|
||||
|
||||
return passwordCrypto.compare(password, user.password);
|
||||
})
|
||||
.then((correct) => {
|
||||
.then(correct => {
|
||||
isValidPassword = correct;
|
||||
const accountLockoutPolicy = new AccountLockout(user, req.config);
|
||||
return accountLockoutPolicy.handleLoginAttempt(isValidPassword);
|
||||
@@ -145,7 +145,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
// Sometimes the authData still has null on that keys
|
||||
// https://github.com/parse-community/parse-server/issues/935
|
||||
if (user.authData) {
|
||||
Object.keys(user.authData).forEach((provider) => {
|
||||
Object.keys(user.authData).forEach(provider => {
|
||||
if (user.authData[provider] === null) {
|
||||
delete user.authData[provider];
|
||||
}
|
||||
@@ -157,7 +157,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
|
||||
return resolve(user);
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
return reject(error);
|
||||
});
|
||||
});
|
||||
@@ -181,7 +181,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
req.info.clientSDK,
|
||||
req.info.context
|
||||
)
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
if (
|
||||
!response.results ||
|
||||
response.results.length == 0 ||
|
||||
@@ -282,13 +282,13 @@ export class UsersRouter extends ClassesRouter {
|
||||
|
||||
handleVerifyPassword(req) {
|
||||
return this._authenticateUserFromRequest(req)
|
||||
.then((user) => {
|
||||
.then(user => {
|
||||
// Remove hidden properties.
|
||||
UsersRouter.removeHiddenProperties(user);
|
||||
|
||||
return { response: user };
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
@@ -306,7 +306,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
req.info.clientSDK,
|
||||
req.info.context
|
||||
)
|
||||
.then((records) => {
|
||||
.then(records => {
|
||||
if (records.results && records.results.length) {
|
||||
return rest
|
||||
.del(
|
||||
@@ -383,7 +383,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
response: {},
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
err => {
|
||||
if (err.code === Parse.Error.OBJECT_NOT_FOUND) {
|
||||
// Return success so that this endpoint can't
|
||||
// be used to enumerate valid emails
|
||||
@@ -414,70 +414,68 @@ export class UsersRouter extends ClassesRouter {
|
||||
);
|
||||
}
|
||||
|
||||
return req.config.database
|
||||
.find('_User', { email: email })
|
||||
.then((results) => {
|
||||
if (!results.length || results.length < 1) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.EMAIL_NOT_FOUND,
|
||||
`No user found with email ${email}`
|
||||
);
|
||||
}
|
||||
const user = results[0];
|
||||
return req.config.database.find('_User', { email: email }).then(results => {
|
||||
if (!results.length || results.length < 1) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.EMAIL_NOT_FOUND,
|
||||
`No user found with email ${email}`
|
||||
);
|
||||
}
|
||||
const user = results[0];
|
||||
|
||||
// remove password field, messes with saving on postgres
|
||||
delete user.password;
|
||||
// remove password field, messes with saving on postgres
|
||||
delete user.password;
|
||||
|
||||
if (user.emailVerified) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OTHER_CAUSE,
|
||||
`Email ${email} is already verified.`
|
||||
);
|
||||
}
|
||||
if (user.emailVerified) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OTHER_CAUSE,
|
||||
`Email ${email} is already verified.`
|
||||
);
|
||||
}
|
||||
|
||||
const userController = req.config.userController;
|
||||
return userController.regenerateEmailVerifyToken(user).then(() => {
|
||||
userController.sendVerificationEmail(user);
|
||||
return { response: {} };
|
||||
});
|
||||
const userController = req.config.userController;
|
||||
return userController.regenerateEmailVerifyToken(user).then(() => {
|
||||
userController.sendVerificationEmail(user);
|
||||
return { response: {} };
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
mountRoutes() {
|
||||
this.route('GET', '/users', (req) => {
|
||||
this.route('GET', '/users', req => {
|
||||
return this.handleFind(req);
|
||||
});
|
||||
this.route('POST', '/users', (req) => {
|
||||
this.route('POST', '/users', req => {
|
||||
return this.handleCreate(req);
|
||||
});
|
||||
this.route('GET', '/users/me', (req) => {
|
||||
this.route('GET', '/users/me', req => {
|
||||
return this.handleMe(req);
|
||||
});
|
||||
this.route('GET', '/users/:objectId', (req) => {
|
||||
this.route('GET', '/users/:objectId', req => {
|
||||
return this.handleGet(req);
|
||||
});
|
||||
this.route('PUT', '/users/:objectId', (req) => {
|
||||
this.route('PUT', '/users/:objectId', req => {
|
||||
return this.handleUpdate(req);
|
||||
});
|
||||
this.route('DELETE', '/users/:objectId', (req) => {
|
||||
this.route('DELETE', '/users/:objectId', req => {
|
||||
return this.handleDelete(req);
|
||||
});
|
||||
this.route('GET', '/login', (req) => {
|
||||
this.route('GET', '/login', req => {
|
||||
return this.handleLogIn(req);
|
||||
});
|
||||
this.route('POST', '/login', (req) => {
|
||||
this.route('POST', '/login', req => {
|
||||
return this.handleLogIn(req);
|
||||
});
|
||||
this.route('POST', '/logout', (req) => {
|
||||
this.route('POST', '/logout', req => {
|
||||
return this.handleLogOut(req);
|
||||
});
|
||||
this.route('POST', '/requestPasswordReset', (req) => {
|
||||
this.route('POST', '/requestPasswordReset', req => {
|
||||
return this.handleResetRequest(req);
|
||||
});
|
||||
this.route('POST', '/verificationEmailRequest', (req) => {
|
||||
this.route('POST', '/verificationEmailRequest', req => {
|
||||
return this.handleVerificationEmailRequest(req);
|
||||
});
|
||||
this.route('GET', '/verifyPassword', (req) => {
|
||||
this.route('GET', '/verifyPassword', req => {
|
||||
return this.handleVerifyPassword(req);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user