-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.js
130 lines (117 loc) · 3.95 KB
/
tag.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
'use strict';
import uuid from "uuid";
import * as dynamoDbLib from "./libs/dynamodb-lib";
import { success, failure } from "./libs/response-lib";
const table = "LBS_Zone";
module.exports = {
create: async(event, context, callback) => {
const data = JSON.parse(event.body);
const params = {
TableName: table,
Item: {
tagId: uuid.v1(),
tagName: data.tagName,
accesses: data.accesses,
color: data.color,
size: data.size,
tagStatus: data.tagStatus,
mainArea: data.mainArea,
display: data.display,
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,
tagId: 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,
tagId: event.pathParameters.id
},
UpdateExpression: "SET tagName = :tagName, "+
"accesses = :accesses, "+
"color = :color, "+
"size = :size, "+
"tagStatus = :tagStatus, "+
"mainArea = :mainArea, "+
"display = :display, "+
"update_at = :update_at",
ExpressionAttributeValues: {
":tagName": data.tagName ? data.tagName : null,
":accesses": data.accesses ? data.accesses : null,
":color": data.color ? data.color : null,
":size": data.size ? data.size : null,
":tagStatus": data.tagStatus ? data.tagStatus : null,
":mainArea": data.mainArea ? data.mainArea : null,
":display": data.display ? data.display : 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 }));
}
}
/*
list: async (event, context, callback) => {
var params = {
RequestItems: {
[table]: {
Keys: [{
'zoneId':'sdfsdf'
}]
}
}
};
try {
const result = await dynamoDbLib.call("batchGet", params);
if (result.Responses[table][0]) {
// Return the retrieved item
callback(null, result.Responses[table]);
} else {
callback(null, failure({ status: false, error: "Item not found." }));
}
} catch (e) {
callback(null, failure(e));
}
}
*/
};