Apply "iterative" database approach to new backend.
This commit is contained in:
parent
aa345b61cf
commit
8b1b559adb
10
server.js
10
server.js
@ -171,6 +171,15 @@ const ENDPOINTDATA=[
|
|||||||
function CreateDynamicEndpoints() {
|
function CreateDynamicEndpoints() {
|
||||||
ENDPOINTDATA.map((endpoint)=>{
|
ENDPOINTDATA.map((endpoint)=>{
|
||||||
app.get("/"+endpoint.endpoint,(req,res)=>{
|
app.get("/"+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")
|
db.query('select * from '+endpoint.endpoint+" order by id desc")
|
||||||
.then((data)=>{
|
.then((data)=>{
|
||||||
res.status(200).json({fields:data.fields,rows:data.rows})
|
res.status(200).json({fields:data.fields,rows:data.rows})
|
||||||
@ -178,6 +187,7 @@ function CreateDynamicEndpoints() {
|
|||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
res.status(500).send(err.message)
|
res.status(500).send(err.message)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user