From 8b1b559adb0951c36854dec6f54968e1ce017a87 Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Thu, 29 Jul 2021 06:36:42 +0000 Subject: [PATCH] Apply "iterative" database approach to new backend. --- server.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/server.js b/server.js index 73b7215..b07ac19 100644 --- a/server.js +++ b/server.js @@ -171,13 +171,23 @@ const ENDPOINTDATA=[ function CreateDynamicEndpoints() { ENDPOINTDATA.map((endpoint)=>{ app.get("/"+endpoint.endpoint,(req,res)=>{ - 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) - }) + 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) + }) + } })