From d1476ac35c70a9c71b6dd2be292e36ed94093015 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 15 Aug 2021 20:38:43 -0500 Subject: [PATCH 1/8] Forgot --- server.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/server.js b/server.js index 0844157..361206f 100644 --- a/server.js +++ b/server.js @@ -811,6 +811,58 @@ app.post(PREFIX+"/validUser",(req,res)=>{ }) }) +app.post(PREFIX+"/saveskilltree",(req,res)=>{ + db4.query('select * from password where password=$1',[req.body.pass]) + .then((data)=>{ + if (data.rows.length>0) { + return db.query('select * from skill_tree_data where class_id=$1 limit 1',[req.body.class_id]) + } else { + var msg="Could not authenticate!";res.status(500).send(msg);throw msg + } + }) + .then((data)=>{ + if (data.rows.length>0) { + return db.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 where class_id=$9', + [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.class_id]) + } else { + return db.query('insert into skill_tree_data(data,skill_data,line_color,line_width,gridsizex,gridsizey,gridpaddingx,gridpaddingy,class_id) values($1,$2,$3,$4,$5,$6,$7,$8,$9)', + [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.class_id]) + } + }) + .then((data)=>{ + res.status(200).send("OK!") + }) + .catch((err)=>{ + res.status(500).send(err.message) + }) +}) + +app.post(PREFIX+"/test/saveskilltree",(req,res)=>{ + db4.query('select * from password where password=$1',[req.body.pass]) + .then((data)=>{ + if (data.rows.length>0) { + return db2.query('select * from skill_tree_data where class_id=$1 limit 1',[req.body.class_id]) + } else { + var msg="Could not authenticate!";res.status(500).send(msg);throw msg + } + }) + .then((data)=>{ + if (data.rows.length>0) { + return db2.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 where class_id=$9', + [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.class_id]) + } else { + return db2.query('insert into skill_tree_data(data,skill_data,line_color,line_width,gridsizex,gridsizey,gridpaddingx,gridpaddingy,class_id) values($1,$2,$3,$4,$5,$6,$7,$8,$9)', + [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.class_id]) + } + }) + .then((data)=>{ + res.status(200).send("OK!") + }) + .catch((err)=>{ + res.status(500).send(err.message) + }) +}) + //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")) From 96566c7ea0dd7e3bfc49e5bcc5e45232c0e06ab8 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Mon, 16 Aug 2021 09:34:14 -0500 Subject: [PATCH 2/8] Implement halflineheight endpoint value --- ngsplanner_patch.sql | 3 ++- ngsplanner_schema.sql | 3 ++- ngsplanner_seed.sql | 4 ++-- server.js | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ngsplanner_patch.sql b/ngsplanner_patch.sql index 1a468f8..e301b48 100644 --- a/ngsplanner_patch.sql +++ b/ngsplanner_patch.sql @@ -9,4 +9,5 @@ alter table photon_art add column icon text; alter table users add column recovery_hash text; alter table armor rename column pb_gauge_build to slot; CREATE TABLE "skill_tree_data"("id" SERIAL UNIQUE PRIMARY KEY,"class_id" int,"data" text,"skill_data" text,"line_color" text,"line_width" int,"gridsizex" int,"gridsizey" int,"gridpaddingx" int,"gridpaddingy" int); -ALTER TABLE "skill_tree_data" ADD FOREIGN KEY ("class_id") REFERENCES "class" ("id"); \ No newline at end of file +ALTER TABLE "skill_tree_data" ADD FOREIGN KEY ("class_id") REFERENCES "class" ("id"); +alter table skill_tree_data add column halflineheight int; \ No newline at end of file diff --git a/ngsplanner_schema.sql b/ngsplanner_schema.sql index 55e9a0d..c9f0b40 100644 --- a/ngsplanner_schema.sql +++ b/ngsplanner_schema.sql @@ -316,7 +316,8 @@ CREATE TABLE "skill_tree_data" ( "gridsizex" int, "gridsizey" int, "gridpaddingx" int, - "gridpaddingy" int + "gridpaddingy" int, + "halflineheight" int ); ALTER TABLE "builds" ADD FOREIGN KEY ("users_id") REFERENCES "users" ("id"); diff --git a/ngsplanner_seed.sql b/ngsplanner_seed.sql index b470bba..c22a6cb 100644 --- a/ngsplanner_seed.sql +++ b/ngsplanner_seed.sql @@ -276,5 +276,5 @@ insert into class_skill_data(name,class_skill_id,dependency,level,effect,duratio insert into class_skill_data(name,class_skill_id,dependency,level,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) values('Assault Charge Advent',(SELECT id from class_skill WHERE name='Assault Charge Advent' limit 1),'',1,'Effect Name',30,24,1.0,1.1,false,0.8,'',0,0,0,0,0,0,0.6,0,0); -insert into skill_tree_data(class_id,data,skill_data,line_color,line_width,gridsizex,gridsizey,gridpaddingx,gridpaddingy) - values((select id from class where name='Hunter'),'□ □ ,└□─┘□□, │ ││, │ □│, □─□┼□, □ ','','#000000',3,80,60,10,10); \ No newline at end of file +insert into skill_tree_data(class_id,data,skill_data,line_color,line_width,gridsizex,gridsizey,gridpaddingx,gridpaddingy,halflineheight) + values((select id from class where name='Hunter'),'□ □ ,└□─┘□□, │ ││, │ □│, □─□┼□, □ ','','#000000',3,80,60,10,10,60); \ No newline at end of file diff --git a/server.js b/server.js index 361206f..a3ff977 100644 --- a/server.js +++ b/server.js @@ -223,7 +223,7 @@ const ENDPOINTDATA=[ }, { endpoint:"skill_tree_data", - requiredfields:["class_id","data","skill_data","line_color","line_width","gridsizex","gridsizey","gridpaddingx","gridpaddingy"], + requiredfields:["class_id","data","skill_data","line_color","line_width","gridsizex","gridsizey","gridpaddingx","gridpaddingy","halflineheight"], optionalfields:[], excludedfields:[] //Fields to not output in GET. } From aa85511e87a1a4fbe2c746b98dc477c1bec31863 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Mon, 16 Aug 2021 18:24:48 -0500 Subject: [PATCH 3/8] Added extra handling of endpoints --- server.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server.js b/server.js index a3ff977..daea152 100644 --- a/server.js +++ b/server.js @@ -822,11 +822,11 @@ app.post(PREFIX+"/saveskilltree",(req,res)=>{ }) .then((data)=>{ if (data.rows.length>0) { - return db.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 where class_id=$9', - [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.class_id]) + return db.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', + [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) } else { - return db.query('insert into skill_tree_data(data,skill_data,line_color,line_width,gridsizex,gridsizey,gridpaddingx,gridpaddingy,class_id) values($1,$2,$3,$4,$5,$6,$7,$8,$9)', - [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.class_id]) + return db.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,$9,$10)', + [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) } }) .then((data)=>{ @@ -848,11 +848,11 @@ app.post(PREFIX+"/test/saveskilltree",(req,res)=>{ }) .then((data)=>{ if (data.rows.length>0) { - return db2.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 where class_id=$9', - [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.class_id]) + return db2.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', + [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) } else { - return db2.query('insert into skill_tree_data(data,skill_data,line_color,line_width,gridsizex,gridsizey,gridpaddingx,gridpaddingy,class_id) values($1,$2,$3,$4,$5,$6,$7,$8,$9)', - [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.class_id]) + return db2.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,$9,$10)', + [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) } }) .then((data)=>{ From aa7d7faf9f79061fdda4a400256f2d55bb920e83 Mon Sep 17 00:00:00 2001 From: Nic0Nic0Nii Date: Wed, 18 Aug 2021 05:19:05 +0000 Subject: [PATCH 4/8] Fix up patch and schema database files --- ngsplanner_patch.sql | 1 + ngsplanner_schema.sql | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ngsplanner_patch.sql b/ngsplanner_patch.sql index e301b48..3a6faff 100644 --- a/ngsplanner_patch.sql +++ b/ngsplanner_patch.sql @@ -8,6 +8,7 @@ alter table potential_data add column description text; alter table photon_art add column icon text; alter table users add column recovery_hash text; alter table armor rename column pb_gauge_build to slot; +alter table armor add column battle_power_value text; CREATE TABLE "skill_tree_data"("id" SERIAL UNIQUE PRIMARY KEY,"class_id" int,"data" text,"skill_data" text,"line_color" text,"line_width" int,"gridsizex" int,"gridsizey" int,"gridpaddingx" int,"gridpaddingy" int); ALTER TABLE "skill_tree_data" ADD FOREIGN KEY ("class_id") REFERENCES "class" ("id"); alter table skill_tree_data add column halflineheight int; \ No newline at end of file diff --git a/ngsplanner_schema.sql b/ngsplanner_schema.sql index c9f0b40..5092b1c 100644 --- a/ngsplanner_schema.sql +++ b/ngsplanner_schema.sql @@ -127,7 +127,7 @@ CREATE TABLE "armor" ( "panic_res" float, "poison_res" float, "slot" int, - "pb_gauge_build" float, + "battle_power_value" float, "icon" text, "popularity" int, "editors_choice" int From 9cb3f06e8cd12b8f67d290a0d858d19feec04fe3 Mon Sep 17 00:00:00 2001 From: Nic0Nic0Nii Date: Wed, 18 Aug 2021 06:06:57 +0000 Subject: [PATCH 5/8] Add in a server_test for the test backend --- server_test.js | 826 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 826 insertions(+) create mode 100644 server_test.js diff --git a/server_test.js b/server_test.js new file mode 100644 index 0000000..94f7a6c --- /dev/null +++ b/server_test.js @@ -0,0 +1,826 @@ +const express = require('express'); +const app = express() +const bodyParser = require('body-parser'); + +const { Pool } = require('pg'); + +const db = new Pool({ + connectionString: process.env.DATABASE_URL, + ssl: { + rejectUnauthorized: false + } +}); +const PORT = process.env.PORT || 5000; +app.use(bodyParser.json()) +app.use( + bodyParser.urlencoded({ + extended: true, + }) +) +let allowCrossDomain = function(req, res, next) { + res.header('Access-Control-Allow-Origin', "*"); + res.header('Access-Control-Allow-Headers', "*"); + res.header('Access-Control-Allow-Methods', "*"); + next(); + } + app.use(allowCrossDomain); + app.listen(PORT, () => console.log(`Listening on ${ PORT }`)); + + var authenticated = true; + + +const PREFIX="" + +const ENDPOINTDATA=[ + { + endpoint:"class", + requiredfields:["name"], + optionalfields:["icon"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"class_level_data", + requiredfields:["class_id","level","hp","atk","def","name"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"class_weapon_type_data", + requiredfields:["class_id","weapon_type_id"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"weapon", + requiredfields:["name","rarity","level_req","atk"], + optionalfields:["potential_id","variance","base_affix_slots","drop_info","pb_gauge_build","icon"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"weapon_existence_data", + requiredfields:["weapon_type_id","weapon_id"], + optionalfields:["popularity","editors_choice","icon","special_name"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"weapon_type", + requiredfields:["name","dmg_type"], + optionalfields:["icon","shorthand"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"photon_art", + requiredfields:["name","weapon_type_id","potency","dps"], + optionalfields:["power_distribution","pp","frames","icon"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"armor", + requiredfields:["name","rarity","level_req","def"], + 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","slot","icon","popularity","editors_choice"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"potential", + requiredfields:["name"], + optionalfields:["icon"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"potential_data", + requiredfields:["potential_id","level","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","description"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"builds", + requiredfields:["users_id","creator","build_name","class1","created_on","last_modified","data"], + optionalfields:["class2","likes","editors_choice"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"skill", + requiredfields:["name","skill_type_id"], + optionalfields:["icon"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"skill_type", + requiredfields:["name"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"skill_data", + requiredfields:["skill_id","level","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"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"class_skill", + requiredfields:["name","class_id"], + optionalfields:["icon","description"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"class_skill_data", + requiredfields:["name","class_skill_id","level"], + 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"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"augment", + requiredfields:["augment_type_id","name"], + 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. + }, + { + endpoint:"augment_type", + requiredfields:["name"], + optionalfields:["icon"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"enemy_data", + requiredfields:["level","def","atk"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"food", + requiredfields:["name"], + 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. + }, + { + endpoint:"food_mult", + requiredfields:["amount"], + optionalfields:["potency","pp","dmg_res","hp","pp_consumption","pp_recovery","weak_point_dmg","hp_recovery"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"roles", + requiredfields:["name"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"users", + requiredfields:["username","email","created_on","roles_id"], + optionalfields:["avatar","editors_choice","recovery_hash"], + excludedfields:["password_hash"] //Fields to not output in GET. + }, + { + endpoint:"database_audit", + requiredfields:["action","table_name","row_name","row_id","new_value","date","users_id"], + optionalfields:["old_value"], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"skill_tree_data", + requiredfields:["class_id","data","skill_data","line_color","line_width","gridsizex","gridsizey","gridpaddingx","gridpaddingy","halflineheight"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + } +] + +const MAXATTEMPTS=5 +const LOCKOUTTIME=60000 +var failedattempts=0 +var lockedTime=new Date().getTime()-LOCKOUTTIME //Starts unlocked + +for (var test of ["","/test"]) { + + app.post(PREFIX+test+"/passwordcheck",(req,res)=>{ + db.query('select * from password where password=$1',[req.body.pass]) + .then((data)=>{ + if (data.rows.length>0) { + res.status(200).json({verified:true}) + } else { + var msg="Could not authenticate!";res.status(500).send(msg);throw msg + } + }) + .catch((err)=>{ + res.status(500).send(err.message) + }) + }) + app.get(PREFIX+test+"/databases",(req,res)=>{ + db.query('select * from password where password=$1',[req.query.pass]) + .then((data)=>{ + if (data.rows.length>0) { + return db.query('select * from pg_database where datname like \'ngsplanner%\' order by datname desc limit 100') + } else { + var msg="Could not authenticate!";res.status(500).send(msg);throw msg + } + }) + .then((data)=>{ + res.status(200).json(data.rows) + }) + .catch((err)=>{ + res.status(500).send(err.message) + }) + }) + + app.post(PREFIX+test+"/databases/restorefrombackup",(req,res)=>{ + if (req.body.database) { + db.query('select * from password where password=$1',[req.body.pass]) + .then((data)=>{ + if (data.rows.length>0) { + return db3.query('select * from pg_database where datname=$1',[req.body.database]) + } else { + var msg="Could not authenticate!";res.status(500).send(msg);throw msg + } + }) + .then((data)=>{ + if (data.rows.length>0) { + db.end(()=>{}) + return db3.query('select pg_terminate_backend (pid) from pg_stat_activity where pg_stat_activity.datname=\'ngsplanner\'') + } else { + var msg="Could not find requested database "+req.body.database;res.status(500).send(msg);throw msg + } + }) + .then(()=>{ + return db3.query('drop database ngsplanner') + }) + .then(()=>{ + return db3.query('create database ngsplanner with template '+req.body.database) + }) + .then(()=>{ + db = new Pool({ + user: 'postgres', + password: '', + host: 'postgres', + database: 'ngsplanner', + port: 5432, + }) + res.status(200).send("Done!") + }) + .catch((err)=>{ + console.log(err.message) + res.status(500).send(err.message) + }) + } else { + res.status(500).send("Invalid data!") + } + }) + app.post(PREFIX+test+"/databases/testtolive",(req,res)=>{ + db.query('select * from password where password=$1',[req.body.pass]) + .then((data)=>{ + if (data.rows.length>0) { + db.end(()=>{}) + db2.end(()=>{}) + return db3.query('select pg_terminate_backend (pid) from pg_stat_activity where pg_stat_activity.datname=\'ngsplanner\' or pg_stat_activity.datname=\'ngsplanner2\'') + } else { + var msg="Could not authenticate!";res.status(500).send(msg);throw msg + } + }) + .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+test+"/databases/livetotest",(req,res)=>{ + db.query('select * from password where password=$1',[req.body.pass]) + .then((data)=>{ + if (data.rows.length>0) { + db.end(()=>{}) + db2.end(()=>{}) + return db3.query('select pg_terminate_backend (pid) from pg_stat_activity where pg_stat_activity.datname=\'ngsplanner\' or pg_stat_activity.datname=\'ngsplanner2\'') + } else { + var msg="Could not authenticate!";res.status(500).send(msg);throw msg + } + }) + .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+test+"/databases/backup",(req,res)=>{ + var date = new Date() + db.query('select * from password where password=$1',[req.body.pass]) + .then((data)=>{ + if (data.rows.length>0) { + db.end(()=>{}) + return db3.query('select pg_terminate_backend (pid) from pg_stat_activity where pg_stat_activity.datname=\'ngsplanner\'') + } else { + var msg="Could not authenticate!";res.status(500).send(msg);throw msg + } + }) + .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)=>{ + db.query('select * from password where password=$1',[req.query.pass]) + .then((data)=>{ + if (data.rows.length>0) { + 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) + }) + } + } else { + res.status(500).send("Could not authenticate!") + } + }) + }) + + app.post(PREFIX+"/"+endpoint.endpoint,async(req,res)=>{ + db.query('select * from password where password=$1',[req.body.pass]) + .then(async(data)=>{ + if (data.rows.length>0) { + 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)=>{ + if (!field.includes("_id")) {return field+"=$"+(i+1)}else{ + if (Number.isNaN(Number(req.body[field]))) {return field+"=(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"} else {return 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)=>{ + 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)} + }}).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.post(PREFIX+"/"+endpoint.endpoint,async(req,res)=>{ + db.query('select * from password where password=$1',[req.body.pass]) + .then(async(data)=>{ + if (data.rows.length>0) { + 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)=>{ + if (!field.includes("_id")) {return field+"=$"+(i+1)}else{ + if (Number.isNaN(Number(req.body[field]))) {return field+"=(select id from "+field.replace("_id","")+" where name=$"+(i+1)+")"} else {return 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)=>{ + 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)} + }}).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) + }) + } + } else { + res.status(500).send("Could not authenticate!") + } + }) + }) + } else { + res.status(500).send("Could not authenticate!") + } + }) + }) + + app.patch(PREFIX+"/"+endpoint.endpoint,(req,res)=>{ + if (req.body.id) { + db.query('select * from password where password=$1',[req.body.pass]) + .then((data)=>{ + if (data.rows.length>0) { + var combinedfields = [...endpoint.requiredfields,...endpoint.optionalfields,...endpoint.excludedfields] + //console.log(combinedfields) + var all_filled_fields=combinedfields.filter((field)=>(field in req.body)) + + return 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]) + } else { + var msg="Could not authenticate!";res.status(500).send(msg);throw msg + } + }) + .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('select * from password where password=$1',[req.body.pass]) + .then((data)=>{ + if (data.rows.length>0) { + return db.query('delete from '+endpoint.endpoint+' where id=$1 returning *',[req.body.id]) + } else { + var msg="Could not authenticate!";res.status(500).send(msg);throw msg + } + }) + .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)=>{ + db.query('select * from password where password=$1',[req.query.pass]) + .then((data)=>{ + if (data.rows.length>0) { + 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) + }) + } + } else { + res.status(500).send("Could not authenticate!") + } + }) + }) + + app.post(PREFIX+"/test/"+endpoint.endpoint,async(req,res)=>{ + db.query('select * from password where password=$1',[req.body.pass]) + .then(async(data)=>{ + if (data.rows.length>0) { + 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 db2.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) { + 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) + }) + } + } else { + res.status(500).send("Could not authenticate!") + } + }) + }) + + app.patch(PREFIX+"/test/"+endpoint.endpoint,(req,res)=>{ + if (req.body.id) { + db.query('select * from password where password=$1',[req.body.pass]) + .then((data)=>{ + if (data.rows.length>0) { + var combinedfields = [...endpoint.requiredfields,...endpoint.optionalfields,...endpoint.excludedfields] + //console.log(combinedfields) + var all_filled_fields=combinedfields.filter((field)=>(field in req.body)) + + return 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]) + } else { + var msg="Could not authenticate!";res.status(500).send(msg);throw msg + } + }) + .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) { + db.query('select * from password where password=$1',[req.body.pass]) + .then((data)=>{ + if (data.rows.length>0) { + return db2.query('delete from '+endpoint.endpoint+' where id=$1 returning *',[req.body.id]) + } else { + var msg="Could not authenticate!";res.status(500).send(msg);throw msg + } + }) + .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) +}) + +app.post(PREFIX+"/validUser",(req,res)=>{ + //console.log(sh.SecretHash("098f6bcd4621d373cade4e832627b4f6")) + db.query('select * from users where username=$1 and password_hash=$2 limit 1',[req.body.username,sh.SecretHash(req.body.password)]) + .then((data)=>{ + if (data.rows.length>0) { + res.status(200).json({verified:true}) + } else { + res.status(200).json({verified:false}) + } + }) + .catch((err)=>{ + res.status(500).send(err.message) + }) +}) + +app.post(PREFIX+"/saveskilltree",(req,res)=>{ + db.query('select * from password where password=$1',[req.body.pass]) + .then((data)=>{ + if (data.rows.length>0) { + return db.query('select * from skill_tree_data where class_id=$1 limit 1',[req.body.class_id]) + } else { + var msg="Could not authenticate!";res.status(500).send(msg);throw msg + } + }) + .then((data)=>{ + if (data.rows.length>0) { + return db.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', + [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) + } else { + return db.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,$9,$10)', + [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) + } + }) + .then((data)=>{ + res.status(200).send("OK!") + }) + .catch((err)=>{ + res.status(500).send(err.message) + }) +}) + +app.post(PREFIX+"/test/saveskilltree",(req,res)=>{ + db.query('select * from password where password=$1',[req.body.pass]) + .then((data)=>{ + if (data.rows.length>0) { + return db2.query('select * from skill_tree_data where class_id=$1 limit 1',[req.body.class_id]) + } else { + var msg="Could not authenticate!";res.status(500).send(msg);throw msg + } + }) + .then((data)=>{ + if (data.rows.length>0) { + return db2.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', + [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) + } else { + return db2.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,$9,$10)', + [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) + } + }) + .then((data)=>{ + res.status(200).send("OK!") + }) + .catch((err)=>{ + res.status(500).send(err.message) + }) +}) + +//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")) +}) + +CreateDynamicEndpoints() \ No newline at end of file From 7e297c9875045dce47fda9d9999d878eb079bbe3 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 18 Aug 2021 23:39:49 -0500 Subject: [PATCH 6/8] Fix bad ordering for /saveskilltree endpoints --- server.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index daea152..e62947a 100644 --- a/server.js +++ b/server.js @@ -825,7 +825,7 @@ app.post(PREFIX+"/saveskilltree",(req,res)=>{ return db.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', [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) } else { - return db.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,$9,$10)', + return db.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)', [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) } }) @@ -851,7 +851,7 @@ app.post(PREFIX+"/test/saveskilltree",(req,res)=>{ return db2.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', [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) } else { - return db2.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,$9,$10)', + return db2.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)', [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) } }) @@ -868,4 +868,4 @@ ENDPOINTDATA.forEach((endpoint)=>{ console.log(endpoint.endpoint+":\n\t"+endpoint.requiredfields.join('\t')+(endpoint.optionalfields.length>0?"\t":"")+endpoint.optionalfields.join("\t")) }) -CreateDynamicEndpoints() \ No newline at end of file +CreateDynamicEndpoints() From 3f3476de79acaf66c5fbd2740038947a9da7b61b Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 18 Aug 2021 23:41:11 -0500 Subject: [PATCH 7/8] Fix server test --- server_test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server_test.js b/server_test.js index 94f7a6c..affa594 100644 --- a/server_test.js +++ b/server_test.js @@ -780,7 +780,7 @@ app.post(PREFIX+"/saveskilltree",(req,res)=>{ return db.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', [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) } else { - return db.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,$9,$10)', + return db.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)', [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) } }) @@ -806,7 +806,7 @@ app.post(PREFIX+"/test/saveskilltree",(req,res)=>{ return db2.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', [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) } else { - return db2.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,$9,$10)', + return db2.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)', [req.body.data,req.body.skill_data,req.body.line_color,req.body.line_width,req.body.gridsizex,req.body.gridsizey,req.body.gridpaddingx,req.body.gridpaddingy,req.body.halflineheight,req.body.class_id]) } }) @@ -823,4 +823,4 @@ ENDPOINTDATA.forEach((endpoint)=>{ console.log(endpoint.endpoint+":\n\t"+endpoint.requiredfields.join('\t')+(endpoint.optionalfields.length>0?"\t":"")+endpoint.optionalfields.join("\t")) }) -CreateDynamicEndpoints() \ No newline at end of file +CreateDynamicEndpoints() From 03e7144eaef7591e2f4a02d7e4ab01b42ec733a1 Mon Sep 17 00:00:00 2001 From: Nic0Nic0Nii Date: Thu, 19 Aug 2021 07:09:43 +0000 Subject: [PATCH 8/8] Implement site_data table to backend --- ngsplanner_patch.sql | 3 ++- ngsplanner_schema.sql | 6 ++++++ ngsplanner_seed.sql | 4 +++- server.js | 6 ++++++ server_test.js | 6 ++++++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ngsplanner_patch.sql b/ngsplanner_patch.sql index 3a6faff..b557a1c 100644 --- a/ngsplanner_patch.sql +++ b/ngsplanner_patch.sql @@ -11,4 +11,5 @@ alter table armor rename column pb_gauge_build to slot; alter table armor add column battle_power_value text; CREATE TABLE "skill_tree_data"("id" SERIAL UNIQUE PRIMARY KEY,"class_id" int,"data" text,"skill_data" text,"line_color" text,"line_width" int,"gridsizex" int,"gridsizey" int,"gridpaddingx" int,"gridpaddingy" int); ALTER TABLE "skill_tree_data" ADD FOREIGN KEY ("class_id") REFERENCES "class" ("id"); -alter table skill_tree_data add column halflineheight int; \ No newline at end of file +alter table skill_tree_data add column halflineheight int; +CREATE TABLE "site_data" ("id" SERIAL UNIQUE PRIMARY KEY,"field" text,"data" text); diff --git a/ngsplanner_schema.sql b/ngsplanner_schema.sql index 5092b1c..37ecf75 100644 --- a/ngsplanner_schema.sql +++ b/ngsplanner_schema.sql @@ -320,6 +320,12 @@ CREATE TABLE "skill_tree_data" ( "halflineheight" int ); +CREATE TABLE "site_data" ( + "id" SERIAL UNIQUE PRIMARY KEY, + "field" text, + "data" text +); + ALTER TABLE "builds" ADD FOREIGN KEY ("users_id") REFERENCES "users" ("id"); ALTER TABLE "users" ADD FOREIGN KEY ("roles_id") REFERENCES "roles" ("id"); diff --git a/ngsplanner_seed.sql b/ngsplanner_seed.sql index c22a6cb..4dba741 100644 --- a/ngsplanner_seed.sql +++ b/ngsplanner_seed.sql @@ -277,4 +277,6 @@ insert into class_skill_data(name,class_skill_id,dependency,level,effect,duratio values('Assault Charge Advent',(SELECT id from class_skill WHERE name='Assault Charge Advent' limit 1),'',1,'Effect Name',30,24,1.0,1.1,false,0.8,'',0,0,0,0,0,0,0.6,0,0); insert into skill_tree_data(class_id,data,skill_data,line_color,line_width,gridsizex,gridsizey,gridpaddingx,gridpaddingy,halflineheight) - values((select id from class where name='Hunter'),'□ □ ,└□─┘□□, │ ││, │ □│, □─□┼□, □ ','','#000000',3,80,60,10,10,60); \ No newline at end of file + values((select id from class where name='Hunter'),'□ □ ,└□─┘□□, │ ││, │ □│, □─□┼□, □ ','','#000000',3,80,60,10,10,60); + +insert into site_data(field,data) values('UNDER_CONSTRUCTION_TEXT','NGSplanner.com is currently under construction! Please check back after Sig yells at me enough to help finish it.'); \ No newline at end of file diff --git a/server.js b/server.js index e62947a..6cb7fcf 100644 --- a/server.js +++ b/server.js @@ -226,6 +226,12 @@ const ENDPOINTDATA=[ requiredfields:["class_id","data","skill_data","line_color","line_width","gridsizex","gridsizey","gridpaddingx","gridpaddingy","halflineheight"], optionalfields:[], excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"site_data", + requiredfields:["field","data"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. } ] diff --git a/server_test.js b/server_test.js index affa594..affb8c3 100644 --- a/server_test.js +++ b/server_test.js @@ -181,6 +181,12 @@ const ENDPOINTDATA=[ requiredfields:["class_id","data","skill_data","line_color","line_width","gridsizex","gridsizey","gridpaddingx","gridpaddingy","halflineheight"], optionalfields:[], excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"site_data", + requiredfields:["field","data"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. } ]