Skip to content

Commit a92d82d

Browse files
committed
Cleanups.
1 parent 63827a9 commit a92d82d

9 files changed

Lines changed: 70 additions & 30 deletions

File tree

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ For a matching model-driven Web UI, use [Evolutility-UI-React](http://github.com
1111
1. [Installation](#Installation)
1212
2. [Setup](#Setup)
1313
3. [Configuration](#Configuration)
14-
4. [Models](#Models)
15-
5. [API](#API)
14+
4. [Models](#Models): [Object](#Object) - [Field](#Field) - [Collection](#Collection)
15+
5. [API](#API): [Get](#API_Get) - [Update](#API_Update) - [More](#API_Extras)
1616
6. [License](#License)
1717

1818

@@ -59,7 +59,7 @@ npm start
5959

6060
**Note**: The database creation and population scripts are logged in the files "evol-db-schema-{datetime}.sql" and "evol-db-data-{datetime}.sql".
6161

62-
In a web browser, go to the url [http://localhost:2000/api/v1/evolutility/todo](http://localhost:2000/api/v1/evolutility/todo).
62+
In a web browser, go to [http://localhost:2000/api/v1/](http://localhost:2000/api/v1/) for REST or [http://localhost:2000/graphql](http://localhost:2000/graphql) for GraphQL.
6363

6464

6565
<a name="Configuration"></a>
@@ -70,7 +70,7 @@ Configuration options are set in the file [config.js](https://github.com/evolute
7070

7171
| Option | Description |
7272
|---------------|-----------------------------------------|
73-
| apiPath | Path for REST API (i.e.: "/api/v1/evolutility/"). |
73+
| apiPath | Path for REST API (i.e.: "/api/v1/"). |
7474
| apiPort | Port for REST API (i.e.: 2000). |
7575
| connectionString | DB connection string (i.e.: "postgres://evol:love@localhost:5432/evol"). |
7676
| schema | DB schema name (i.e.: "evolutility").|
@@ -91,7 +91,7 @@ Configuration options are set in the file [config.js](https://github.com/evolute
9191
To be accessible by the REST API, each database table must be described in a model.
9292
Models contain the name of the driving table and the list of fields/columns present in the API.
9393

94-
94+
<a name="Object"></a>
9595
### Object
9696

9797
| Property | Description |
@@ -103,7 +103,7 @@ Models contain the name of the driving table and the list of fields/columns pres
103103
| titleField | Field id for the column value used as record title. |
104104
| searchFields | Array of field ids for fields used to perform searches. |
105105

106-
106+
<a name="Field"></a>
107107
### Field
108108

109109
| Property | Description |
@@ -125,7 +125,7 @@ Models contain the name of the driving table and the list of fields/columns pres
125125
| deleteTrigger | Deleting records in the lovTable will trigger a cascade delete (this property is only used while creating the database). |
126126

127127

128-
128+
<a name="Collection"></a>
129129
### Collection
130130

131131
Multiple Master-Details can be specified with collections.
@@ -142,6 +142,7 @@ Multiple Master-Details can be specified with collections.
142142
Example of collection in [Wine cellar](https://github.com/evoluteur/evolutility-server-node/blob/master/models/pim/winecellar.js).
143143

144144

145+
<a name="SampleModel"></a>
145146
### Sample model
146147

147148
Below is the model for a To-Do app.
@@ -209,9 +210,9 @@ Evolutility-Server-Node provides a generic RESTful API for CRUD (Create, Read, U
209210
The API is inspired from [PostgREST](http://postgrest.com).
210211
211212
When running Evolutility-Server-Node locally, the url for the "todo" app is
212-
[http://localhost:2000/api/v1/evolutility/todo](http://localhost:2000/api/v1/evolutility/todo).
213-
213+
[http://localhost:2000/api/v1/todo](http://localhost:2000/api/v1/todo).
214214
215+
<a name="API_Get"></a>
215216
### Requesting Information
216217
217218
#### Get One
@@ -313,6 +314,7 @@ GET /todo?format=csv
313314
```
314315
Notes: In the returned data every object has an extra property "\_full_count" which indicate the total number of records in the query (before limit).
315316
317+
<a name="API_Update"></a>
316318
### Updating Data
317319
318320
#### Record creation
@@ -358,6 +360,7 @@ DELETE /<model.id>/<id>
358360
DELETE /todo/5
359361
```
360362
363+
<a name="API_Extras"></a>
361364
### Extras endpoints
362365
363366
In addition to CRUD, Evolutility-Server-Node provides a few endpoints for Charts, Lists of values, file upload, and API discovery.

config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
connectionString: process.env.DATABASE_URL || 'postgres://evol:love@localhost:5432/Evolutility',
1313
schema: 'evolutility',
1414

15+
// OPTIONS
1516
// Pagination and maximum number of rows
1617
pageSize: 50,
1718
lovSize: 100,
@@ -22,7 +23,6 @@ module.exports = {
2223
wTimestamp: true,
2324
// - "WhoIs" columns u_uid and c_uid w/ userid of creator and last modifier
2425
wWhoIs: false,
25-
2626
// - Comments & Ratings (community feature)
2727
wComments: false,
2828
wRating: false,

js/graphql-schema.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ const model2gqlObjectType = m => {
8484
fields['c_date'] = gqlField({type: ft.datetime})
8585
fields['u_date'] = gqlField({type: ft.datetime})
8686
}
87+
/*
88+
// - "who-is" columns to track user who created and last modified the record.
89+
if(config.wWhoIs){
90+
fields['c_uid'] = gqlField({type: 'date'})
91+
fields['u_uid'] = gqlField({type: 'date'})
92+
}
93+
*/
94+
// - tracking number of comments.
95+
if(config.wComments){
96+
fields['nb_comments'] = gqlField({type: ft.int})
97+
}
98+
// - tracking ratings.
99+
if(config.wRating){
100+
fields['nb_ratings'] = gqlField({type: ft.int})
101+
fields['avg_ratings'] = gqlField({type: ft.dec})
102+
}
103+
87104
return new GraphQLObjectType({
88105
name: m.id,
89106
fields: fields,
@@ -173,7 +190,7 @@ const makeGQLschema = () => {
173190
const RootQuery = new GraphQLObjectType({
174191
name: 'RootQueryType',
175192
fields: makeGQLschema(),
176-
description: 'Evolutility'
193+
description: 'Evolutility active models.'
177194
})
178195

179196
module.exports = new GraphQLSchema({

js/routes.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ if(config.schemaQueries){
4545
router.get(apiPath+':entity/stats', stats.numbers);
4646

4747
// ====== CRUD ====================================
48-
// - GET MANY ------------------------------------
48+
// - GET MANY -
4949
router.get(apiPath+':entity', crud.getMany);
50-
// - GET ONE ------------------------------------
50+
// - GET ONE -
5151
router.get(apiPath+':entity/:id', crud.getOne);
52-
// - INSERT ONE ------------------------------------
52+
// - INSERT ONE -
5353
router.post(apiPath+':entity', crud.insertOne);
54-
// - UPDATE ONE ------------------------------------
54+
// - UPDATE ONE -
5555
router.patch(apiPath+':entity/:id', crud.updateOne);
5656
router.put(apiPath+':entity/:id', crud.updateOne);
5757
router.post(apiPath+':entity/upload/:id', upload.uploadOne);
58-
// - DELETE ONE ------------------------------------
58+
// - DELETE ONE -
5959
router.delete(apiPath+':entity/:id', crud.deleteOne);
60-
// - LOV -----------------------------------------
60+
// - LOV -
6161
router.get(apiPath+':entity/lov/:field', crud.lovOne);
62-
// - SUB-COLLECTIONS ------------------------------------
62+
// - SUB-COLLECTIONS -
6363
router.get(apiPath+':entity/collec/:collec', crud.getCollec);
6464

6565
// ====== GET CHARTS ====================================

js/setup/database.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function sqlSchemaWithData(){
187187
}
188188
}
189189

190-
const sqlComment = (target, targetName, targetId) => 'COMMENT ON '+target+' '+targetName+' IS \''+targetId.replace(/'/g,'')+'\';\n'
190+
const sqlComment = (target, targetName, targetId) => 'COMMENT ON '+target+' '+targetName+' IS \''+(targetId?targetId.replace(/'/g,''):'')+'\';\n'
191191

192192
const sqlIndex = (index, table, column) => 'CREATE INDEX idx_'+index+' ON '+table+' USING btree ('+column+');\n';
193193
/*
@@ -336,11 +336,11 @@ function createSchema(runSQL = true, logFile = true){
336336
dbConfig.idleTimeoutMillis = 30000; // max client idle time before being closed
337337
const pool = new pg.Pool(dbConfig);
338338

339+
if(logFile) {
340+
logToFile(sql, false)
341+
}
339342
pool.connect(function(err, client, done) {
340343
// - Create schema and tables
341-
if(logFile) {
342-
logToFile(sql, false)
343-
}
344344
client.query(sql, function(err, data) {
345345
if(err){
346346
done();

js/utils/errors.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function badRequest(res, msg, errorCode = 400) {
66
logger.logError(msg)
77
res.statusMessage = errorMsg
88
res.status(errorCode).end();
9+
return res
910
}
1011

1112
module.exports = {

models/all_models.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/*
2+
___ _ _ _ _ _ _
3+
| __|_ _____| |_ _| |_(_) (_) |_ _ _
4+
| _|\ V / _ \ | || | _| | | | _| || |
5+
|___|\_/\___/_|\_,_|\__|_|_|_|\__|\_, |
6+
|__/
7+
https://github.com/evoluteur/evolutility-models
8+
*/
9+
110
module.exports = {
211
todo: require('./pim/todo'),
312
contact: require('./pim/contact'),

models/data/all_data.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*
2+
___ _ _ _ _ _ _
3+
| __|_ _____| |_ _| |_(_) (_) |_ _ _
4+
| _|\ V / _ \ | || | _| | | | _| || |
5+
|___|\_/\___/_|\_,_|\__|_|_|_|\__|\_, |
6+
|__/
7+
https://github.com/evoluteur/evolutility-models
8+
*/
19

210
module.exports = {
311
todo: require('./pim/todo-data'),

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@
1111
},
1212
"bugs": "https://github.com/evoluteur/evolutility-server-node/issues",
1313
"scripts": {
14-
"start": "supervisor ./bin/www"
14+
"start": "supervisor ./bin/www",
15+
"makedb": "node js/setup/database.js"
1516
},
1617
"dependencies": {
1718
"chalk": "~2.4.2",
1819
"body-parser": "~1.18.3",
1920
"csv-express": "~1.2.2",
2021
"debug": "~4.1.1",
21-
"express": "~4.16.4",
22-
"express-graphql": "~0.7.1",
22+
"express": "~4.17.1",
23+
"express-graphql": "~0.8.0",
24+
"graphql": "~14.4.2",
2325
"formidable": "~1.2.1",
24-
"graphql": "~14.1.1",
25-
"helmet": "~3.15.0",
26-
"pg": "^7.8.0",
27-
"pg-connection-string": "~2.0.0",
28-
"pg-promise": "^8.6.4",
26+
"helmet": "~3.18.0",
27+
"pg": "^7.11.0",
28+
"pg-connection-string": "~2.1.0",
29+
"pg-promise": "^8.7.3",
2930
"shortid": "~2.2.14",
3031
"supervisor": "~0.12.0",
3132
"underscore": "~1.9.1"
@@ -37,6 +38,7 @@
3738
"MDA",
3839
"platform",
3940
"REST",
41+
"GraphQL",
4042
"metadata",
4143
"database",
4244
"nodejs",

0 commit comments

Comments
 (0)