getUserProjects:function(id, callback){
var self = this,
mysql = self.mysql,
db = self.db,
qr = "SELECT id, project_name, elem_markids FROM projects WHERE user_id = ? and showstatus = 0",
arr = [id];
db.query(qr,arr,function(err, result){
if(err){
console.log("Can't make request: " + err);
callback("query_error",undefined); //Сразу смотреть в логи.
}
/* С этого места */
var res = [];
for(var i=0;result.length > i;i++){
var rs = result[i];
self.getProjectsSheets(rs.id,function(err,val){
rs.sheets = val;
});
res.push(rs);
}
callback(null,res);
/* По это */
});
},
getProjectsSheets:function( id,callback ){
var self = this,
mysql = self.mysql,
db = self.db,
qr = "SELECT id, project_id ,sheet_name,label,current FROM sheets WHERE project_id = ? and showstatus = 0",
arr = [id];
db.query(qr,arr,function(err, result){
if(err){
console.log("Can't make request: " + err);
}
callback(null,result)
})
}
getUserProjects:function(id,callback){
var self = this,
mysql = self.mysql,
db = self.db,
qr = "SELECT id, project_name, elem_markids FROM projects WHERE user_id = ? and showstatus = 0",
arr = [id];
var def = Q.defer();
db.query(qr,arr,function(err, result){
var res = [];
if(err){
console.log("Can't make request: " + err);
if(callback) {
callback("query_error", undefined); //Сразу смотреть в логи.
}
}
for(var i = 0; result.length > i;i++){
var rs = result[i];
var qr = "SELECT id, project_id ,sheet_name,label,current FROM sheets WHERE project_id = ? and showstatus = 0",
arr = [rs.id];
db.query(qr,arr,function(err, result){
if(err){
console.log("Can't make request: " + err);
}
def.resolve([rs,result]);
});
res.push(def.promise);
}
Q.all(res).spread(function(){
var res = [];
for(var key in arguments){
var prom = arguments[key];
var proj = prom[0],sheets = prom[1];
proj.sheets = sheets;
res.push(proj);
}
callback(null,res);
});
});
},