-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.js
More file actions
260 lines (215 loc) · 5.75 KB
/
handler.js
File metadata and controls
260 lines (215 loc) · 5.75 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
const AWS = require("aws-sdk");
AWS.config.update({ region: 'us-east-1' });
const express = require("express");
const serverless = require("serverless-http");
const app = express();
const port = 3000
const USERS_TABLE = "SampleTable";// process.env.USERS_TABLE;
const dynamoDbClient = new AWS.DynamoDB.DocumentClient(
{ endpoint: "http://localhost:8000" }
);
app.use(express.json());
app.post("/provider-cicd-create", async function (req, res) {
const { userId, name, cicd_id } = req.body;
// if (typeof userId !== "string") {
// res.status(400).json({ error: '"userId" must be a string' });
// } else if (typeof name !== "string") {
// res.status(400).json({ error: '"name" must be a string' });
// }
console.log('TABLE TO SAVE ', "providers_cicd");
const id = AWS.util.uuid.v4()
const params = {
TableName: "providers_cicd",
Item: {
name: name,
logo: "",
id: id
},
};
try {
await dynamoDbClient.put(params).promise();
res.json({ "SAVE CICD": "......." });
// res.json({ userId, name });
} catch (error) {
console.log(error);
res.status(500).json({ error: "Could not create user" });
}
});
app.post("/create-frameworks", async function (req, res) {
const { userId, name, cicd_id } = req.body;
// if (typeof userId !== "string") {
// res.status(400).json({ error: '"userId" must be a string' });
// } else if (typeof name !== "string") {
// res.status(400).json({ error: '"name" must be a string' });
// }
console.log('TABLE TO SAVE ', "cicd");
const id = AWS.util.uuid.v4()
var frameworks = [
{
"name": "react",
"cicd_id": "4ec5cc7c-aaf9-4d8f-86f1-e0192d0e8828",
"logo": "",
"id": "",
"type": "front"
},
{
"name": "angular",
"cicd_id": "4ec5cc7c-aaf9-4d8f-86f1-e0192d0e8828",
"logo": "",
"id": "",
"type": "front"
},
{
"name": "vue",
"cicd_id": "4ec5cc7c-aaf9-4d8f-86f1-e0192d0e8828",
"logo": "",
"id": "",
"type": "front"
},
{
"name": "laravel",
"cicd_id": "4ec5cc7c-aaf9-4d8f-86f1-e0192d0e8828",
"logo": "",
"id": "",
"type": "front"
},
{
"name": "django",
"cicd_id": "4ec5cc7c-aaf9-4d8f-86f1-e0192d0e8828",
"logo": "",
"id": "",
"type": "front"
},
{
"name": "nodejs",
"cicd_id": "4ec5cc7c-aaf9-4d8f-86f1-e0192d0e8828",
"logo": "",
"id": "",
"type": "back"
},
{
"name": "react natine",
"cicd_id": "4ec5cc7c-aaf9-4d8f-86f1-e0192d0e8828",
"logo": "",
"id": "",
"type": "movile"
},
{
"name": "swift",
"cicd_id": "4ec5cc7c-aaf9-4d8f-86f1-e0192d0e8828",
"logo": "",
"id": "",
"type": "movile"
}
]
const posts = await Promise.all(
frameworks.map(async (framework) => {
todo = {
TableName: "frameworks",
Item: {
name: framework.name,
cicd_id: framework.cicd_id,
logo: "",
type: framework.type,
id: AWS.util.uuid.v4()
},
};
console.log('Xxxxxxxxxxxxxxxxxxxx', AWS.util.uuid.v4());
return await dynamoDbClient.put(todo).promise();
})
)
console.log('SAVING FRAMWWORKS.... ');
try {
//await dynamoDbClient.put(params).promise();
res.json({ "OK": "......." });
// res.json({ userId, name });
} catch (error) {
console.log(error);
res.status(500).json({ error: "Could not create user" });
}
});
// WHY DOES NOT QUERY BY CICD KEY
app.get("/frameworks/:cicd_id", async function (req, res) {
console.log('cicd ID', req.params.cicd_id);
const params = {
TableName: "frameworks",
keys: [
{
cicd_id: req.params.cicd_id
},
]
};
try {
const { Item } = await dynamoDbClient.get(params).promise();
if (Item) {
const { name, id, logo } = Item;
res.json({ name, id });
} else {
res
.status(404)
.json({ error: 'Could not find user with provided "framework"' });
}
} catch (error) {
console.log(error);
res.status(500).json({ error: "Could not retreive user" });
}
});
app.post("/concepto", async function (req, res) {
const { userId, name, cicd_id } = req.body;
// if (typeof userId !== "string") {
// res.status(400).json({ error: '"userId" must be a string' });
// } else if (typeof name !== "string") {
// res.status(400).json({ error: '"name" must be a string' });
// }
console.log('TABLE TO SAVE ', "cicd");
const id = AWS.util.uuid.v4()
const params = {
AttributeDefinitions: [
{
AttributeName: "Season", //ATTRIBUTE_NAME_1
AttributeType: "N", //ATTRIBUTE_TYPE
},
{
AttributeName: "Episode", //ATTRIBUTE_NAME_2
AttributeType: "N", //ATTRIBUTE_TYPE
},
],
KeySchema: [
{
AttributeName: "Season", //ATTRIBUTE_NAME_1
KeyType: "HASH",
},
{
AttributeName: "Episode", //ATTRIBUTE_NAME_2
KeyType: "RANGE",
},
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
TableName: "TEST_TABLE", //TABLE_NAME
StreamSpecification: {
StreamEnabled: false,
},
};
const data = await ddbClient.send(new xx(params));
console.log('TEST DE CONDEPTOS.... ');
try {
//await dynamoDbClient.put(params).promise();
res.json({ "OK": "......." });
// res.json({ userId, name });
} catch (error) {
console.log(error);
res.status(500).json({ error: "Could not create user" });
}
});
app.use((req, res, next) => {
return res.status(404).json({
error: "Not Found",
});
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
module.exports.handler = serverless(app);