Skip to content

Commit

Permalink
fix(app): Fix relationships errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Tallyb committed Oct 12, 2016
1 parent caa66bf commit 29716d1
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 26 deletions.
11 changes: 11 additions & 0 deletions common/models/author.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
"type": "string",
"required": true
},
"Genre": {
"type": "string",
"required": false,
"enum": [
"HUMOR",
"SCI_FI",
"HORROR",
"ROMANCE",
"NON_FICTION"
]
},
"birth_date": {
"type": "date",
"required": true
Expand Down
4 changes: 2 additions & 2 deletions common/models/note.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"validations": [],
"relations": {
"authors": {
"type": "hasOne",
"author": {
"type": "belongsTo",
"model": "Author",
"foreignKey": ""
}
Expand Down
18 changes: 14 additions & 4 deletions data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@
"ACL": 1,
"RoleMapping": 1,
"Role": 1,
"Note": 1,
"Author": 2
"Note": 6,
"Author": 6
},
"models": {
"User": {},
"AccessToken": {},
"ACL": {},
"RoleMapping": {},
"Role": {},
"Note": {},
"Note": {
"1": "{\"title\":\"1st note\",\"content\":\"Hope it will work\",\"id\":1}",
"2": "{\"title\":\"Who is Afraid\",\"content\":\"Hope it will work\",\"authorId\":3,\"id\":2}",
"3": "{\"title\":\"A room with a View\",\"content\":\"Hope it will work\",\"authorId\":3,\"id\":3}",
"4": "{\"title\":\"2nd note\",\"content\":\"Hope it will work\",\"authorId\":4,\"id\":4}",
"5": "{\"title\":\"Of Mice and Men\",\"content\":\"A long one\",\"authorId\":4,\"id\":5}"
},
"Author": {
"1": "{\"first_name\":\"John\",\"last_name\":\"Steinback\",\"birth_date\":\"2016-10-06T00:00:00.000Z\",\"id\":1}"
"1": "{\"first_name\":\"Ernest\",\"last_name\":\"Hemingway\",\"birth_date\":\"1960-02-29T22:00:00.000Z\",\"id\":1}",
"2": "{\"first_name\":\"Mark\",\"last_name\":\"Twain\",\"birth_date\":\"2016-10-08T18:22:58.307Z\",\"id\":2}",
"3": "{\"first_name\":\"Virginia\",\"last_name\":\"Wolf\",\"birth_date\":\"1960-02-29T22:00:00.000Z\",\"id\":3}",
"4": "{\"first_name\":\"John\",\"last_name\":\"Steinback\",\"Genre\":\"HUMOR\",\"birth_date\":\"2016-10-12T00:00:00.000Z\",\"id\":4}",
"5": "{\"first_name\":\"Tony\",\"last_name\":\"Morrison\",\"birth_date\":\"1943-12-31T22:00:00.000Z\",\"id\":5}"
}
}
}
10 changes: 5 additions & 5 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const typesMapping = {
Date: 'Date'
};

function validProps(model){
return _.omitBy(model.definition.properties, p=>{
function validProps(model) {
return _.omitBy(model.definition.properties, p => {
return p.deprecated;
});
}
Expand Down Expand Up @@ -43,9 +43,9 @@ function propsTypes(model) {
.join(' \n ');
}

function validRelations (model) {
return _.omitBy(model.relations, r=>{
return !r.shared;
function validRelations(model) {
return _.omitBy(model.relations, r => {
return !r.modelTo.shared;
});
}

Expand Down
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
"test": "mocha --reporter spec --timeout 10000",
"start": "node server/server.js",
"nodemon": "nodemon server/server.js",
"vocha:coverage": "istanbul cover --root . --include-all-sources --dir ./coverage --report text --report text-summary --report lcov --print none _mocha -- test/**/*.spec.js --require test/test.helpers.js --reporter spec --timeout 10000",
"mocha:watch": "mocha -R nyan -w --timeout 10000",
"publish:patch": "npm-bump patch && npm publish",
"publish:minor": "npm-bump minor && npm publish"
"mocha:coverage": "istanbul cover --root . --include-all-sources --dir ./coverage --report text --report text-summary --report lcov --print none _mocha -- test/**/*.spec.js --require test/test.helpers.js --reporter spec --timeout 10000",
"mocha:watch": "mocha -R nyan -w --timeout 10000"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -48,17 +46,17 @@
},
"devDependencies": {
"apollo-client": "^0.4.20",
"babel-eslint": "^6.1.2",
"babel-eslint": "^7.0.0",
"bluebird": "^3.4.6",
"chai": "^3.5.0",
"chai-http": "^3.0.0",
"compression": "^1.0.3",
"conventional-changelog-cli": "^1.2.0",
"cors": "^2.5.2",
"cpy-cli": "^1.0.1",
"eslint": "^2.13.1",
"eslint": "^3.7.1",
"eslint-plugin-nodeca": "^1.0.3",
"helmet": "^1.3.0",
"helmet": "^2.3.0",
"istanbul": "^0.4.5",
"loopback": "^2.22.0",
"loopback-boot": "^2.6.5",
Expand All @@ -72,4 +70,4 @@
"standard-version": "^3.0.0",
"strong-error-handler": "^1.0.1"
}
}
}
5 changes: 0 additions & 5 deletions server/boot/graphql.js

This file was deleted.

2 changes: 1 addition & 1 deletion server/datasources.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"db": {
"name": "db",
"connector": "memory",
"file": "../data.json"
"file": "./data.json"
}
}
2 changes: 1 addition & 1 deletion server/model-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"Note": {
"dataSource": "db",
"public": true
"public": true
},
"Author": {
"dataSource": "db",
Expand Down

0 comments on commit 29716d1

Please sign in to comment.