forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost-items-handler.ts
More file actions
30 lines (27 loc) · 1.02 KB
/
post-items-handler.ts
File metadata and controls
30 lines (27 loc) · 1.02 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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { v4 as uuidv4 } from "uuid";
import type { Handler } from "src/types/handler.js";
import type { Item } from "src/types/item.js";
import { buildStatementCommand } from "../statement-commands/command-helper.js";
const postItemsHandler: Handler = {
withClient:
({ rdsDataClient }) =>
async (req, res) => {
const { description, guide, status, name }: Item = req.body;
const values = {
description: { StringValue: description },
guide: { StringValue: guide },
status: { StringValue: status },
name: { StringValue: name },
};
const command = buildStatementCommand(
`insert into items (iditem, description, guide, status, username, archived)
values ("${uuidv4()}", ":description", ":guide", ":status", ":name", 0)`,
values,
);
await rdsDataClient.send(command);
res.status(200).send({});
},
};
export { postItemsHandler };