Skip to content
This repository was archived by the owner on Jul 15, 2021. It is now read-only.

Commit 8207c90

Browse files
committed
Server bugs
1 parent fa534e1 commit 8207c90

File tree

5 files changed

+43
-49
lines changed

5 files changed

+43
-49
lines changed

server/models/category.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
var _ = require('lodash');
22

33
var categories = [
4-
{"id": 1, "name": "Testing", "icon": "tumblr"},
5-
{"id": 2, "name": "Personal Note", "icon": "pencil"},
6-
{"id": 3, "name": "Bash", "icon": "terminal"},
7-
{"id": 4, "name": "Idea", "icon": "lightbulb"},
8-
{"id": 5, "name": "Use with Caution","icon": "warning"},
9-
{"id": 6, "name": "Question", "icon": "question"},
10-
{"id": 7, "name": "Best Practice","icon": "thumbs up outline"},
11-
{"id": 8, "name": "Code Snippet", "icon": "code"}
4+
{"id": 1, "name": "Testing"},
5+
{"id": 2, "name": "Personal Note"},
6+
{"id": 3, "name": "Bash"},
7+
{"id": 4, "name": "Idea"},
8+
{"id": 5, "name": "Use with Caution"},
9+
{"id": 6, "name": "Question"},
10+
{"id": 7, "name": "Best Practice"},
11+
{"id": 8, "name": "Code Snippet"}
1212
]
1313

1414
module.exports = {

server/models/note.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ var _ = require('lodash');
22
var Category = require('./category')
33
var User = require('./user')
44
var notes = [
5-
{"id":1 ,"userId": 13, "categoryId": 8, "link" :"https://www.youtube.com/watch?feature=player_detailpage&v=ZhfUv0spHCY#t=1870", "description": "NgModel Best Practice", "content" : "Always use dot syntax when using NgModel! Treat Scope as read-only in templates & write-only in controllers. The purpose of the scope is to refer to the model, not be the model. The model is your javascript objects. When doing bidirectional binding with ngModel make sure you don't bind directly to the scope properties. This will cause unexpected behavior in the child scopes.", "title" : "NgModel BP", "icon" : "basic info"},
6-
{"id":2 ,"userId": 2, "categoryId": 3, "link" : "https://docs.angularjs.org/api/ng#directive", "description" : "Markers on a **DOM element** that tell AngularJS's HTML compiler `$compile` to attach a specified behavior to that DOM element.", "title" : "Directives", "icon" : "code", "content": "Markers on a **DOM element**"},
7-
{"id":3 ,"userId": 1, "categoryId": 6, "link" : "", "description" : "Clarify the confusion between Service the term and `service` the angular method and to explain the 5 different Service recipes in Angular.", "title" : "Service Service? Really Angular?","content": "There are 5 Recipes used to create a Service. One of those *was* unfortunately named, Service. So yes, amongst its fellow peers such as Provider Service and Factory Service, there is in fact a Service Service.", "icon" : "question"},
8-
{"id":4 ,"userId": 2, "categoryId": 6, "link" : "", "description" : "QUESTIONABLE DESCRIPTION GOES HERE", "title" : "TEST TEST TEST", "content": "QUESTIONABLE CONTENT GOES HERE", "icon" : "question"},
9-
{"id":5 ,"userId": 4, "categoryId": 6, "link" : "", "description" : "Define Service", "title" : "What is a Service", "content": "Service: Angular services are objects that are wired together using dependency injection (DI). You can use services to organize and share code across your app.", "icon" : "question"},
10-
{"id":6 ,"userId": 5, "categoryId": 6, "description" : "Steps for Creating a Service", "title" : "How do you create a Service?", "content": "You can register a service to our Angular module `app` with a one of the following 5 recipes: \\n - **factory** \\n - **provider** \\n - **service** \\n - **value** \\n - **constant** ", "icon" : "question"}
5+
{"id":1 ,"userId": 13, "categoryId": 8, "description": "NgModel Best Practice", "content" : "Always use dot syntax when using NgModel! Treat Scope as read-only in templates & write-only in controllers. The purpose of the scope is to refer to the model, not be the model. The model is your javascript objects. When doing bidirectional binding with ngModel make sure you don't bind directly to the scope properties. This will cause unexpected behavior in the child scopes.", "title" : "NgModel BP"},
6+
{"id":2 ,"userId": 2, "categoryId": 3, "description" : "Markers on a **DOM element** that tell AngularJS's HTML compiler `$compile` to attach a specified behavior to that DOM element.", "title" : "Directives", "content": "Markers on a **DOM element**"},
7+
{"id":3 ,"userId": 1, "categoryId": 6, "description" : "Clarify the confusion between Service the term and `service` the angular method and to explain the 5 different Service recipes in Angular.", "title" : "Service Service? Really Angular?","content": "There are 5 Recipes used to create a Service. One of those *was* unfortunately named, Service. So yes, amongst its fellow peers such as Provider Service and Factory Service, there is in fact a Service Service."},
8+
{"id":4 ,"userId": 2, "categoryId": 6, "description" : "QUESTIONABLE DESCRIPTION GOES HERE", "title" : "TEST TEST TEST", "content": "QUESTIONABLE CONTENT GOES HERE"},
9+
{"id":5 ,"userId": 4, "categoryId": 6, "description" : "Define Service", "title" : "What is a Service", "content": "Service: Angular services are objects that are wired together using dependency injection (DI). You can use services to organize and share code across your app."},
10+
{"id":6 ,"userId": 5, "categoryId": 6, "description" : "Steps for Creating a Service", "title" : "How do you create a Service?", "content": "You can register a service to our Angular module `app` with a one of the following 5 recipes: \\n - **factory** \\n - **provider** \\n - **service** \\n - **value** \\n - **constant** "}
1111
]
1212
var lastId = 6;
1313

@@ -51,7 +51,7 @@ module.exports = {
5151
for(var i=0, l=notes.length; i < l; i++) {
5252
if(notes[i].id === id){
5353
deletedNote = notes[i];
54-
notes.splice(0, i);
54+
notes.splice(i, 1);
5555
break;
5656
}
5757
}

server/models/user.js

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/routes/category.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
1-
var categories = [
2-
{"id": 1, "name": "Testing", "icon": "tumblr"},
3-
{"id": 2, "name": "Personal Note", "icon": "pencil"},
4-
{"id": 3, "name": "Bash", "icon": "terminal"},
5-
{"id": 4, "name": "Idea", "icon": "lightbulb"},
6-
{"id": 5, "name": "Use with Caution","icon": "warning"},
7-
{"id": 6, "name": "Question", "icon": "question"},
8-
{"id": 7, "name": "Best Practice","icon": "thumbs up outline"},
9-
{"id": 8, "name": "Code Snippet", "icon": "code"}
10-
]
1+
var Category = require('../models/category');
112

123
module.exports = function(app) {
134
// Return a list of available node types
145
app.get('/categories', function(req, res) {
15-
res.json(categories);
6+
res.json(Category.all());
167
});
178

189
app.get('/categories/:id', function(req, res) {
1910
var categoryId = parseInt(req.param('id'), 10);
20-
var selectedCategory = _.find(categories, function(category){
21-
return category.id === categoryId;
22-
});
23-
24-
res.json(selectedCategory || {});
11+
res.json(Category.get(categoryId) || {});
2512
});
2613
};

server/routes/note.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ module.exports = function(app) {
77
});
88

99
app.post('/notes', function(req, res) {
10-
res.json(Note.create(req.body));
10+
// Add a delay here to simulate the delay of a live server
11+
// So things like button isSubmitting states can be demonstrated
12+
setTimeout(function(){
13+
res.json(Note.create(req.body));
14+
}, 1000);
1115
});
1216

13-
app.put('/notes', function(req, res) {
14-
res.json(Note.update(req.body));
17+
app.put('/notes/:id', function(req, res) {
18+
// Add a delay here to simulate the delay of a live server
19+
// So things like button isSubmitting states can be demonstrated
20+
setTimeout(function(){
21+
res.json(Note.update(req.body));
22+
},1000)
1523
});
1624

1725
app.get('/notes/:id', function(req, res) {
@@ -20,7 +28,6 @@ module.exports = function(app) {
2028
});
2129

2230
app.delete('/notes/:id', function(req, res) {
23-
var noteId = parseInt(req.param('id'), 10);
24-
res.json(Note.delete(noteId) || {});
31+
res.json(Note.delete(parseInt(req.param('id'), 10)) || {});
2532
});
2633
};

0 commit comments

Comments
 (0)