Added POST dynamic endpoint

pull/1/head
sigonasr2 3 years ago
parent 3698772318
commit ce8bf448a1
  1. 5
      ngsplanner_schema.sql
  2. 94
      server.js

@ -31,11 +31,13 @@ CREATE TABLE "class" (
); );
CREATE TABLE "class_weapon_type_data" ( CREATE TABLE "class_weapon_type_data" (
"id" SERIAL UNIQUE PRIMARY KEY,
"class_id" int, "class_id" int,
"weapon_type_id" int "weapon_type_id" int
); );
CREATE TABLE "class_level_data" ( CREATE TABLE "class_level_data" (
"id" SERIAL UNIQUE PRIMARY KEY,
"class_id" int, "class_id" int,
"level" int, "level" int,
"hp" int, "hp" int,
@ -70,6 +72,7 @@ CREATE TABLE "potential" (
); );
CREATE TABLE "potential_data" ( CREATE TABLE "potential_data" (
"id" SERIAL UNIQUE PRIMARY KEY,
"potential_id" int, "potential_id" int,
"level" int, "level" int,
"mel_dmg" float, "mel_dmg" float,
@ -157,6 +160,7 @@ CREATE TABLE "skill" (
); );
CREATE TABLE "skill_data" ( CREATE TABLE "skill_data" (
"id" SERIAL UNIQUE PRIMARY KEY,
"skill_id" int, "skill_id" int,
"level" int, "level" int,
"variance" float, "variance" float,
@ -205,6 +209,7 @@ CREATE TABLE "builds" (
); );
CREATE TABLE "weapon_existence_data" ( CREATE TABLE "weapon_existence_data" (
"id" SERIAL UNIQUE PRIMARY KEY,
"weapon_type_id" int, "weapon_type_id" int,
"weapon_id" int "weapon_id" int
); );

@ -48,116 +48,116 @@ new Pool({
const ENDPOINTDATA=[ const ENDPOINTDATA=[
{ {
endpoint:"class", endpoint:"class",
requiredfields:["name","icon"], requiredfields:["name"],
optionalfields:[], optionalfields:["icon"],
excludedfields:[] //Fields to not output in GET. excludedfields:[] //Fields to not output in GET.
}, },
{ {
endpoint:"class_level_data", endpoint:"class_level_data",
requiredfields:["name","icon"], requiredfields:["class_id","level","hp","atk","def"],
optionalfields:[], optionalfields:[],
excludedfields:[] //Fields to not output in GET. excludedfields:[] //Fields to not output in GET.
}, },
{ {
endpoint:"class_weapon_type_data", endpoint:"class_weapon_type_data",
requiredfields:["name","icon"], requiredfields:["class_id","weapon_type_id"],
optionalfields:[], optionalfields:[],
excludedfields:[] //Fields to not output in GET. excludedfields:[] //Fields to not output in GET.
}, },
{ {
endpoint:"weapon", endpoint:"weapon",
requiredfields:["name","icon"], 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:"weapon_existence_data", endpoint:"weapon_existence_data",
requiredfields:["name","icon"], requiredfields:["weapon_type_id","weapon_id"],
optionalfields:[], optionalfields:[],
excludedfields:[] //Fields to not output in GET. excludedfields:[] //Fields to not output in GET.
}, },
{ {
endpoint:"weapon_type", endpoint:"weapon_type",
requiredfields:["name","icon"], requiredfields:["name"],
optionalfields:[], optionalfields:["icon"],
excludedfields:[] //Fields to not output in GET. excludedfields:[] //Fields to not output in GET.
}, },
{ {
endpoint:"armor", endpoint:"armor",
requiredfields:["name","icon"], requiredfields:["name","rarity","level_req","def"],
optionalfields:[], 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"],
excludedfields:[] //Fields to not output in GET. excludedfields:[] //Fields to not output in GET.
}, },
{ {
endpoint:"potential", endpoint:"potential",
requiredfields:["name","icon"], requiredfields:["name"],
optionalfields:[], optionalfields:["icon"],
excludedfields:[] //Fields to not output in GET. excludedfields:[] //Fields to not output in GET.
}, },
{ {
endpoint:"potential_data", endpoint:"potential_data",
requiredfields:["name","icon"], requiredfields:["potential_id","level"],
optionalfields:[], 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:"builds", endpoint:"builds",
requiredfields:["name","icon"], requiredfields:["user_id","creator","build_name","class1","created_on","last_modified","data"],
optionalfields:[], optionalfields:["class2","likes"],
excludedfields:[] //Fields to not output in GET. excludedfields:[] //Fields to not output in GET.
}, },
{ {
endpoint:"skill", endpoint:"skill",
requiredfields:["name","icon"], requiredfields:["name","skill_type_id"],
optionalfields:[], optionalfields:["icon"],
excludedfields:[] //Fields to not output in GET. excludedfields:[] //Fields to not output in GET.
}, },
{ {
endpoint:"skill_type", endpoint:"skill_type",
requiredfields:["name","icon"], requiredfields:["name"],
optionalfields:[], optionalfields:[],
excludedfields:[] //Fields to not output in GET. excludedfields:[] //Fields to not output in GET.
}, },
{ {
endpoint:"skill_data", endpoint:"skill_data",
requiredfields:["name","icon"], requiredfields:["skill_id","level"],
optionalfields:[], optionalfields:["variance","mel_dmg","rng_dmg","tec_dmg","crit_rate","crit_dmg","pp_cost_reduction","active_pp_recovery","natural_pp_recovery","dmg_res"],
excludedfields:[] //Fields to not output in GET. excludedfields:[] //Fields to not output in GET.
}, },
{ {
endpoint:"augment", endpoint:"augment",
requiredfields:["name","icon"], requiredfields:["augment_type_id","level"],
optionalfields:[], 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"],
excludedfields:[] //Fields to not output in GET. excludedfields:[] //Fields to not output in GET.
}, },
{ {
endpoint:"augment_type", endpoint:"augment_type",
requiredfields:["name","icon"], requiredfields:["name"],
optionalfields:[], optionalfields:["icon"],
excludedfields:[] //Fields to not output in GET. excludedfields:[] //Fields to not output in GET.
}, },
{ {
endpoint:"food", endpoint:"food",
requiredfields:["name","icon"], requiredfields:["material"],
optionalfields:[], 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:"food_mult", endpoint:"food_mult",
requiredfields:["name","icon"], requiredfields:["amount"],
optionalfields:[], 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:"roles", endpoint:"roles",
requiredfields:["name","icon"], requiredfields:["name"],
optionalfields:[], optionalfields:[],
excludedfields:[] //Fields to not output in GET. excludedfields:[] //Fields to not output in GET.
}, },
{ {
endpoint:"users", endpoint:"users",
requiredfields:["name","icon"], requiredfields:["username","email","created_on","role_id"],
optionalfields:[], optionalfields:["avatar"],
excludedfields:["password_hash"] //Fields to not output in GET. excludedfields:["password_hash"] //Fields to not output in GET.
} }
] ]
@ -173,6 +173,34 @@ function CreateDynamicEndpoints() {
res.status(500).send(err.message) res.status(500).send(err.message)
}) })
}) })
app.post("/"+endpoint.endpoint,(req,res)=>{
var allExist=true
endpoint.requiredfields.forEach((field)=>{
if (!(field in req.body)) {
allExist=false;
}
})
if (!allExist) {
res.status(300).send("Invalid query!")
return
}
var combinedfields = [...endpoint.requiredfields,...endpoint.optionalfields,...endpoint.excludedfields]
//console.log(combinedfields)
var all_filled_fields=combinedfields.filter((field)=>(field in req.body))
db.query('insert into '+endpoint.endpoint+"("+all_filled_fields.join(',')+") values("+all_filled_fields.map((field,i)=>"$"+(i+1)).join(",")+")",all_filled_fields.map((field)=>req.body[field]))
.then((data)=>{
res.status(200).json(data.rows)
})
.catch((err)=>{
res.status(500).send(err.message)
})
})
}) })
} }

Loading…
Cancel
Save