-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathhandler.js
61 lines (53 loc) · 1.52 KB
/
handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict'
const Create = require('./handlers/create.js')
const List = require('./handlers/list.js')
const ReadAll = require('./handlers/read-all.js')
const ReadOne = require('./handlers/read-one.js')
const Update = require('./handlers/update.js')
const Delete = require('./handlers/delete.js')
function makeResponse(error, result) {
const statusCode = error && error.statusCode || 200
return {
statusCode,
headers: {
"Access-Control-Allow-Origin" : "*"
},
body: JSON.stringify(result),
}
}
exports.create = (event, context, callback) => {
Create(event, (error, result) => {
const response = makeResponse(error, result)
context.succeed(response)
})
}
exports.list = (event, context, callback) => {
List(event, (error, result) => {
const response = makeResponse(error, result)
context.succeed(response)
})
}
exports.readAll = (event, context, callback) => {
ReadAll(event, (error, result) => {
const response = makeResponse(error, result)
context.succeed(response)
})
}
exports.readOne = (event, context, callback) => {
ReadOne(event, (error, result) => {
const response = makeResponse(error, result)
context.succeed(response)
})
}
exports.update = (event, context, callback) => {
Update(event, (error, result) => {
const response = makeResponse(error, result)
context.succeed(response)
})
}
exports.delete = (event, context, callback) => {
Delete(event, (error, result) => {
const response = makeResponse(error, result)
context.succeed(response)
})
}