Skip to content

Commit 49baa6c

Browse files
committed
remove checkin and add devPost attribute
1 parent 394db77 commit 49baa6c

16 files changed

Lines changed: 239 additions & 186 deletions

File tree

amplify/auth/PostConfirmation/handler.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export const handler: PostConfirmationTriggerHandler = async (event) => {
5858
role: "Participant",
5959
id: event.request.userAttributes.sub,
6060
email: event.request.userAttributes.email,
61-
checkedIn: false,
6261
willEatMeals: false,
6362
allergies: "",
6463
institution: "",

amplify/data/resource.ts

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ const schema = a
3535
completedRegistration: a.boolean(),
3636
allergies: a.string(),
3737
willEatMeals: a.boolean(),
38-
checkedIn: a
39-
.boolean()
40-
.default(false)
41-
.authorization((allow) => [
42-
allow.ownerDefinedIn("profileOwner").to(["read"]),
43-
allow.groups(["Admin"]).to(["read", "update", "delete", "create"]),
44-
]),
4538
teamId: a
4639
.id()
4740
.authorization((allow) => [
@@ -95,6 +88,12 @@ const schema = a
9588
members: a.hasMany("User", "teamId"),
9689
scores: a.hasMany("Score", "teamId"),
9790
teamRooms: a.hasMany("TeamRoom", "teamId"),
91+
devPostLink: a
92+
.string()
93+
.authorization((allow) => [
94+
allow.groups(["Admin"]).to(["read", "update"]),
95+
allow.authenticated().to(["read", "update"]),
96+
]),
9897
})
9998
.authorization((allow) => [
10099
allow.group("Admin").to(["read", "update", "create", "delete"]),
@@ -280,21 +279,6 @@ const schema = a
280279
.authorization((allow) => [allow.group("Admin")])
281280
.handler(a.handler.function(ResetHackathon))
282281
.returns(a.ref("StatusCodeFunctionResponse")),
283-
284-
// Custom resolvers
285-
SetUserAsCheckedIn: a
286-
.mutation()
287-
.arguments({
288-
userId: a.string().required(),
289-
})
290-
.returns(a.ref("User"))
291-
.authorization((allow) => [allow.authenticated()])
292-
.handler(
293-
a.handler.custom({
294-
dataSource: a.ref("User"),
295-
entry: "./user/SetUserAsCheckedIn.js",
296-
}),
297-
),
298282
})
299283

300284
.authorization((allow) => [

amplify/data/user/SetUserAsCheckedIn.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

amplify/function/BusinessLogic/CreateTeamWithCode/handler.ts

Lines changed: 75 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { generateClient } from "aws-amplify/data";
33
import type { AppSyncIdentityCognito } from "aws-lambda";
44

55
import type { Schema } from "../../../data/resource";
6+
import { tryCatch } from "../utils/try-catch";
67
import { createTeam, updateUser } from "./graphql/mutations";
78
import { getTeam } from "./graphql/queries";
89

@@ -38,101 +39,89 @@ const client = generateClient<Schema>({
3839
authMode: "iam",
3940
});
4041

42+
const createNewTeam = (teamName: string, teamId: string) =>
43+
client.graphql({
44+
query: createTeam,
45+
variables: {
46+
input: {
47+
name: teamName,
48+
id: teamId,
49+
},
50+
},
51+
});
52+
const updateUserTeam = (id: string, teamId: string) =>
53+
client.graphql({
54+
query: updateUser,
55+
variables: {
56+
input: {
57+
id,
58+
teamId,
59+
},
60+
},
61+
});
62+
const generateTeamId = () =>
63+
Array.from(Array(4), () =>
64+
Math.floor(Math.random() * 36)
65+
.toString(36)
66+
.toUpperCase(),
67+
).join("");
68+
const getTeamFromId = (teamId: string) =>
69+
client.graphql({
70+
query: getTeam,
71+
variables: {
72+
id: teamId,
73+
},
74+
});
4175
export const handler: Schema["CreateTeamWithCode"]["functionHandler"] = async (
4276
event,
4377
) => {
44-
let team = null;
45-
let teamId: string | null = null;
46-
try {
47-
do {
48-
teamId = Array.from(Array(4), () =>
49-
Math.floor(Math.random() * 36)
50-
.toString(36)
51-
.toUpperCase(),
52-
).join("");
53-
54-
team = (
55-
await client.graphql({
56-
query: getTeam,
57-
variables: {
58-
id: teamId,
59-
},
60-
})
61-
).data.getTeam;
62-
} while (team != null);
78+
const {
79+
arguments: { addCallerToTeam, teamName },
80+
} = event;
6381

64-
const teamCreation = await client
65-
.graphql({
66-
query: createTeam,
67-
variables: {
68-
input: {
69-
name: event.arguments.teamName,
70-
id: teamId,
71-
},
72-
},
73-
})
74-
.catch(() => {
75-
throw new Error(
76-
JSON.stringify({
77-
body: { value: `Error creating team` },
78-
statusCode: 500,
79-
headers: { "Content-Type": "application/json" },
80-
}),
81-
);
82-
});
83-
84-
if (teamCreation) {
85-
if (event.arguments.addCallerToTeam) {
86-
return await client
87-
.graphql({
88-
query: updateUser,
89-
variables: {
90-
input: {
91-
id: (event.identity as AppSyncIdentityCognito).sub,
92-
teamId: teamId,
93-
},
94-
},
95-
})
96-
.then(() => {
97-
return {
98-
body: { value: teamId },
99-
statusCode: 200,
100-
headers: { "Content-Type": "application/json" },
101-
};
102-
})
103-
.catch(() => {
104-
throw new Error(
105-
JSON.stringify({
106-
body: { value: `Error updating user (team was created)` },
107-
statusCode: 500,
108-
headers: { "Content-Type": "application/json" },
109-
}),
110-
);
111-
});
112-
} else {
113-
return {
114-
body: { value: teamId },
115-
statusCode: 200,
116-
headers: { "Content-Type": "application/json" },
117-
};
118-
}
119-
} else {
120-
throw new Error(
121-
JSON.stringify({
122-
body: { value: `Error creating team` },
123-
statusCode: 500,
124-
headers: { "Content-Type": "application/json" },
125-
}),
126-
);
127-
}
128-
} catch (error) {
129-
console.error(error);
82+
let teamId = generateTeamId();
83+
let { error: teamIdTaken } = await tryCatch(getTeamFromId(teamId));
84+
while (teamIdTaken) {
85+
teamId = generateTeamId();
86+
({ error: teamIdTaken } = await tryCatch(getTeamFromId(teamId)));
87+
} // possibility of infite loop at 36^4 teams
88+
const { error: createTeamError } = await tryCatch(
89+
createNewTeam(teamName, teamId),
90+
);
91+
if (createTeamError) {
13092
throw new Error(
13193
JSON.stringify({
132-
body: { value: `Unhandled Internal Server Error` },
94+
body: { value: `Error creating team` },
13395
statusCode: 500,
13496
headers: { "Content-Type": "application/json" },
13597
}),
13698
);
13799
}
100+
if (!addCallerToTeam) {
101+
return {
102+
body: { value: teamId },
103+
statusCode: 200,
104+
headers: { "Content-Type": "application/json" },
105+
};
106+
}
107+
const { error: updateUserError, data: updateUserSuccess } = await tryCatch(
108+
updateUserTeam((event.identity as AppSyncIdentityCognito).sub, teamId),
109+
);
110+
if (updateUserSuccess) {
111+
return {
112+
body: { value: teamId },
113+
statusCode: 200,
114+
headers: { "Content-Type": "application/json" },
115+
};
116+
}
117+
118+
throw new Error(
119+
JSON.stringify({
120+
body: {
121+
value: `Error updating user ( ${(event.identity as AppSyncIdentityCognito).sub}) (team was created) ${updateUserError}`,
122+
},
123+
statusCode: 500,
124+
headers: { "Content-Type": "application/json" },
125+
}),
126+
);
138127
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Types for the result object with discriminated union
2+
type Success<T> = {
3+
data: T;
4+
error: null;
5+
};
6+
7+
type Failure<E> = {
8+
data: null;
9+
error: E;
10+
};
11+
12+
type Result<T, E = Error> = Success<T> | Failure<E>;
13+
14+
// Main wrapper function
15+
export async function tryCatch<T, E = Error>(
16+
promise: Promise<T>,
17+
): Promise<Result<T, E>> {
18+
try {
19+
const data = await promise;
20+
return { data, error: null };
21+
} catch (error) {
22+
return { data: null, error: error as E };
23+
}
24+
}

src/app/admin/teams/TeamTableSetup.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ export const teamColumns = [
4949
filterFn: "includesString",
5050
sortingFn: "alphanumeric",
5151
}),
52-
columnHelper.accessor("members", {
53-
cell: (info) =>
54-
info.getValue().every((member) => member.checkedIn)
55-
? "Checked In"
56-
: "Not Checked In",
57-
header: "Check-in Status",
58-
sortingFn: "basic",
59-
}),
6052
columnHelper.accessor("approved", {
6153
cell: ({
6254
getValue,
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
1-
import type { Schema } from "@/amplify/data/resource";
21
import client from "@/components/_Amplify/AmplifyBackendClient";
32

43
import TeamsTable from "./TeamsTable";
54

6-
type Members = Pick<
7-
Schema["User"]["type"],
8-
"id" | "firstName" | "lastName" | "checkedIn"
9-
>;
10-
export type Team = Pick<Schema["Team"]["type"], "name" | "approved" | "id"> & {
11-
members: Members[];
12-
};
5+
const getTeams = client.models.Team.list({
6+
selectionSet: [
7+
"name",
8+
"approved",
9+
"id",
10+
"devPostLink",
11+
"members.id",
12+
"members.firstName",
13+
"members.lastName",
14+
],
15+
});
16+
export type Team = Awaited<typeof getTeams>["data"][number];
1317
export default async function TeamsTablePage() {
14-
const { data: teams } = await client.models.Team.list({
15-
selectionSet: [
16-
"name",
17-
"approved",
18-
"id",
19-
"members.id",
20-
"members.firstName",
21-
"members.lastName",
22-
"members.checkedIn",
23-
],
24-
});
18+
const { data: teams } = await getTeams;
2519
if (!teams || !Array.isArray(teams)) return "No teams were found";
2620
return <TeamsTable teams={teams} />;
2721
}

src/app/admin/teams/components/ViewButton.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ export default function ViewButton({ team }: { team: Team }) {
3232
<td className={"rounded-md p-2"}>
3333
{`${member.firstName} ${member.lastName}`}
3434
</td>
35-
<td className={"rounded-md p-2"}>
36-
{member.checkedIn ? "Checked In" : "Not Checked In"}
37-
</td>
35+
<td className={"rounded-md p-2"}>{member.id}</td>
3836
</tr>
3937
))}
4038
</tbody>

src/app/participant/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export default function page() {
2929
<div className="flex flex-col gap-4">
3030
<NextMealScheduled />
3131
<GoToFoodTicket />
32-
{/* <DevPostSubmission /> */}
3332
</div>
3433
<div className="flex flex-col gap-4">
3534
<ImportantInformation />

0 commit comments

Comments
 (0)