Skip to content

Commit 086bcad

Browse files
authored
Merge pull request #128 from uwblueprint/annie/participant-page
annie/participant page
2 parents 232bb80 + 75df23b commit 086bcad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+10765
-10244
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/prettier.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/graphql/resolvers/participantResolver.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import IParticipantService from "../../services/interface/participantInterface";
55
const participantService: IParticipantService = new ParticipantService();
66
const participantResolvers = {
77
Query: {
8-
getAllParticipants: async (): Promise<Participant[]> => {
9-
return participantService.getAllParticipants();
8+
getPastParticipants: async (): Promise<Participant[]> => {
9+
return participantService.getPastParticipants();
10+
},
11+
getCurrentParticipants: async (): Promise<Participant[]> => {
12+
return participantService.getCurrentParticipants();
1013
},
1114
getParticipantById: async (
1215
_parent: undefined,
@@ -37,6 +40,30 @@ const participantResolvers = {
3740
password,
3841
);
3942
},
43+
updateParticipantById: async (
44+
_parent: undefined,
45+
{
46+
participantId,
47+
roomNumber,
48+
arrival,
49+
departure,
50+
password,
51+
}: {
52+
participantId: string;
53+
roomNumber?: number;
54+
arrival?: string;
55+
departure?: string;
56+
password?: string;
57+
},
58+
): Promise<boolean> => {
59+
return participantService.updateParticipantById(
60+
participantId,
61+
roomNumber,
62+
arrival,
63+
departure,
64+
password,
65+
);
66+
},
4067
},
4168
};
4269

backend/graphql/types/resolvers.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@ import { gql } from "apollo-server-express";
22

33
const resolverTypes = gql`
44
type Query {
5-
getAllParticipants: [Participant]
6-
getParticipantById(participantId: String): Participant
5+
getPastParticipants: [Participant]
6+
getCurrentParticipants: [Participant]
7+
getParticipantById(participantId: String!): Participant
78
getAvailableRooms: [Int]
89
}
910
1011
type Mutation {
1112
login(role: String!, encryptedPassword: String!): AuthResponse
1213
createParticipant(
13-
participantId: String
14+
participantId: String!
15+
roomNumber: Int!
16+
arrival: String!
17+
password: String!
18+
): Boolean
19+
updateParticipantById(
20+
participantId: String!
1421
roomNumber: Int
1522
arrival: String
23+
departure: String
1624
password: String
1725
): Boolean
1826
}

backend/services/implementation/miscImplementation.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ class MiscService implements IMiscService {
77
const today = new Date();
88
const rooms = await prisma.participant.findMany({
99
where: {
10-
OR: [
11-
{ departure: null },
12-
{ departure: { gte: today.toISOString() } },
13-
],
10+
OR: [{ departure: "" }, { departure: { gte: today.toISOString() } }],
1411
},
1512
select: {
1613
roomNumber: true,

backend/services/implementation/participantImplementation.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,24 @@ import prisma from "../../prisma";
33
import IParticipantService from "../interface/participantInterface";
44

55
class ParticipantService implements IParticipantService {
6-
async getAllParticipants(): Promise<Participant[]> {
6+
async getPastParticipants(): Promise<Participant[]> {
77
try {
88
const participants = await prisma.participant.findMany({
9-
orderBy: [{ departure: "asc" }, { arrival: "desc" }],
9+
where: {departure: { not: "" }},
10+
orderBy: [{ departure: "desc" }],
11+
});
12+
return participants;
13+
} catch (err) {
14+
console.log(err);
15+
throw err;
16+
}
17+
}
18+
19+
async getCurrentParticipants(): Promise<Participant[]> {
20+
try {
21+
const participants = await prisma.participant.findMany({
22+
where: {departure: ""},
23+
orderBy: [{ roomNumber: "asc" }],
1024
});
1125
return participants;
1226
} catch (err) {
@@ -43,6 +57,7 @@ class ParticipantService implements IParticipantService {
4357
participantId,
4458
roomNumber,
4559
arrival,
60+
departure: "",
4661
password,
4762
},
4863
});
@@ -52,6 +67,31 @@ class ParticipantService implements IParticipantService {
5267
throw err;
5368
}
5469
}
70+
71+
async updateParticipantById(
72+
participantId: string,
73+
roomNumber?: number,
74+
arrival?: string,
75+
departure?: string,
76+
password?: string,
77+
): Promise<boolean> {
78+
const updatedData: Record<string, any> = {};
79+
if (roomNumber) updatedData.roomNumber = roomNumber;
80+
if (arrival) updatedData.arrival = arrival;
81+
if (departure) updatedData.departure = departure;
82+
if (password) updatedData.password = password;
83+
84+
try {
85+
await prisma.participant.update({
86+
where: { participantId },
87+
data: updatedData,
88+
});
89+
return true;
90+
} catch (err) {
91+
console.log(err);
92+
throw err;
93+
}
94+
}
5595
}
5696

5797
export default ParticipantService;
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import { Participant } from "@prisma/client";
22

33
interface IParticipantService {
4-
getAllParticipants(): Promise<Participant[]>;
4+
getPastParticipants(): Promise<Participant[]>;
5+
getCurrentParticipants(): Promise<Participant[]>;
56
getParticipantById(participantId: string): Promise<Participant | null>;
67
createParticipant(
78
participantId: string,
89
roomNumber: number,
910
arrival: string,
1011
password: string,
1112
): Promise<boolean>;
13+
updateParticipantById(
14+
participantId: string,
15+
roomNumber?: number,
16+
arrival?: string,
17+
departure?: string,
18+
password?: string,
19+
): Promise<boolean>;
1220
}
1321

1422
export default IParticipantService;

0 commit comments

Comments
 (0)