Works. fixed GAE errors...
This commit is contained in:
parent
bd072b675e
commit
f26625b469
6 changed files with 58 additions and 29 deletions
|
@ -2,11 +2,11 @@
|
||||||
"name": "the_social_notework",
|
"name": "the_social_notework",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "A sample Back ent for an Android app",
|
"description": "A sample Back ent for an Android app",
|
||||||
"main": "app.js",
|
"main": "server.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"start": "node app.js"
|
"start": "node server.js"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
'use strict';
|
|
||||||
var serverModule = require('./server/server');
|
var serverModule = require('./server/server');
|
||||||
|
|
||||||
var server = serverModule.getInstance();
|
var server = serverModule.getInstance();
|
|
@ -3,7 +3,7 @@ var gcloud = require('gcloud');
|
||||||
var dataset = gcloud.datastore({
|
var dataset = gcloud.datastore({
|
||||||
// This environment variable is set by app.yaml when running on GAE, but will
|
// This environment variable is set by app.yaml when running on GAE, but will
|
||||||
// need to be manually set when running locally.
|
// need to be manually set when running locally.
|
||||||
projectId: 'thesocialnotework'
|
projectId: 'thesocialnotework-api'
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = dataset;
|
module.exports = dataset;
|
||||||
|
|
|
@ -65,7 +65,7 @@ router.post('/register', (req, res) => {
|
||||||
password: req.body.password,
|
password: req.body.password,
|
||||||
email: req.body.email,
|
email: req.body.email,
|
||||||
creation_time: new Date(),
|
creation_time: new Date(),
|
||||||
avatar: null
|
avatar: 'http://www.aljazeera.com/mritems/images/site/DefaultAvatar.jpg'
|
||||||
}
|
}
|
||||||
}, function (err, user) {
|
}, function (err, user) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -85,7 +85,7 @@ router.post('/register', (req, res) => {
|
||||||
|
|
||||||
router.post('/user/upsert', (req, res) => {});
|
router.post('/user/upsert', (req, res) => {});
|
||||||
router.post('/note/upsert', (req, res) => {
|
router.post('/note/upsert', (req, res) => {
|
||||||
if (!req.body || !req.body.title || !req.body.body || !req.body.tags || !req.body.owner_id || !req.body.address) {
|
if (!req.body || !req.body.title || !req.body.body || !req.body.owner_id || !req.body.address) {
|
||||||
utils.response_400(res, {
|
utils.response_400(res, {
|
||||||
title: "Note To Self",
|
title: "Note To Self",
|
||||||
body: "I know nothing!!!",
|
body: "I know nothing!!!",
|
||||||
|
@ -98,21 +98,55 @@ router.post('/note/upsert', (req, res) => {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (req.body.id) { //Update a Note
|
if (req.body.id) { //Update a Note
|
||||||
// var query = db.createQuery('Note').filter('owner_id', )
|
var key = db.key(['Note', Number(req.body.id)]);
|
||||||
utils.response_500(res, "Not Yet Implemented - Imean updating the Note");
|
db.get(key, (err, entity) => {
|
||||||
} else {
|
if (err) {
|
||||||
|
utils.response_500(res, "DB Error");
|
||||||
|
} else {
|
||||||
|
if (!entity) {
|
||||||
|
utils.response_400(res, {
|
||||||
|
title: "Note To Self",
|
||||||
|
body: "I know nothing!!!",
|
||||||
|
lat: 35.01,
|
||||||
|
lng: 51.2,
|
||||||
|
address: "Some Where over the rainbow",
|
||||||
|
tags: ['nofilter', 'testing', 'education'],
|
||||||
|
owner_id: 123,
|
||||||
|
is_public: true
|
||||||
|
}, "id not valid - No Notes with that ID");
|
||||||
|
} else {
|
||||||
|
entity.data.title = req.body.title || entity.data.title;
|
||||||
|
entity.data.body = req.body.body || entity.data.body;
|
||||||
|
entity.data.lat = req.body.lat || entity.data.lat;
|
||||||
|
entity.data.lng = req.body.lng || entity.data.lng;
|
||||||
|
entity.data.address = req.body.address || entity.data.address;
|
||||||
|
entity.data.tags = req.body.tags || entity.data.tags;
|
||||||
|
entity.data.is_public = req.body.is_public || entity.data.is_public;
|
||||||
|
db.save(entity, (err, _resp) => {
|
||||||
|
if (err) {
|
||||||
|
utils.response_500(res, "DB Error");
|
||||||
|
} else {
|
||||||
|
res.send(utils.convertToNoteObj(entity));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else { //** Create a new Note **//
|
||||||
db.save({
|
db.save({
|
||||||
key: db.key('Note'),
|
key: db.key('Note'),
|
||||||
data: {
|
data: {
|
||||||
title: req.body.title,
|
title: req.body.title,
|
||||||
lat: req.body.lat,
|
lat: req.body.lat,
|
||||||
lng: req.body.lng,
|
lng: req.body.lng,
|
||||||
|
address: req.body.address,
|
||||||
body: req.body.body,
|
body: req.body.body,
|
||||||
owner_id: req.body.owner_id,
|
owner_id: req.body.owner_id,
|
||||||
is_public: req.body.is_public || false,
|
is_public: req.body.is_public || false,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
likes: 0,
|
likes: 0,
|
||||||
tags: req.body.tags || []
|
tags: req.body.tags || [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(err, response) => {
|
(err, response) => {
|
||||||
|
@ -120,22 +154,16 @@ router.post('/note/upsert', (req, res) => {
|
||||||
utils.response_500(res, "DB Error");
|
utils.response_500(res, "DB Error");
|
||||||
} else {
|
} else {
|
||||||
res.statusCode = 201;
|
res.statusCode = 201;
|
||||||
res.send({
|
var id = Number(response.mutationResults[0].key.path[0].id);
|
||||||
status: "OK",
|
var key = db.key(['Note', id]);
|
||||||
message: "Saved"
|
db.get(key, (err, entity) => {
|
||||||
|
console.log(JSON.stringify(entity, null, 2));
|
||||||
|
if (!err) res.send({
|
||||||
|
status: "OK",
|
||||||
|
note: utils.convertToNoteObj(entity)
|
||||||
|
});
|
||||||
|
else utils.response_500(res, "DB Error->" + err);
|
||||||
});
|
});
|
||||||
// var query = db.createQuery('Note')
|
|
||||||
// .filter('_id', response.mutationResults[0].key.path[0].id);
|
|
||||||
// db.get(db.key(['Note', response.mutationResults[0].key.path[0].id]), (err, entity) => {
|
|
||||||
// if (err) {
|
|
||||||
// utils.response_500(res, "DB Error" + err);
|
|
||||||
// } else {
|
|
||||||
// res.statusCode = 201;
|
|
||||||
// console.log(JSON.stringify(entity, null, 2));
|
|
||||||
// console.log('=====');
|
|
||||||
// res.send(utils.convertToNoteObj(entity));
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
|
'use strict';
|
||||||
var server;
|
var server;
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var bodyParser = require('body-parser');
|
var bodyParser = require('body-parser');
|
||||||
var api = require('./api');
|
var api = require('./api');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
constructor() {
|
constructor() {
|
||||||
console.log('Pin');
|
console.log('Creating Server');
|
||||||
this.app = express();
|
this.app = express();
|
||||||
// parse application/x-www-form-urlencoded
|
// parse application/x-www-form-urlencoded
|
||||||
this.app.use(bodyParser.urlencoded({
|
this.app.use(bodyParser.urlencoded({
|
||||||
|
|
|
@ -34,14 +34,16 @@ module.exports = {
|
||||||
title: note.data.title,
|
title: note.data.title,
|
||||||
location: {
|
location: {
|
||||||
lat: note.data.lat,
|
lat: note.data.lat,
|
||||||
lng: note.data.lng
|
lng: note.data.lng,
|
||||||
|
address: note.data.address
|
||||||
},
|
},
|
||||||
body: note.data.body,
|
body: note.data.body,
|
||||||
owner_id: note.data.owner_id,
|
owner_id: note.data.owner_id,
|
||||||
is_public: note.data.is_public,
|
is_public: note.data.is_public,
|
||||||
created_at: note.data.created_at,
|
created_at: note.data.created_at,
|
||||||
likes: note.data.likes,
|
likes: note.data.likes,
|
||||||
tags: note.data.tags,
|
tags: note.data.tags
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue