Include new database management endpoints

dependabot/npm_and_yarn/server/chart.js-node-ssr-example/path-parse-1.0.7
sigonasr2, Sig, Sigo 3 years ago
parent 847def6d39
commit 677857ae43
  1. 788
      server/app.js

@ -36,229 +36,571 @@ let allowCrossDomain = function(req, res, next) {
} }
app.use(allowCrossDomain); app.use(allowCrossDomain);
const db = var db =
new Pool({ new Pool({
user: 'postgres', user: 'postgres',
password: '', password: '',
host: 'postgres', host: 'postgres',
database: 'divar', database: 'ngsplanner',
port: 5432, port: 5432,
}) })
const db2 = var db2 =
new Pool({ new Pool({
user: 'postgres', user: 'postgres',
password: '', password: '',
host: 'postgres', host: 'postgres',
database: 'ngsplanner2', database: 'ngsplanner2',
port: 5432, port: 5432,
}) })
const ENDPOINTDATA=[ var db3 =
{ new Pool({
endpoint:"class", user: 'postgres',
requiredfields:["name"], password: '',
optionalfields:["icon"], host: 'postgres',
excludedfields:[] //Fields to not output in GET. database: '',
}, port: 5432,
{ })
endpoint:"class_level_data",
requiredfields:["class_id","level","hp","atk","def","name"], const PREFIX="/ngsplanner"
optionalfields:[],
excludedfields:[] //Fields to not output in GET. const ENDPOINTDATA=[
}, {
{ endpoint:"class",
endpoint:"class_weapon_type_data", requiredfields:["name"],
requiredfields:["class_id","weapon_type_id"], optionalfields:["icon"],
optionalfields:[], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"class_level_data",
endpoint:"weapon", requiredfields:["class_id","level","hp","atk","def","name"],
requiredfields:["name","rarity","level_req","atk"], optionalfields:[],
optionalfields:["potential_id","variance","base_affix_slots","drop_info","pb_gauge_build","icon"], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"class_weapon_type_data",
endpoint:"weapon_existence_data", requiredfields:["class_id","weapon_type_id"],
requiredfields:["weapon_type_id","weapon_id"], optionalfields:[],
optionalfields:["popularity","editors_choice"], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"weapon",
endpoint:"weapon_type", requiredfields:["name","rarity","level_req","atk"],
requiredfields:["name","dmg_type"], optionalfields:["potential_id","variance","base_affix_slots","drop_info","pb_gauge_build","icon"],
optionalfields:["icon"], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"weapon_existence_data",
endpoint:"armor", requiredfields:["weapon_type_id","weapon_id"],
requiredfields:["name","rarity","level_req","def"], optionalfields:["popularity","editors_choice"],
optionalfields:["hp","pp","mel_dmg","rng_dmg","tec_dmg","crit_rate","crit_dmg","pp_cost_reduction","active_pp_recovery","natural_pp_recovery","dmg_res","all_down_res","burn_res","freeze_res","blind_res","shock_res","panic_res","poison_res","battle_power_value","pb_gauge_build","icon","popularity","editors_choice"], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"weapon_type",
endpoint:"potential", requiredfields:["name","dmg_type"],
requiredfields:["name"], optionalfields:["icon"],
optionalfields:["icon"], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"photon_art",
endpoint:"potential_data", requiredfields:["name","weapon_type_id","potency","dps"],
requiredfields:["potential_id","level","name"], optionalfields:["power_distribution","pp","frames"],
optionalfields:["mel_dmg","rng_dmg","tec_dmg","crit_rate","crit_dmg","pp_cost_reduction","active_pp_recovery","natural_pp_recovery","dmg_res","all_down_res","burn_res","freeze_res","blind_res","shock_res","panic_res","poison_res","battle_power_value","pb_gauge_build"], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"armor",
endpoint:"builds", requiredfields:["name","rarity","level_req","def"],
requiredfields:["users_id","creator","build_name","class1","created_on","last_modified","data"], optionalfields:["hp","pp","mel_dmg","rng_dmg","tec_dmg","crit_rate","crit_dmg","pp_cost_reduction","active_pp_recovery","natural_pp_recovery","dmg_res","all_down_res","burn_res","freeze_res","blind_res","shock_res","panic_res","poison_res","battle_power_value","pb_gauge_build","icon","popularity","editors_choice"],
optionalfields:["class2","likes","editors_choice"], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"potential",
endpoint:"skill", requiredfields:["name"],
requiredfields:["name","skill_type_id"], optionalfields:["icon"],
optionalfields:["icon"], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"potential_data",
endpoint:"skill_type", requiredfields:["potential_id","level","name"],
requiredfields:["name"], optionalfields:["mel_dmg","rng_dmg","tec_dmg","crit_rate","crit_dmg","pp_cost_reduction","active_pp_recovery","natural_pp_recovery","dmg_res","all_down_res","burn_res","freeze_res","blind_res","shock_res","panic_res","poison_res","battle_power_value","pb_gauge_build"],
optionalfields:[], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"builds",
endpoint:"skill_data", requiredfields:["users_id","creator","build_name","class1","created_on","last_modified","data"],
requiredfields:["skill_id","level","name"], optionalfields:["class2","likes","editors_choice"],
optionalfields:["variance","mel_dmg","rng_dmg","tec_dmg","crit_rate","crit_dmg","pp_cost_reduction","active_pp_recovery","natural_pp_recovery","dmg_res","popularity","editors_choice"], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"skill",
endpoint:"augment", requiredfields:["name","skill_type_id"],
requiredfields:["augment_type_id","name"], optionalfields:["icon"],
optionalfields:["variance","hp","pp","mel_dmg","rng_dmg","tec_dmg","crit_rate","crit_dmg","pp_cost_reduction","active_pp_recovery","natural_pp_recovery","dmg_res","affix_success_rate","all_down_res","burn_res","freeze_res","blind_res","shock_res","panic_res","poison_res","battle_power_value","pb_gauge_build","popularity","editors_choice"], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"skill_type",
endpoint:"augment_type", requiredfields:["name"],
requiredfields:["name"], optionalfields:[],
optionalfields:["icon"], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"skill_data",
endpoint:"food", requiredfields:["skill_id","level","name"],
requiredfields:["name"], optionalfields:["variance","mel_dmg","rng_dmg","tec_dmg","crit_rate","crit_dmg","pp_cost_reduction","active_pp_recovery","natural_pp_recovery","dmg_res","popularity","editors_choice"],
optionalfields:["potency","pp","dmg_res","hp","pp_consumption","pp_recovery","weak_point_dmg","hp_recovery","popularity","editors_choice"], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"class_skill",
endpoint:"food_mult", requiredfields:["name","class_id"],
requiredfields:["amount"], optionalfields:["icon","description"],
optionalfields:["potency","pp","dmg_res","hp","pp_consumption","pp_recovery","weak_point_dmg","hp_recovery"], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"class_skill_data",
endpoint:"roles", requiredfields:["name","class_skill_id","level"],
requiredfields:["name"], optionalfields:["dependency","effect","duration","cooldown","damage_taken","pa_potency","conditional_buff","pp_recovery","property","all_damage_buff","active_pp_recovery","status_ailment_accum","status_ailment_duration","pp_consumption","max_hp_decrease","natural_pp_recovery","added_pp","pb_gauge_fortification"],
optionalfields:[], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
}, {
{ endpoint:"augment",
endpoint:"users", requiredfields:["augment_type_id","name"],
requiredfields:["username","email","created_on","roles_id"], optionalfields:["variance","hp","pp","mel_dmg","rng_dmg","tec_dmg","crit_rate","crit_dmg","pp_cost_reduction","active_pp_recovery","natural_pp_recovery","dmg_res","affix_success_rate","all_down_res","burn_res","freeze_res","blind_res","shock_res","panic_res","poison_res","battle_power_value","pb_gauge_build","popularity","editors_choice"],
optionalfields:["avatar","editors_choice"], excludedfields:[] //Fields to not output in GET.
excludedfields:["password_hash"] //Fields to not output in GET. },
}, {
{ endpoint:"augment_type",
endpoint:"database_audit", requiredfields:["name"],
requiredfields:["action","table_name","row_name","row_id","new_value","date","users_id"], optionalfields:["icon"],
optionalfields:["old_value"], excludedfields:[] //Fields to not output in GET.
excludedfields:[] //Fields to not output in GET. },
} {
] endpoint:"enemy_data",
requiredfields:["level","def","atk"],
function CreateDynamicEndpoints() { optionalfields:[],
ENDPOINTDATA.map((endpoint)=>{ excludedfields:[] //Fields to not output in GET.
app.get("/ngsplanner/"+endpoint.endpoint,(req,res)=>{ },
if (endpoint.requiredfields.includes("name")) { {
db2.query('select distinct on (name) name,* from '+endpoint.endpoint+' order by name,id desc') endpoint:"food",
.then((data)=>{ requiredfields:["name"],
res.status(200).json({fields:data.fields,rows:data.rows}) optionalfields:["potency","pp","dmg_res","hp","pp_consumption","pp_recovery","weak_point_dmg","hp_recovery","popularity","editors_choice"],
}) excludedfields:[] //Fields to not output in GET.
.catch((err)=>{ },
res.status(500).send(err.message) {
}) endpoint:"food_mult",
} else { requiredfields:["amount"],
db2.query('select * from '+endpoint.endpoint+" order by id desc") optionalfields:["potency","pp","dmg_res","hp","pp_consumption","pp_recovery","weak_point_dmg","hp_recovery"],
.then((data)=>{ excludedfields:[] //Fields to not output in GET.
res.status(200).json({fields:data.fields,rows:data.rows}) },
}) {
.catch((err)=>{ endpoint:"roles",
res.status(500).send(err.message) requiredfields:["name"],
}) optionalfields:[],
} excludedfields:[] //Fields to not output in GET.
}) },
{
endpoint:"users",
app.post("/ngsplanner/"+endpoint.endpoint,(req,res)=>{ requiredfields:["username","email","created_on","roles_id"],
optionalfields:["avatar","editors_choice"],
var allExist=true excludedfields:["password_hash"] //Fields to not output in GET.
endpoint.requiredfields.forEach((field)=>{ },
if (!(field in req.body)) { {
allExist=false; endpoint:"database_audit",
} requiredfields:["action","table_name","row_name","row_id","new_value","date","users_id"],
}) optionalfields:["old_value"],
if (!allExist) { excludedfields:[] //Fields to not output in GET.
res.status(300).send("Required fields are: "+endpoint.requiredfields.filter((field)=>!(field in req.body)).join(',')) }
return ]
}
app.get(PREFIX+"/databases",(req,res)=>{
var combinedfields = [...endpoint.requiredfields,...endpoint.optionalfields,...endpoint.excludedfields] db.query('select * from pg_database where datname like \'ngsplanner%\' order by datname desc limit 100')
//console.log(combinedfields) .then((data)=>{
var all_filled_fields=combinedfields.filter((field)=>(field in req.body)) res.status(200).json(data.rows)
})
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)=>req.body[field])) .catch((err)=>{
.then((data)=>{ res.status(500).send(err.message)
res.status(200).json(data.rows) })
}) })
.catch((err)=>{
res.status(500).send(err.message) app.post(PREFIX+"/databases/restorefrombackup",(req,res)=>{
}) if (req.body.database) {
}) db3.query('select * from pg_database where datname=$1',[req.body.database])
.then((data)=>{
app.patch("/ngsplanner/"+endpoint.endpoint,(req,res)=>{ if (data.rows.length>0) {
if (req.body.id) { db.end(()=>{})
var combinedfields = [...endpoint.requiredfields,...endpoint.optionalfields,...endpoint.excludedfields] return db3.query('select pg_terminate_backend (pid) from pg_stat_activity where pg_stat_activity.datname=\'ngsplanner\'')
//console.log(combinedfields) } else {
var all_filled_fields=combinedfields.filter((field)=>(field in req.body)) throw "Could not find requested database "+req.body.database
}
db2.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]) })
.then((data)=>{ .then(()=>{
res.status(200).json(data.rows) return db3.query('drop database ngsplanner')
}) })
.catch((err)=>{ .then(()=>{
res.status(500).send(err.message) return db3.query('create database ngsplanner with template '+req.body.database)
}) })
} else { .then(()=>{
res.status(300).send("Invalid query!") db = new Pool({
} user: 'postgres',
}) password: '',
host: 'postgres',
app.delete("/ngsplanner/"+endpoint.endpoint,(req,res)=>{ database: 'ngsplanner',
if (req.body.id) { port: 5432,
db2.query('delete from '+endpoint.endpoint+' where id=$1 returning *',[req.body.id]) })
.then((data)=>{ res.status(200).send("Done!")
res.status(200).json(data.rows) })
}) .catch((err)=>{
.catch((err)=>{ console.log(err.message)
res.status(500).send(err.message) res.status(500).send(err.message)
}) })
} else { } else {
res.status(300).send("Invalid query!") res.status(500).send("Invalid data!")
} }
}) })
})
} app.post(PREFIX+"/databases/testtolive",(req,res)=>{
db.end(()=>{})
db2.end(()=>{})
db3.query('select pg_terminate_backend (pid) from pg_stat_activity where pg_stat_activity.datname=\'ngsplanner\' or pg_stat_activity.datname=\'ngsplanner2\'')
.then(()=>{
return db3.query('drop database ngsplanner')
})
.then(()=>{
return db3.query('create database ngsplanner with template ngsplanner2')
})
.then(()=>{
db = new Pool({
user: 'postgres',
password: '',
host: 'postgres',
database: 'ngsplanner',
port: 5432,
})
db2 = new Pool({
user: 'postgres',
password: '',
host: 'postgres',
database: 'ngsplanner2',
port: 5432,
})
res.status(200).send("Done!")
})
.catch((err)=>{
console.log(err.message)
res.status(500).send(err.message)
})
})
app.post(PREFIX+"/databases/livetotest",(req,res)=>{
db.end(()=>{})
db2.end(()=>{})
db3.query('select pg_terminate_backend (pid) from pg_stat_activity where pg_stat_activity.datname=\'ngsplanner\' or pg_stat_activity.datname=\'ngsplanner2\'')
.then(()=>{
return db3.query('drop database ngsplanner2')
})
.then(()=>{
return db3.query('create database ngsplanner2 with template ngsplanner')
})
.then(()=>{
db = new Pool({
user: 'postgres',
password: '',
host: 'postgres',
database: 'ngsplanner',
port: 5432,
})
db2 = new Pool({
user: 'postgres',
password: '',
host: 'postgres',
database: 'ngsplanner2',
port: 5432,
})
res.status(200).send("Done!")
})
.catch((err)=>{
res.status(500).send(err.message)
})
})
app.post(PREFIX+"/databases/backup",(req,res)=>{
db.end(()=>{})
var date = new Date()
db3.query('select pg_terminate_backend (pid) from pg_stat_activity where pg_stat_activity.datname=\'ngsplanner\'')
.then(()=>{
return db3.query('create database ngsplanner'+String(date.getFullYear()).padStart(4,'0')+String(date.getMonth()).padStart(2,'0')+String(date.getDate()).padStart(2,'0')+String(date.getHours()).padStart(2,'0')+String(date.getMinutes()).padStart(2,'0')+String(date.getSeconds()).padStart(2,'0')+' with template ngsplanner')
})
.then(()=>{
db = new Pool({
user: 'postgres',
password: '',
host: 'postgres',
database: 'ngsplanner',
port: 5432,
})
res.status(200).send("Done!")
})
.catch((err)=>{
res.status(500).send(err.message)
})
})
function CreateDynamicEndpoints() {
ENDPOINTDATA.forEach((endpoint)=>{
app.get(PREFIX+"/"+endpoint.endpoint,(req,res)=>{
if (endpoint.requiredfields.includes("name")) {
db.query('select distinct on (name) name,* from '+endpoint.endpoint+' order by name,id desc')
.then((data)=>{
res.status(200).json({fields:data.fields,rows:data.rows})
})
.catch((err)=>{
res.status(500).send(err.message)
})
} else {
db.query('select * from '+endpoint.endpoint+" order by id desc")
.then((data)=>{
res.status(200).json({fields:data.fields,rows:data.rows})
})
.catch((err)=>{
res.status(500).send(err.message)
})
}
})
app.post(PREFIX+"/"+endpoint.endpoint,async(req,res)=>{
var allExist=true
endpoint.requiredfields.forEach((field)=>{
if (!(field in req.body)) {
allExist=false;
}
})
if (!allExist) {
res.status(300).send("Required fields are: "+endpoint.requiredfields.filter((field)=>!(field in req.body)).join(','))
return
}
var combinedfields = [...endpoint.requiredfields,...endpoint.optionalfields,...endpoint.excludedfields]
//console.log(combinedfields)
var all_filled_fields=combinedfields.filter((field)=>(field in req.body))
var requiresInsert=true
if (endpoint.requiredfields.includes("name")) {
await db.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)=>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) {
db.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)=>req.body[field]))
.then((data)=>{
res.status(200).json(data.rows)
})
.catch((err)=>{
res.status(500).send(err.message)
})
}
})
app.patch(PREFIX+"/"+endpoint.endpoint,(req,res)=>{
if (req.body.id) {
var combinedfields = [...endpoint.requiredfields,...endpoint.optionalfields,...endpoint.excludedfields]
//console.log(combinedfields)
var all_filled_fields=combinedfields.filter((field)=>(field in req.body))
db.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])
.then((data)=>{
res.status(200).json(data.rows)
})
.catch((err)=>{
res.status(500).send(err.message)
})
} else {
res.status(300).send("Invalid query!")
}
})
app.delete(PREFIX+"/"+endpoint.endpoint,(req,res)=>{
if (req.body.id) {
db.query('delete from '+endpoint.endpoint+' where id=$1 returning *',[req.body.id])
.then((data)=>{
res.status(200).json(data.rows)
})
.catch((err)=>{
res.status(500).send(err.message)
})
} else {
res.status(300).send("Invalid query!")
}
})
app.get(PREFIX+"/test/"+endpoint.endpoint,(req,res)=>{
if (endpoint.requiredfields.includes("name")) {
db2.query('select distinct on (name) name,* from '+endpoint.endpoint+' order by name,id desc')
.then((data)=>{
res.status(200).json({fields:data.fields,rows:data.rows})
})
.catch((err)=>{
res.status(500).send(err.message)
})
} else {
db2.query('select * from '+endpoint.endpoint+" order by id desc")
.then((data)=>{
res.status(200).json({fields:data.fields,rows:data.rows})
})
.catch((err)=>{
res.status(500).send(err.message)
})
}
})
app.post(PREFIX+"/test/"+endpoint.endpoint,(req,res)=>{
var allExist=true
endpoint.requiredfields.forEach((field)=>{
if (!(field in req.body)) {
allExist=false;
}
})
if (!allExist) {
res.status(300).send("Required fields are: "+endpoint.requiredfields.filter((field)=>!(field in req.body)).join(','))
return
}
var combinedfields = [...endpoint.requiredfields,...endpoint.optionalfields,...endpoint.excludedfields]
//console.log(combinedfields)
var all_filled_fields=combinedfields.filter((field)=>(field in req.body))
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)=>req.body[field]))
.then((data)=>{
res.status(200).json(data.rows)
})
.catch((err)=>{
res.status(500).send(err.message)
})
})
app.patch(PREFIX+"/test/"+endpoint.endpoint,(req,res)=>{
if (req.body.id) {
var combinedfields = [...endpoint.requiredfields,...endpoint.optionalfields,...endpoint.excludedfields]
//console.log(combinedfields)
var all_filled_fields=combinedfields.filter((field)=>(field in req.body))
db2.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])
.then((data)=>{
res.status(200).json(data.rows)
})
.catch((err)=>{
res.status(500).send(err.message)
})
} else {
res.status(300).send("Invalid query!")
}
})
app.delete(PREFIX+"/test/"+endpoint.endpoint,(req,res)=>{
if (req.body.id) {
db2.query('delete from '+endpoint.endpoint+' where id=$1 returning *',[req.body.id])
.then((data)=>{
res.status(200).json(data.rows)
})
.catch((err)=>{
res.status(500).send(err.message)
})
} else {
res.status(300).send("Invalid query!")
}
})
})
}
function CleanUp(arr,vals){
return arr.map((arrVal)=>{
vals.forEach((val)=>{
arrVal[val]=undefined
})
return arrVal
})
}
app.get(PREFIX+'/data',async(req,res)=>{
var finalresult = {}
var promises = []
for (var endpoint of ENDPOINTDATA) {
if (endpoint.requiredfields.includes("name")) {
await db.query('select * from (select distinct on (name) name,* from '+endpoint.endpoint+' order by name,id desc)t order by id asc')
.then((data)=>{
finalresult[endpoint.endpoint]={}
data.rows.forEach((val)=>{finalresult[endpoint.endpoint][val.name]=val})
})
} else {
await db.query('select * from '+endpoint.endpoint+" order by id desc")
.then((data)=>{
finalresult[endpoint.endpoint]=data.rows
})
}
}
res.status(200).json(finalresult)
})
app.get(PREFIX+'/test/data',async(req,res)=>{
var finalresult = {}
var promises = []
for (var endpoint of ENDPOINTDATA) {
if (endpoint.requiredfields.includes("name")) {
await db2.query('select distinct on (name) name,* from '+endpoint.endpoint+' order by name,id desc')
.then((data)=>{
finalresult[endpoint.endpoint]={}
data.rows.forEach((val)=>{finalresult[endpoint.endpoint][val.name]=val})
})
} else {
await db2.query('select * from '+endpoint.endpoint+" order by id desc")
.then((data)=>{
finalresult[endpoint.endpoint]=data.rows
})
}
}
res.status(200).json(finalresult)
})
app.get(PREFIX+'/dataid',async(req,res)=>{
var finalresult = {}
var promises = []
for (var endpoint of ENDPOINTDATA) {
await db.query('select * from '+endpoint.endpoint+' order by id asc')
.then((data)=>{
finalresult[endpoint.endpoint]={}
data.rows.forEach((val)=>{finalresult[endpoint.endpoint][val.id]=val})
})
}
res.status(200).json(finalresult)
})
app.get(PREFIX+'/test/dataid',async(req,res)=>{
var finalresult = {}
var promises = []
for (var endpoint of ENDPOINTDATA) {
await db2.query('select * from '+endpoint.endpoint+' order by id asc')
.then((data)=>{
finalresult[endpoint.endpoint]={}
data.rows.forEach((val)=>{finalresult[endpoint.endpoint][val.id]=val})
})
}
res.status(200).json(finalresult)
})
//Generates our table schema:
ENDPOINTDATA.forEach((endpoint)=>{
console.log(endpoint.endpoint+":\n\t"+endpoint.requiredfields.join('\t')+(endpoint.optionalfields.length>0?"\t":"")+endpoint.optionalfields.join("\t"))
})
/*const db2 = /*const db2 =
new Pool({ new Pool({

Loading…
Cancel
Save