Skip to content

Commit 08b02dd

Browse files
committed
Cleanups.
1 parent 3d2a4d9 commit 08b02dd

3 files changed

Lines changed: 23 additions & 19 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ More sample models:
210210
211211
<a name="API"></a>
212212
## API
213-
Evolutility-Server-Node provides a generic RESTful API for CRUD (Create, Read, Update, Delete) and more. It uses [Node.js](https://nodejs.org/en/), [Express](http://expressjs.com/) and [PostgreSQL](http://www.postgresql.org/).
213+
Evolutility-Server-Node provides a generic RESTful API for CRUD (Create, Read, Update, Delete) and more. It uses [Node.js](https://nodejs.org/en/), [Express](http://expressjs.com/), [PostgreSQL](http://www.postgresql.org/), and [PG-Promise](https://github.com/vitaly-t/pg-promise).
214214
The API is inspired from [PostgREST](http://postgrest.com).
215215
216-
When running Evolutility-Server-Node locally, the url for the "todo" app is
217-
[http://localhost:2000/api/v1/todo](http://localhost:2000/api/v1/todo).
216+
When running Evolutility-Server-Node locally, the base url is
217+
[http://localhost:2000/api/v1/](http://localhost:2000/api/v1/).
218218
219219
<a name="API_Get"></a>
220220
### Requesting Information

js/crud.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -303,22 +303,26 @@ function getOne(req, res) {
303303
// - insert a single record
304304
function insertOne(req, res) {
305305
logger.logReq('INSERT ONE', req);
306-
const m = dico.getModel(req.params.entity),
307-
pKey = m.pKey || 'id',
308-
q = sqls.namedValues(m, req, 'insert');
309-
310-
if(q.invalids){
311-
returnInvalid(res, q.invalids)
312-
}else if(m && q.names.length){
313-
const ps = q.names.map((n, idx) => '$'+(idx+1));
314-
const selectId = pKey==='id' ? pKey : '"'+pKey+'" as id'
315-
const sql = 'INSERT INTO '+m.schemaTable+
316-
' ("'+q.names.join('","')+'") values('+ps.join(',')+')'+
317-
' RETURNING '+selectId+', '+sqls.select(m.fields, false, null, 'C')+';';
318-
319-
query.runQuery(res, sql, q.values, true);
306+
const m = dico.getModel(req.params.entity)
307+
if(!m){
308+
return errors.badRequest(res)
320309
}else{
321-
errors.badRequest(res)
310+
const pKey = m.pKey || 'id',
311+
q = sqls.namedValues(m, req, 'insert');
312+
313+
if(q.invalids){
314+
returnInvalid(res, q.invalids)
315+
}else if(m && q.names.length){
316+
const ps = q.names.map((n, idx) => '$'+(idx+1));
317+
const selectId = pKey==='id' ? pKey : '"'+pKey+'" as id'
318+
const sql = 'INSERT INTO '+m.schemaTable+
319+
' ("'+q.names.join('","')+'") values('+ps.join(',')+')'+
320+
' RETURNING '+selectId+', '+sqls.select(m.fields, false, null, 'C')+';';
321+
322+
query.runQuery(res, sql, q.values, true);
323+
}else{
324+
errors.badRequest(res)
325+
}
322326
}
323327
}
324328

models/designer/field.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ module.exports = {
139139
"type": "text",
140140
"label": "LOV Table",
141141
"maxLength": 100,
142-
"column": "lovTable"
142+
"column": "lovtable"
143143
},
144144
{
145145
"id": "lovColumn",

0 commit comments

Comments
 (0)