-
Notifications
You must be signed in to change notification settings - Fork 0
/
notification.js
112 lines (102 loc) · 3.65 KB
/
notification.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
'use strict';
import uuid from "uuid";
import * as dynamoDbLib from "./libs/dynamodb-lib";
import { success, failure } from "./libs/response-lib";
const table = "LBS_Notification";
module.exports = {
create: async(event, context, callback) => {
const data = JSON.parse(event.body);
const params = {
TableName: table,
Item: {
areaId: uuid.v1(),
building: data.building,
cameras: data.cameras,
floor: data.floor,
height: data.height,
image: data.image,
areaName: data.areaName,
room: data.room,
width: data.width,
zones: data.zones,
areaStatus: data.areaStatus,
createdAt: new Date().getTime(),
update_at: new Date().getTime()
}
};
try {
await dynamoDbLib.call("put", params);
callback(null, success(params.Item));
} catch (e) {
callback(null, failure({ status: false }));
}
},
delete: async(event, context, callback) => {
const params = {
TableName: table,
Key: {
//userId: event.requestContext.identity.cognitoIdentityId,
areaId: event.pathParameters.id
}
};
try {
const result = await dynamoDbLib.call("delete", params);
callback(null, success({ status: true }));
} catch (e) {
callback(null, failure({ status: false }));
}
},
update: async(event, context, callback) => {
const data = JSON.parse(event.body);
const params = {
TableName: table,
Key: {
//userId: event.requestContext.identity.cognitoIdentityId,
areaId: event.pathParameters.id
},
UpdateExpression: "SET areaName = :areaName, "+
"building = :building, "+
"cameras = :cameras, "+
"floor = :floor, "+
"height = :height, "+
"image = :image, "+
"room = :room, "+
"width = :width, "+
"zones = :zones, "+
"areaStatus = :areaStatus, "+
"update_at = :update_at",
ExpressionAttributeValues: {
":areaName": data.areaName ? data.areaName : null,
":building": data.building ? data.building : null,
":cameras": data.cameras ? data.cameras : null,
":floor": data.floor ? data.floor : null,
":height": data.height ? data.height : null,
":image": data.image ? data.image : null,
":room": data.room ? data.room : null,
":width": data.width ? data.width : null,
":zones": data.zones ? data.zones : null,
":areaStatus": data.areaStatus ? data.areaStatus : null,
":update_at": new Date().getTime()
},
ReturnValues: "ALL_NEW"
};
try {
const result = await dynamoDbLib.call("update", params);
callback(null, success({ status: true }));
} catch (e) {
callback(null, failure(e));
}
},
list: async (event, context, callback) => {
const params = {
TableName: table
};
try {
const result = await dynamoDbLib.call("scan", params);
// Return the matching list of items in response body
callback(null, success(result.Items));
} catch (e) {
callback(null, failure({ status: false }));
}
}
};