if(Number.isNaN(Number(req.body[field]))){returnfield+"=(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"}else{returnfield+"=$"+(i+1)}
}}).join(",")+' where name=$'+(all_filled_fields.length+1)+' returning *',[...all_filled_fields.map((field)=>req.body[field]),req.body["name"]]])*/
awaitdb.query('update '+endpoint.endpoint+' set '+all_filled_fields.map((field,i)=>{
awaitdb.query('update '+endpoint.endpoint+' set '+all_filled_fields.map((field,i)=>{
if(Number.isNaN(Number(req.body[field]))){returnfield+"=(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"}else{returnfield+"=$"+(i+1)}
if(Number.isNaN(Number(req.body[field]))){returnfield+"=(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"}else{returnfield+"=$"+(i+1)}
}}).join(",")+' where name=$'+(all_filled_fields.length+1)+' returning *',[...all_filled_fields.map((field)=>typeofreq.body[field]==='string'?req.body[field].trim():req.body[field]),req.body["name"]])
}}).join(",")+' where name=$'+(all_filled_fields.length+1)+' returning *',[...all_filled_fields.map((field)=>typeofreq.body[field]==='string'?req.body[field].trim():req.body[field]),req.body["name"]])
.then((data)=>{
.then((data)=>{
if(data.rows.length===0){
if(data.rows.length===0){
requiresInsert=true
requiresInsert=true
@ -457,7 +492,7 @@ function CreateDynamicEndpoints() {
db.query('insert into '+endpoint.endpoint+"("+all_filled_fields.join(',')+") values("+all_filled_fields.map((field,i)=>{
db.query('insert into '+endpoint.endpoint+"("+all_filled_fields.join(',')+") values("+all_filled_fields.map((field,i)=>{
if(!field.includes("_id")){return"$"+(i+1)}else{
if(!field.includes("_id")){return"$"+(i+1)}else{
if(Number.isNaN(Number(req.body[field]))){return"(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"}else{return"$"+(i+1)}
if(Number.isNaN(Number(req.body[field]))){return"(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"}else{return"$"+(i+1)}
if(Number.isNaN(Number(req.body[field]))){returnfield+"=(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"}else{returnfield+"=$"+(i+1)}
console.log(field+"=(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")");
}}).join(",")+' where name=$'+(all_filled_fields.length+1)+' returning *',[...all_filled_fields.map((field)=>typeofreq.body[field]==='string'?req.body[field].trim():req.body[field]),req.body["name"]])
returnfield+"=(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"}else{returnfield+"=$"+(i+1)}
}}).join(",")+' where name=$'+(all_filled_fields.length+1)+' returning *',[...all_filled_fields.map((field)=>typeofreq.body[field]==='string'?req.body[field].trim():req.body[field]),req.body["name"]])
.then((data)=>{
.then((data)=>{
if(data.rows.length===0){
if(data.rows.length===0){
requiresInsert=true
requiresInsert=true
@ -506,7 +539,7 @@ function CreateDynamicEndpoints() {
db.query('insert into '+endpoint.endpoint+"("+all_filled_fields.join(',')+") values("+all_filled_fields.map((field,i)=>{
db.query('insert into '+endpoint.endpoint+"("+all_filled_fields.join(',')+") values("+all_filled_fields.map((field,i)=>{
if(!field.includes("_id")){return"$"+(i+1)}else{
if(!field.includes("_id")){return"$"+(i+1)}else{
if(Number.isNaN(Number(req.body[field]))){return"(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"}else{return"$"+(i+1)}
if(Number.isNaN(Number(req.body[field]))){return"(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"}else{return"$"+(i+1)}
returndb.query('update '+endpoint.endpoint+' set '+all_filled_fields.map((field,i)=>field+"=$"+(i+1)).join(",")+" where id=$"+(all_filled_fields.length+1)+" returning *",[...all_filled_fields.map((field)=>req.body[field]),req.body.id])
returndb.query('update '+endpoint.endpoint+' set '+all_filled_fields.map((field,i)=>field+"=$"+(i+1)).join(",")+" where id=$"+(all_filled_fields.length+1)+" returning *",[...all_filled_fields.map((field)=>typeofreq.body[field]==='string'?req.body[field].trim():req.body[field]),req.body.id])
}else{
}else{
varmsg="Could not authenticate!";res.status(500).send(msg);throwmsg
varmsg="Could not authenticate!";res.status(500).send(msg);throwmsg
}
}
@ -626,14 +651,7 @@ function CreateDynamicEndpoints() {
awaitdb2.query('update '+endpoint.endpoint+' set '+all_filled_fields.map((field,i)=>field+"=$"+(i+1)).join(",")+' where name=$'+(all_filled_fields.length+1)+' returning *',[...all_filled_fields.map((field)=>typeofreq.body[field]==='string'?req.body[field].trim():req.body[field]),req.body["name"]])
if(Number.isNaN(Number(req.body[field]))){returnfield+"=(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"}else{returnfield+"=$"+(i+1)}
}}).join(",")+' where name=$'+(all_filled_fields.length+1)+' returning *',[...all_filled_fields.map((field)=>req.body[field]),req.body["name"]]])*/
awaitdb2.query('update '+endpoint.endpoint+' set '+all_filled_fields.map((field,i)=>{
if(Number.isNaN(Number(req.body[field]))){returnfield+"=(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"}else{returnfield+"=$"+(i+1)}
}}).join(",")+' where name=$'+(all_filled_fields.length+1)+' returning *',[...all_filled_fields.map((field)=>typeofreq.body[field]==='string'?req.body[field].trim():req.body[field]),req.body["name"]])
.then((data)=>{
.then((data)=>{
if(data.rows.length===0){
if(data.rows.length===0){
requiresInsert=true
requiresInsert=true
@ -647,59 +665,7 @@ function CreateDynamicEndpoints() {
})
})
}
}
if(requiresInsert){
if(requiresInsert){
db2.query('insert into '+endpoint.endpoint+"("+all_filled_fields.join(',')+") values("+all_filled_fields.map((field,i)=>{
db2.query('insert into '+endpoint.endpoint+"("+all_filled_fields.join(',')+") values("+all_filled_fields.map((field,i)=>"$"+(i+1)).join(",")+") returning *",all_filled_fields.map((field)=>typeofreq.body[field]==='string'?req.body[field].trim():req.body[field]))
if(!field.includes("_id")){return"$"+(i+1)}else{
if(Number.isNaN(Number(req.body[field]))){return"(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"}else{return"$"+(i+1)}
console.log(field+"=(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")");
returnfield+"=(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"}else{returnfield+"=$"+(i+1)}
}}).join(",")+' where name=$'+(all_filled_fields.length+1)+' returning *',[...all_filled_fields.map((field)=>typeofreq.body[field]==='string'?req.body[field].trim():req.body[field]),req.body["name"]])
.then((data)=>{
if(data.rows.length===0){
requiresInsert=true
}else{
requiresInsert=false
res.status(200).json(data.rows)
}
})
.catch((err)=>{
res.status(500).send(err.message)
})
}
if(requiresInsert){
db2.query('insert into '+endpoint.endpoint+"("+all_filled_fields.join(',')+") values("+all_filled_fields.map((field,i)=>{
if(!field.includes("_id")){return"$"+(i+1)}else{
if(Number.isNaN(Number(req.body[field]))){return"(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"}else{return"$"+(i+1)}
returndb2.query('update '+endpoint.endpoint+' set '+all_filled_fields.map((field,i)=>field+"=$"+(i+1)).join(",")+" where id=$"+(all_filled_fields.length+1)+" returning *",[...all_filled_fields.map((field)=>req.body[field]),req.body.id])
returndb2.query('update '+endpoint.endpoint+' set '+all_filled_fields.map((field,i)=>field+"=$"+(i+1)).join(",")+" where id=$"+(all_filled_fields.length+1)+" returning *",[...all_filled_fields.map((field)=>typeofreq.body[field]==='string'?req.body[field].trim():req.body[field]),req.body.id])
}else{
}else{
varmsg="Could not authenticate!";res.status(500).send(msg);throwmsg
varmsg="Could not authenticate!";res.status(500).send(msg);throwmsg
}
}
@ -781,37 +734,144 @@ function CleanUp(arr,vals){
})
})
returnarrVal
returnarrVal
})
})
}
app.get(PREFIX+'/data',async(req,res)=>{
varfinalresult={}
varpromises=[]
for(varendpointofENDPOINTDATA){
if(endpoint.requiredfields.includes("name")){
awaitdb.query('select * from (select distinct on (name) name,* from '+endpoint.endpoint+' order by name,id desc)t order by id asc')
db.query('select * from users where username=$1 and password_hash=$2 limit 1',[req.body.username,sh.SecretHash(req.body.password)])
.then((data)=>{
.then((data)=>{
res.status(200).json(data.rows)
if(data.rows.length>0){
res.status(200).json({verified:true})
}else{
res.status(200).json({verified:false})
}
})
})
.catch((err)=>{
.catch((err)=>{
res.status(500).send(err.message)
res.status(500).send(err.message)
})
})
})
})
app.post("/updateItem",(req,res)=>{
app.post(PREFIX+"/saveskilltree",(req,res)=>{
db.query("update crafting_list set obtained=$1 where id=$2",[req.body.obtained,req.body.id])
db4.query('select * from password where password=$1',[req.body.pass])
.then((data)=>{
if(data.rows.length>0){
returndb.query('select * from skill_tree_data where class_id=$1 limit 1',[req.body.class_id])
}else{
varmsg="Could not authenticate!";res.status(500).send(msg);throwmsg
}
})
.then((data)=>{
.then((data)=>{
returndb.query("update site_data set last_modified=$1",[req.body.last_modified])
if(data.rows.length>0){
returndb.query('update skill_tree_data set data=$1,skill_data=$2,line_color=$3,line_width=$4,gridsizex=$5,gridsizey=$6,gridpaddingx=$7,gridpaddingy=$8,halflineheight=$9 where class_id=$10',
returndb.query('insert into skill_tree_data(data,skill_data,line_color,line_width,gridsizex,gridsizey,gridpaddingx,gridpaddingy,class_id,halflineheight) values($1,$2,$3,$4,$5,$6,$7,$8,$10,$9)',
db.query('insert into crafting_list(itemid,name,obtained,required,icon) values($1,$2,$3,$4,$5)',[req.body.itemid,req.body.name,req.body.obtained,req.body.required,req.body.icon])
db4.query('select * from password where password=$1',[req.body.pass])
.then((data)=>{
.then((data)=>{
res.status(200).send("Yay!")
if(data.rows.length>0){
returndb2.query('select * from skill_tree_data where class_id=$1 limit 1',[req.body.class_id])
}else{
varmsg="Could not authenticate!";res.status(500).send(msg);throwmsg
}
})
.then((data)=>{
if(data.rows.length>0){
returndb2.query('update skill_tree_data set data=$1,skill_data=$2,line_color=$3,line_width=$4,gridsizex=$5,gridsizey=$6,gridpaddingx=$7,gridpaddingy=$8,halflineheight=$9 where class_id=$10',
returndb2.query('insert into skill_tree_data(data,skill_data,line_color,line_width,gridsizex,gridsizey,gridpaddingx,gridpaddingy,class_id,halflineheight) values($1,$2,$3,$4,$5,$6,$7,$8,$10,$9)',