Skip to content

Commit 5695268

Browse files
committed
basic put item integration done
need to send email notifications, etc
1 parent 58f50df commit 5695268

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/api/routes/roomRequests.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ import {
88
} from "common/types/roomRequest.js";
99
import { AppRoles } from "common/roles.js";
1010
import { zodToJsonSchema } from "zod-to-json-schema";
11-
import { randomUUID } from "crypto";
11+
import {
12+
BaseError,
13+
DatabaseInsertError,
14+
InternalServerError,
15+
} from "common/errors/index.js";
16+
import { PutItemCommand } from "@aws-sdk/client-dynamodb";
17+
import { genericConfig } from "common/config.js";
18+
import { marshall } from "@aws-sdk/util-dynamodb";
1219

1320
const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
1421
await fastify.register(rateLimiter, {
@@ -30,9 +37,31 @@ const roomRequestRoutes: FastifyPluginAsync = async (fastify, _options) => {
3037
},
3138
},
3239
async (request, reply) => {
33-
const id = randomUUID().toString();
40+
const requestId = request.id;
41+
if (!request.username) {
42+
throw new InternalServerError({
43+
message: "Could not retrieve username.",
44+
});
45+
}
46+
const body = { ...request.body, requestId, userId: request.username };
47+
try {
48+
await fastify.dynamoClient.send(
49+
new PutItemCommand({
50+
TableName: genericConfig.RoomRequestsTableName,
51+
Item: marshall(body),
52+
}),
53+
);
54+
} catch (e) {
55+
if (e instanceof BaseError) {
56+
throw e;
57+
}
58+
request.log.error(e);
59+
throw new DatabaseInsertError({
60+
message: "Could not save room request.",
61+
});
62+
}
3463
reply.status(201).send({
35-
id,
64+
id: requestId,
3665
status: RoomRequestStatus.CREATED,
3766
});
3867
},

src/ui/pages/roomRequest/NewRoomRequest.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,9 @@ const NewRoomRequest: React.FC<NewRoomRequestProps> = ({
562562
Back
563563
</Button>
564564
)}
565-
{active !== numSteps && <Button onClick={nextStep}>Next step</Button>}
565+
{active !== numSteps && (
566+
<Button onClick={nextStep}>{active === numSteps - 1 ? 'Review' : 'Next'}</Button>
567+
)}
566568
{active === numSteps && !disabled && (
567569
<Button onClick={handleSubmit} color="green">
568570
{isSubmitting ? (

0 commit comments

Comments
 (0)