Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8fcd380

Browse files
Final updated before publish
1 parent a0f4b08 commit 8fcd380

File tree

3 files changed

+81
-67
lines changed

3 files changed

+81
-67
lines changed

‎LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2017 copyright Adnan Rahić
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

‎handler.js

Lines changed: 61 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,90 +6,85 @@ const Note = require('./models/Note');
66

77
module.exports.create = (event, context, callback) => {
88
context.callbackWaitsForEmptyEventLoop = false;
9-
10-
connectToDatabase()
11-
.then(() => {
9+
return connectToDatabase()
10+
.then(() =>
1211
Note.create(JSON.parse(event.body))
13-
.then(note=>callback(null,{
14-
statusCode: 200,
15-
body: JSON.stringify(note)
16-
}))
17-
.catch(err=>callback(null,{
18-
statusCode: err.statusCode||500,
19-
headers: {'Content-Type': 'text/plain'},
20-
body: 'Could not create the note.'
21-
}));
22-
});
23-
};
12+
)
13+
.then(note=>callback(null,{
14+
statusCode: 200,
15+
body: JSON.stringify(note)
16+
}))
17+
.catch(err=>callback(null,{
18+
statusCode: err.statusCode||500,
19+
headers: {'Content-Type': 'text/plain'},
20+
body: 'Could not create the note.'
21+
}));
22+
}
2423

2524
module.exports.getOne = (event, context, callback) => {
2625
context.callbackWaitsForEmptyEventLoop = false;
27-
28-
connectToDatabase()
29-
.then(() => {
26+
return connectToDatabase()
27+
.then(() =>
3028
Note.findById(event.pathParameters.id)
31-
.then(note=>callback(null,{
32-
statusCode: 200,
33-
body: JSON.stringify(note)
34-
}))
35-
.catch(err=>callback(null,{
36-
statusCode: err.statusCode||500,
37-
headers: {'Content-Type': 'text/plain'},
38-
body: 'Could not fetch the note.'
39-
}));
40-
});
29+
)
30+
.then(note=>callback(null,{
31+
statusCode: 200,
32+
body: JSON.stringify(note)
33+
}))
34+
.catch(err=>callback(null,{
35+
statusCode: err.statusCode||500,
36+
headers: {'Content-Type': 'text/plain'},
37+
body: 'Could not fetch the note.'
38+
}));
4139
};
4240

4341
module.exports.getAll = (event, context, callback) => {
4442
context.callbackWaitsForEmptyEventLoop = false;
45-
46-
connectToDatabase()
47-
.then(() => {
43+
return connectToDatabase()
44+
.then(() =>
4845
Note.find()
49-
.then(notes=>callback(null,{
50-
statusCode: 200,
51-
body: JSON.stringify(notes)
52-
}))
53-
.catch(err=>callback(null,{
54-
statusCode: err.statusCode||500,
55-
headers: {'Content-Type': 'text/plain'},
56-
body: 'Could not fetch the notes.'
57-
}))
58-
});
46+
)
47+
.then(notes=>callback(null,{
48+
statusCode: 200,
49+
body: JSON.stringify(notes)
50+
}))
51+
.catch(err=>callback(null,{
52+
statusCode: err.statusCode||500,
53+
headers: {'Content-Type': 'text/plain'},
54+
body: 'Could not fetch the notes.'
55+
}))
5956
};
6057

6158
module.exports.update = (event, context, callback) => {
6259
context.callbackWaitsForEmptyEventLoop = false;
63-
64-
connectToDatabase()
65-
.then(() => {
60+
return connectToDatabase()
61+
.then(() =>
6662
Note.findByIdAndUpdate(event.pathParameters.id, JSON.parse(event.body), { new: true })
67-
.then(note=>callback(null,{
68-
statusCode: 200,
69-
body: JSON.stringify(note)
70-
}))
71-
.catch(err=>callback(null,{
72-
statusCode: err.statusCode||500,
73-
headers: {'Content-Type': 'text/plain'},
74-
body: 'Could not fetch the notes.'
75-
}));
76-
});
63+
)
64+
.then(note=>callback(null,{
65+
statusCode: 200,
66+
body: JSON.stringify(note)
67+
}))
68+
.catch(err=>callback(null,{
69+
statusCode: err.statusCode||500,
70+
headers: {'Content-Type': 'text/plain'},
71+
body: 'Could not fetch the notes.'
72+
}));
7773
};
7874

7975
module.exports.delete = (event, context, callback) => {
8076
context.callbackWaitsForEmptyEventLoop = false;
81-
82-
connectToDatabase()
83-
.then(() => {
77+
return connectToDatabase()
78+
.then(() =>
8479
Note.findByIdAndRemove(event.pathParameters.id)
85-
.then(note=>callback(null,{
86-
statusCode: 200,
87-
body: JSON.stringify({message: 'Removed note with id: '+note._id,note: note})
88-
}))
89-
.catch(err=>callback(null,{
90-
statusCode: err.statusCode||500,
91-
headers: {'Content-Type': 'text/plain'},
92-
body: 'Could not fetch the notes.'
93-
}));
94-
});
80+
)
81+
.then(note=>callback(null,{
82+
statusCode: 200,
83+
body: JSON.stringify({message: 'Removed note with id: '+note._id,note: note})
84+
}))
85+
.catch(err=>callback(null,{
86+
statusCode: err.statusCode||500,
87+
headers: {'Content-Type': 'text/plain'},
88+
body: 'Could not fetch the notes.'
89+
}));
9590
};

‎package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /