UNPKG

ernest

Version:

Web framework for HTTP and HTTPS, using ExpressJS, Session, Mongo, Socket IO, Redis

496 lines (466 loc) 9.18 kB
class AutoServerResponse { constructor(app,dbc,msg,ern) { this.app = app; this.dbc = dbc; this.msg = msg; this.ern = ern; this.nec = {}; this.nec['Insert'] = "Insert"; this.nec['InsertBy'] = "InsertBy"; this.nec['FindOne'] = "FindOne"; this.nec['Find'] = "Find"; this.nec['FindProyect'] = "FindProyect"; this.nec['FindOneShow'] = "FindOneShow"; this.nec['FindShow'] = "FindShow"; this.nec['Update'] = "Update"; this.nec['UpdateBy'] = "UpdateBy"; this.nec['UpdateMany'] = "UpdateMany"; this.nec['DeleteFrom'] = "DeleteFrom"; this.nec['FindSortLim'] = "FindSortLim"; this.nec['FindSort'] = "FindSort"; this.nec['Aggregate'] = "Aggregate"; this.nec['Distincts'] = "Distincts"; this.nec['Names'] = "Names"; this.nec['Exist'] = "Exist"; this.nec['Rename'] = "Rename"; this.nec['Create'] = "Create"; this.nec['Drop'] = "Drop"; this.nec['Empty'] = "Empty"; this.nec['Erase'] = "Erase"; this.nec['Clone'] = "Clone"; }; RewriteCommand(native,custom) { this.nec[native] = custom; return this; }; Enable(icommreq) { var commreq = "/~edbc"; if(icommreq !== undefined) { if(icommreq != null) { if(icommreq != "") { commreq = icommreq; }; }; }; var _this = this; this.app.post(commreq,function(req,res,next) { var com = req.body.command; var col = req.body.collec; if((com !== undefined)&&(col !== undefined)) { _this.Selector(com,col,req,res,next); } else { next(); } }); }; Selector(com,collec,req,res,next) { var _this = this; switch(com) { case _this.nec['Insert']: this.Insert(collec,req,res,next); break; case _this.nec['InsertBy']: this.InsertBy(collec,req,res,next); break; case _this.nec['FindOne']: this.FindOne(collec,req,res,next); break; case _this.nec['Find']: this.Find(collec,req,res,next); break; case _this.nec['FindProyect']: this.FindProyect(collec,req,res,next); break; case _this.nec['FindOneShow']: this.FindOneShow(collec,req,res,next); break; case _this.nec['FindShow']: this.FindShow(collec,req,res,next); break; case _this.nec['Update']: this.Update(collec,req,res,next); break; case _this.nec['UpdateBy']: this.UpdateBy(collec,req,res,next); break; case _this.nec['UpdateMany']: this.UpdateMany(collec,req,res,next); break; case _this.nec['DeleteFrom']: this.DeleteFrom(collec,req,res,next); break; case _this.nec['FindSortLim']: this.FindSortLim(collec,req,res,next); break; case _this.nec['FindSort']: this.FindSort(collec,req,res,next); break; case _this.nec['Aggregate']: this.Aggregate(collec,req,res,next); break; case _this.nec['Distincts']: this.Distincts(collec,req,res,next); break; case _this.nec['Names']: this.Names(req,res,next); break; case _this.nec['Exist']: this.Exist(collec,req,res,next); break; case _this.nec['Rename']: this.Rename(collec,req,res,next); break; case _this.nec['Create']: this.Create(collec,req,res,next); break; case _this.nec['Drop']: this.Drop(collec,req,res,next); break; case _this.nec['Empty']: this.Empty(collec,req,res,next); break; case _this.nec['Erase']: this.Erase(collec,req,res,next); break; case _this.nec['Clone']: this.Clone(collec,req,res,next); break; default: next(); break; }; }; Insert(collec,req,res,next) { let data = req.body.data; if(data !==undefined) { this.dbc.InsertInCollection(data,collec,function(e,r) { res.json({error:e,data:d}); }) ; } else { res.json(null); } }; InsertBy(collec,req,res,next) { let data = req.body.data; let insertedBy = req.session.user; if(data !==undefined) { this.dbc.InsertInCollectionBy(data,collec,insertedBy,function(e,d) { res.json({error: e, data:d}); }); } else { res.json(null); } }; FindOne(collec,req,res,next) { let crit = req.body.crit; if(crit !==undefined) { this.dbc.FindOneInCollection(crit,collec,function(e,d) { res.json({error:e,data:d}); }); } else { res.json(null); } }; Find(collec,req,res,next) { let crit = req.body.crit; if(crit !==undefined) { this.dbc.FindInCollection(crit,collec,function(e,d) { res.json({error:e,data:d}); }); } else { res.json(null); } }; FindProyect(collec,req,res,next) { let crit = req.body.crit; let proy = req.body.proy; if((crit !==undefined)&&(proy !== undefined)) { this.dbc.FindProyectInCollection(crit,proy,collec,function(e,d) { res.json({error:e, data:d}); }); } else { res.json(null); } }; FindOneShow(collec,req,res,next) { let crit = req.body.crit; let show = req.body.show; if((crit !==undefined)&&(show !== undefined)) { this.dbc.FindOneInCollShow(crit,show,collec,function(e,doc) { res.json({error:e,data:doc}); }); } else { res.json(null); } }; FindShow(collec,req,res,next) { let crit = req.body.crit; let show = req.body.show; if((crit !==undefined)&&(show !== undefined)) { this.dbc.FindInCollecShow(crit,show,collec,function(e,d) { res.json({error:e,data:d}); }); } else { res.json(null); } }; Update(collec,req,res,next) { let crit = req.body.crit; let set = req.body.set; if((crit !==undefined)&&(set !== undefined)) { this.dbc.UpdateOneinCollec(crit,set,collec,function(e,d) { res.json({error:e, data:d}); }); } else { res.json(null); } }; UpdateBy(collec,req,res,next) { let crit = req.body.crit; let set = req.body.set; let changedBy = req.session.user; if((crit !==undefined)&&(set !== undefined)) { this.dbc.UpdateOneinCollecBy(crit,set,collec,changedBy,function(e,d) { res.json({error:e, data:d}); }); } else { res.json(null); } }; UpdateMany(collec,req,res,next) { let crit = req.body.crit; let set = req.body.set; if((crit !==undefined)&&(set !== undefined)) { this.dbc.UpdateManyinCollec(crit,set,collec,function(e,d) { res.json({error:e,data:d}); }); } else { res.json(null); } }; DeleteFrom(collec,req,res,next) { let crit = req.body.crit; if((crit !==undefined)) { this.dbc.DeleteFromCollection(crit,collec,function(e,r) { res.json({error:e,data:d}); }); } else { res.json(null); } }; FindSortLim(collec,req,res,next) { let crit = req.body.crit; let order = req.body.order; let lim = req.body.lim; if((crit !==undefined)&&(order !== undefined)&&(lim!==undefined)) { this.dbc.FindSortLimInCollect(crit,order,lim,collec,function(e,d) { res.json({error:e,data:d}); }); } else { res.json(null); } }; FindSort(collec,req,res,next) { let crit = req.body.crit; let order = req.body.order; if((crit !==undefined)&&(order !== undefined)) { this.dbc.FindSortInCollection(crit,order,collec,function(e,d) { res.json({error:e,data:d}); }); } else { res.json(null); } }; Aggregate(collec,req,res,next) { let agg_arry = req.body.aggr; if((agg_arry !==undefined)) { this.dbc.AggregatetoArray(agg_arry,collec,function(e,d) { res.json({error:e,data:d}); }) ; } else { res.json(null); } }; Distincts(collec,req,res,next) { let crit = req.body.crit; let query = req.body.query; if((crit !==undefined)&&(query !== undefined)) { this.dbc.GetDistincts(crit,query,collec,function(e,d) { res.json({error:e,data:d}); }); } else { res.json(null); } }; Names(req,res,next) { this.dbc.getCollectionNames(function(e,d) { res.json({error:e,data:d}); }); }; Exist(collec,req,res,next) { this.dbc.CollectionExist(collec,function(e,d) { res.json({error:e,data:d}); }) ; }; Rename(collec,req,res,next) { let oldcollec = collec; let newcollec = req.body.newcollec; if((newcollec !==undefined)) { this.dbc.RenameCollection(oldcollec,newcollec,function(e,d) { res.json({error:e,data:d}); }); } else { res.json(null); } }; Create(collec,req,res,next) { this.dbc.CreateCollection(collec,function(e,d) { res.json({error:e,data:d}); }); }; Drop(collec,req,res,next) { this.dbc.DropCollection(collec,function(e,d) { res.json({error:e,data:d}); }); }; Empty(collec,req,res,next) { this.dbc.EmptyCollection(collec,function(e,d) { res.json({error:e,data:d}); }); }; Erase(collec,req,res,next) { let erase = req.body.beginwith; if((erase !==undefined)) { this.dbc.EraseCollections(erase,function(e,d) { res.json({error:e,data:d}); }); } else { res.json(null); } }; Clone(collec,req,res,next) { let src = collec; let dst = req.body.newcollec; if((dst !==undefined)) { this.dbc.CloneCollection(src,dst,function(e,d) { res.json({error:e,data:d}); }); } else { res.json(null); } }; }; module.exports = AutoServerResponse