|
|
|
@ -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) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|