/**
* notule fill by user
*/
-router.post('countSend', function(req, res){
+router.post('/countSend', function(req, res){
//req.body.notuleId
new Models.Notule('id', req.body.notuleId).fetch({column: ['countsend']})
.then(function(notule){
});
+router.get('/postalCode/:code', function(req, res){
-/**
- * get one notule and its email
- */
-router.get('/:notuleId/:collectivityId', function(req, res){
-
-console.log("get one notules");
-
- var linktable = {
- collectivity_id : req.params.notuleId,
- notule_id : req.params.collectivityId,
- }
+ console.log("toto");
- Models.Collectivity_Notule.where(linktable).fetch({withRelated: ['notule']})
- .then(function (notules){
- res.json({success : true, message: notules.toJSON()});
+ Models.Collectivity.where('code', req.params.code)
+ .fetch({
+ withRelated: ['collectivityMother'],
+ columns: ['id']
})
- .catch(function(err){
- res.json({success : false, message: err});
+ .then(function(collectivity){
+ var collIds = []
+ if(collectivity){
+ //res.json({success: true, message:collectivity.toJSON()})
+ var coll = collectivity.toJSON();
+ collIds.push(coll.id);
+ for(var i = 0; i < coll.collectivityMother.length; i++){
+ collIds.push(coll.collectivityMother[i].collectivity_motherid);
+ }
+ }
+ notulesList(res, collIds)
});
});
+
+
+
+
/**
* create a new notule
*/
var resize = function(file){
var gm = require('gm').subClass({imageMagick: true});
console.log(resize);
- gm(file)
+ gm(file)
.resize(160, 160, '!')
.write(file, function (err) {
console.log("error : " + err)
-
-router.get('/client/:lat/:lon', function(req, res){
-
- lat = req.params.lat;
- lon = req.params.lon;
-
- // client.get("http://nominatim.openstreetmap.org/reverse?format=json&lat=" + lat +"&lon=" + lon +"&email=theo.guillon@adullact-projet.coop", function (data, response) {
+router.get('/cp/:lat/:lon', function(req, res){
+ var lat = req.params.lat;
+ var lon = req.params.lon;
+ client.get("http://nominatim.openstreetmap.org/reverse?format=json&lat=" + lat +"&lon=" + lon +"&email=theo.guillon@adullact-projet.coop", function (data, response) {
// parsed response body as js object
//console.log(data);
//console.log(decoder.write(data));
- // res.json({city : data.address.city})
+
+
+ res.json({success: true, postcode: data.address.postcode});
+
+
+
//get all corresponding collecitvities
//res.json({content : data});
- /* if(!data.address.city){
- return res.send({success: false, message:"no city"});
- }*/
+ /* if(!data.address.city){
+ return res.send({success: false, message:"no city"});
+ }*/
+
+ });
+});
+
+
+
+
+router.get('/client/:lat/:lon', function(req, res){
+
+ var lat = req.params.lat;
+ var lon = req.params.lon;
+
+ client.get("http://nominatim.openstreetmap.org/reverse?format=json&lat=" + lat +"&lon=" + lon +"&email=theo.guillon@adullact-projet.coop", function (data, response) {
+ // parsed response body as js object
+ //console.log(data);
+ //console.log(decoder.write(data));
+ // res.json({city : data.address.city})
+
+ //get all corresponding collecitvities
+
+ //res.json({content : data});
+ if(!data.address){
+ return res.send({success: false, message:"no city"});
+ }
var city = removeDiacritics(data.address.city).toUpperCase()
- Models.Collectivity.where('name', /*data.address.city*/"CĂ©ret")
- .fetch({
- withRelated: ['collectivityMother'],
- columns: ['id']
- })
- .then(function(collectivity){
- var collIds = []
- if(collectivity){
- //res.json({success: true, message:collectivity.toJSON()})
- coll = collectivity.toJSON();
- collIds.push(coll.id);
- for(var i = 0; i < coll.collectivityMother.length; i++){
- collIds.push(coll.collectivityMother[i].collectivity_motherid);
- }
+ Models.Collectivity.where('name', city)
+ .fetch({
+ withRelated: ['collectivityMother'],
+ columns: ['id']
+ })
+ .then(function(collectivity){
+ var collIds = []
+ if(collectivity){
+ //res.json({success: true, message:collectivity.toJSON()})
+ coll = collectivity.toJSON();
+ collIds.push(coll.id);
+ for(var i = 0; i < coll.collectivityMother.length; i++){
+ collIds.push(coll.collectivityMother[i].collectivity_motherid);
}
+ }
+ //res.json({success: true, message: collIds});
+ notulesList(res, collIds)
+ })
- //res.json({success: true, message: collIds});
- notulesList(res, collIds)
- })
-
- //});
+ });
});
+
+
+
+
var notulesList = function(res,collIds){
Models.Collectivity_Notule.where('collectivity_id', 'in', collIds).fetchAll({columns: ['notule_id']})
.then(function(model) {
if (model) {
var coll = model.toJSON();
console.log(coll);
+
+ for(var i = 0; i < coll.length; i++){
+ //coll[i].collectivity = coll[i].collectivityNotule.collectivity;
+ console.log(coll[i]);
+ for(var j = 0; j < coll[i].collectivityNotule.length; j++){
+ coll[i].collectivityNotule[j].id = coll[i].collectivityNotule[j].collectivity.id;
+ coll[i].collectivityNotule[j].name = coll[i].collectivityNotule[j].collectivity.name;
+ coll[i].collectivityNotule[j].type = coll[i].collectivityNotule[j].collectivity.type;
+ coll[i].collectivityNotule[j].code = coll[i].collectivityNotule[j].collectivity.code;
+ coll[i].collectivityNotule[j].image = coll[i].collectivityNotule[j].collectivity.image;
+ delete(coll[i].collectivityNotule[j].collectivity);
+ }
+ coll[i].collectivity = coll[i].collectivityNotule;
+ delete(coll[i].collectivityNotule);
+ //coll[i].collectivity.email = coll[i].collectivityNotule.email;
+
+ }
+
res.json({info: "ok", success: true, message: coll});
} else {
res.json({success: true, message: "no.nodules"});
}
+
+
+/**
+ * get one notule and its email
+ */
+router.get('/:notuleId/:collectivityId', function(req, res){
+
+ console.log("get one notules");
+
+ var linktable = {
+ collectivity_id : req.params.notuleId,
+ notule_id : req.params.collectivityId,
+ }
+
+ Models.Collectivity_Notule.where(linktable).fetch({withRelated: ['notule']})
+ .then(function (notules){
+ res.json({success : true, message: notules.toJSON()});
+ })
+ .catch(function(err){
+ res.json({success : false, message: err});
+ });
+});
+
+
/*
Models.Collectivity.where('name', /*data.address.city*/ //"ville")
/* .fetch({