Skip to content

Commit

Permalink
chore: fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
hopetambala committed Apr 26, 2020
1 parent a13286f commit 4a552fc
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 91 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
logs
public
cloud/_tests_
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![codecov](https://codecov.io/gh/hopetambala/puente-node-cloudcode/branch/master/graph/badge.svg)](https://codecov.io/gh/hopetambala/puente-node-cloudcode)
![](https://img.shields.io/badge/parse_server-✓-blueviolet.svg)

Cloud Code is easy to use because it’s built on the JavaScript SDK for parse-server. The only difference is that this code runs in our Parse Server rather than running on the user’s mobile device. When we update your Cloud Code, it becomes available to all mobile environments instantly.
Cloud Code is easy to use because it’s built on the JavaScript SDK for parse-server. The only difference is that this code runs in our Parse Server rather than running on the user’s mobile device. When we update our Cloud Code, it becomes available to all mobile environments instantly.

For a resource guide:
https://docs.parseplatform.org/cloudcode/guide/
Expand Down Expand Up @@ -49,7 +49,8 @@ This application is built with [Parse Server](https://reactjs.org) and [Back4App
Here are some quick commands to get started in Node:

- `npm install`: Install Node dependencies
- `npm start`: Start the hot reloading development server.
- `npm start`: Start the development server.
- `npm start-with-dash`: Start the server with Parse Dashboard
- `npm test`: Run the test suit
- `npm lint`: Run the ESLinter.

Expand All @@ -67,8 +68,6 @@ To get ramped onto the project with Back4App these following steps must be taken
- Run `b4a add` and choose the project you've created in Back4app Web Service
- Run `b4a develop` to see changes live with Back4app Web Service



## Testing

### JSBin
Expand Down
39 changes: 19 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
const express = require('express');
const { ParseServer } = require('parse-server');
const path = require('path');

var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
const databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;

if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}

var api = new ParseServer({
const api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
cloud: process.env.CLOUD_CODE_MAIN || `${__dirname}/cloud/main.js`,
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY || 'myMasterKey', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
masterKey: process.env.MASTER_KEY || 'myMasterKey', // Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
}
classNames: ['Posts', 'Comments'], // List of classes to support for query subscriptions
},
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey



var app = express();
const app = express();

// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));

// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
const mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);



// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
app.get('/', (req, res) => {
res.status(200).send("I'z a website");
});

// There will be a test page available on the /test path of your server url
// Remove this before launching your app
app.get('/test', function(req, res) {
app.get('/test', (req, res) => {
res.sendFile(path.join(__dirname, '/public/test.html'));
});

var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
const port = process.env.PORT || 1337;
const httpServer = require('http').createServer(app);

httpServer.listen(port, () => {
console.log(`parse-server-example running on port ${port}.`);
});

// This will enable the Live Query real-time server
Expand Down
134 changes: 67 additions & 67 deletions public/assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@
* Steps handler
*/

var Steps = {};
const Steps = {};

Steps.init = function() {
Steps.init = function () {
this.buildParseUrl();
this.bindBtn('#step-1-btn', function(e){
this.bindBtn('#step-1-btn', (e) => {
ParseRequest.postData();
e.preventDefault();
})
}
});
};

Steps.buildParseUrl = function() {
var url = Config.getUrl();
$('#parse-url').html(url + '/parse');
}
Steps.buildParseUrl = function () {
const url = Config.getUrl();
$('#parse-url').html(`${url}/parse`);
};

Steps.bindBtn = function(id, callback) {
Steps.bindBtn = function (id, callback) {
$(id).click(callback);
}
};

Steps.closeStep = function(id) {
Steps.closeStep = function (id) {
$(id).addClass('step--disabled');
}
};

Steps.openStep = function(id) {
Steps.openStep = function (id) {
$(id).removeClass('step--disabled');
}
};

Steps.fillStepOutput = function(id, data) {
$(id).html('Output: ' + data).slideDown();
}
Steps.fillStepOutput = function (id, data) {
$(id).html(`Output: ${data}`).slideDown();
};

Steps.fillStepError = function(id, errorMsg) {
Steps.fillStepError = function (id, errorMsg) {
$(id).html(errorMsg).slideDown();
}
};


Steps.fillBtn = function(id, message) {
$(id).addClass('success').html('' + message);
}
Steps.fillBtn = function (id, message) {
$(id).addClass('success').html(`${message}`);
};

Steps.showWorkingMessage = function() {
Steps.showWorkingMessage = function () {
$('#step-4').delay(500).slideDown();
}
};


/**
Expand All @@ -53,8 +53,8 @@ Steps.showWorkingMessage = function() {

var ParseRequest = {};

ParseRequest.postData = function() {
XHR.setCallback(function(data){
ParseRequest.postData = function () {
XHR.setCallback((data) => {
// store objectID
Store.objectId = JSON.parse(data).objectId;
// close first step
Expand All @@ -63,69 +63,69 @@ ParseRequest.postData = function() {
Steps.fillBtn('#step-1-btn', 'Posted');
// open second step
Steps.openStep('#step-2');
Steps.bindBtn('#step-2-btn', function(e){
Steps.bindBtn('#step-2-btn', (e) => {
ParseRequest.getData();
e.preventDefault();
});
},
function(error) {
Steps.fillStepError('#step-1-error', 'There was a failure: ' + error);
});
(error) => {
Steps.fillStepError('#step-1-error', `There was a failure: ${error}`);
});
XHR.POST('/parse/classes/GameScore');
};

ParseRequest.getData = function() {
XHR.setCallback(function(data){
ParseRequest.getData = function () {
XHR.setCallback((data) => {
// close second step
Steps.closeStep('#step-2');
Steps.fillStepOutput('#step-2-output', data);
Steps.fillBtn('#step-2-btn', 'Fetched');
// open third step
Steps.openStep('#step-3');
Steps.bindBtn('#step-3-btn', function(e){
Steps.bindBtn('#step-3-btn', (e) => {
ParseRequest.postCloudCodeData();
e.preventDefault();
});
},
function(error) {
Steps.fillStepError('#step-2-error', 'There was a failure: ' + error);
});
});
},
(error) => {
Steps.fillStepError('#step-2-error', `There was a failure: ${error}`);
});
XHR.GET('/parse/classes/GameScore');
};

ParseRequest.postCloudCodeData = function() {
XHR.setCallback(function(data){
ParseRequest.postCloudCodeData = function () {
XHR.setCallback((data) => {
// close second step
Steps.closeStep('#step-3');
Steps.fillStepOutput('#step-3-output', data);
Steps.fillBtn('#step-3-btn', 'Tested');
// open third step
Steps.showWorkingMessage();
},
function(error) {
Steps.fillStepError('#step-3-error', 'There was a failure: ' + error);
});
},
(error) => {
Steps.fillStepError('#step-3-error', `There was a failure: ${error}`);
});
XHR.POST('/parse/functions/hello');
}
};


/**
* Store objectId and other references
*/

var Store = {
objectId: ""
objectId: '',
};

var Config = {};

Config.getUrl = function() {
Config.getUrl = function () {
if (url) return url;
var port = window.location.port;
var url = window.location.protocol + '//' + window.location.hostname;
if (port) url = url + ':' + port;
const { port } = window.location;
var url = `${window.location.protocol}//${window.location.hostname}`;
if (port) url = `${url}:${port}`;
return url;
}
};


/**
Expand All @@ -134,10 +134,10 @@ Config.getUrl = function() {

var XHR = {};

XHR.setCallback = function(callback, failureCallback) {
XHR.setCallback = function (callback, failureCallback) {
this.xhttp = new XMLHttpRequest();
var _self = this;
this.xhttp.onreadystatechange = function() {
const _self = this;
this.xhttp.onreadystatechange = function () {
if (_self.xhttp.readyState == 4) {
if (_self.xhttp.status >= 200 && _self.xhttp.status <= 299) {
callback(_self.xhttp.responseText);
Expand All @@ -146,22 +146,22 @@ XHR.setCallback = function(callback, failureCallback) {
}
}
};
}
};

XHR.POST = function(path, callback) {
var seed = {"score":1337,"playerName":"Sean Plott","cheatMode":false}
this.xhttp.open("POST", Config.getUrl() + path, true);
this.xhttp.setRequestHeader("X-Parse-Application-Id", $('#appId').val());
this.xhttp.setRequestHeader("Content-type", "application/json");
XHR.POST = function (path, callback) {
const seed = { score: 1337, playerName: 'Sean Plott', cheatMode: false };
this.xhttp.open('POST', Config.getUrl() + path, true);
this.xhttp.setRequestHeader('X-Parse-Application-Id', $('#appId').val());
this.xhttp.setRequestHeader('Content-type', 'application/json');
this.xhttp.send(JSON.stringify(seed));
}
};

XHR.GET = function(path, callback) {
this.xhttp.open("GET", Config.getUrl() + path + '/' + Store.objectId, true);
this.xhttp.setRequestHeader("X-Parse-Application-Id", $('#appId').val());
this.xhttp.setRequestHeader("Content-type", "application/json");
XHR.GET = function (path, callback) {
this.xhttp.open('GET', `${Config.getUrl() + path}/${Store.objectId}`, true);
this.xhttp.setRequestHeader('X-Parse-Application-Id', $('#appId').val());
this.xhttp.setRequestHeader('Content-type', 'application/json');
this.xhttp.send(null);
}
};


/**
Expand Down

0 comments on commit 4a552fc

Please sign in to comment.