Nicklas Christiansen
03/07/2022, 9:11 PMfunction createEvent(content) {
return <http://API.post|API.post>("notes", "/events", {
body: content
});
}
I tried to add this to routes in ApiStack.js:
"POST /events": "src/createEvent.main",
With this createEvent:
import * as uuid from "uuid";
import handler from "./util/handler";
import dynamoDb from "./util/dynamodb";
export const main = handler(async (event) => {
const data = JSON.parse(event.body);
const params = {
TableName: process.env.TABLE_NAME,
Item: {
// The attributes of the item to be created
eventId: uuid.v1(), // A unique uuid
name: data.content, // Parsed from request body
max_players: data.max_players,
createdAt: Date.now(), // Current Unix timestamp
},
};
await dynamoDb.put(params);
return params.Item;
});
Added this to StorageStack.js:
this.table2 = new sst.Table(this, "Events", {
fields: {
eventId: sst.TableFieldType.STRING,
},
primaryIndex: { partitionKey: "eventId" },
});
Nicklas Christiansen
03/08/2022, 4:16 PM