Skip to content

Commit 89a0262

Browse files
committed
change structure & remove unused code
1 parent 9b09cd7 commit 89a0262

Some content is hidden

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

47 files changed

+1907
-1583
lines changed

backend/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = {
1818
rules: {
1919
"prettier/prettier": ["error", { endOfLine: "auto" }],
2020
"class-methods-use-this": 0,
21+
"import/prefer-default-export": "off"
2122
},
2223
ignorePatterns: ["build/*"],
2324
};

backend/graphql/index.ts

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import { makeExecutableSchema, gql } from "apollo-server-express";
2-
import { applyMiddleware } from "graphql-middleware";
32
import { merge } from "lodash";
3+
// import { applyMiddleware } from "graphql-middleware";
4+
45
import {
56
typeDefs as scalarTypeDefs,
67
resolvers as scalarResolvers,
78
} from "graphql-scalars";
89

9-
import helloResolver from "./resolvers/helloResolver";
1010

1111
import dataModels from "./types/models";
1212
import customTypes from "./types/enums";
1313
import resolverTypes from "./types/resolvers";
1414

15-
const executableSchema = makeExecutableSchema({
15+
import participantResolvers from "./resolvers/participantResolver";
16+
import miscResolvers from "./resolvers/miscResolver";
17+
18+
const schema = makeExecutableSchema({
1619
typeDefs: [
1720
...scalarTypeDefs,
1821
dataModels,
@@ -21,50 +24,53 @@ const executableSchema = makeExecutableSchema({
2124
],
2225
resolvers: merge(
2326
scalarResolvers,
24-
helloResolver
27+
participantResolvers,
28+
miscResolvers
2529
),
2630
});
2731

32+
export default schema;
33+
2834
// const authorizedByAllUserTypes = () =>
2935
// isAuthorizedByUserType(new Set([UserType.STAFF, UserType.RESIDENT]));
3036
// const authorizedByStaff = () =>
3137
// isAuthorizedByUserType(new Set([UserType.STAFF]));
3238

33-
const graphQLMiddlewares = {
34-
Query: {
35-
// getNotificationsByUserId: authorizedByAllUserTypes(),
36-
// getNotificationById: authorizedByAllUserTypes(),
37-
// getStaffByIds: authorizedByStaff(),
38-
// getAllStaff: authorizedByStaff(),
39-
// getResidentsByIds: authorizedByStaff(),
40-
// getAllResidents: authorizedByStaff(),
41-
// getActiveResidents: authorizedByStaff(),
42-
// getTaskById: authorizedByAllUserTypes(),
43-
// getTasksByType: authorizedByAllUserTypes(),
44-
// getTasksByAssigneeId: authorizedByAllUserTypes(),
45-
// getTasksByAssignerId: authorizedByStaff(),
46-
// getTasksByStartDate: authorizedByAllUserTypes(),
47-
// getTasksByEndDate: authorizedByAllUserTypes(),
48-
// getTasksByStatus: authorizedByAllUserTypes(),
49-
},
50-
Mutation: {
51-
// sendNotification: authorizedByAllUserTypes(),
52-
// deleteUserNotification: authorizedByStaff(),
53-
// updateSeenNotification: authorizedByAllUserTypes(),
54-
// sendAnnouncement: authorizedByStaff(),
55-
// addStaff: authorizedByStaff(),
56-
// updateStaff: authorizedByStaff(),
57-
// deleteStaff: authorizedByStaff(),
58-
// addResident: authorizedByStaff(),
59-
// updateResident: authorizedByStaff(),
60-
// deleteResident: authorizedByStaff(),
61-
// redeemCredits: authorizedByStaff(),
62-
// createTask: authorizedByAllUserTypes(),
63-
// updateTask: authorizedByAllUserTypes(),
64-
// deleteTask: authorizedByAllUserTypes(),
65-
// assignTask: authorizedByStaff(),
66-
// changeTaskStatus: authorizedByStaff(),
67-
},
68-
};
39+
// const graphQLMiddlewares = {
40+
// Query: {
41+
// // getNotificationsByUserId: authorizedByAllUserTypes(),
42+
// // getNotificationById: authorizedByAllUserTypes(),
43+
// // getStaffByIds: authorizedByStaff(),
44+
// // getAllStaff: authorizedByStaff(),
45+
// // getResidentsByIds: authorizedByStaff(),
46+
// // getAllResidents: authorizedByStaff(),
47+
// // getActiveResidents: authorizedByStaff(),
48+
// // getTaskById: authorizedByAllUserTypes(),
49+
// // getTasksByType: authorizedByAllUserTypes(),
50+
// // getTasksByAssigneeId: authorizedByAllUserTypes(),
51+
// // getTasksByAssignerId: authorizedByStaff(),
52+
// // getTasksByStartDate: authorizedByAllUserTypes(),
53+
// // getTasksByEndDate: authorizedByAllUserTypes(),
54+
// // getTasksByStatus: authorizedByAllUserTypes(),
55+
// },
56+
// Mutation: {
57+
// // sendNotification: authorizedByAllUserTypes(),
58+
// // deleteUserNotification: authorizedByStaff(),
59+
// // updateSeenNotification: authorizedByAllUserTypes(),
60+
// // sendAnnouncement: authorizedByStaff(),
61+
// // addStaff: authorizedByStaff(),
62+
// // updateStaff: authorizedByStaff(),
63+
// // deleteStaff: authorizedByStaff(),
64+
// // addResident: authorizedByStaff(),
65+
// // updateResident: authorizedByStaff(),
66+
// // deleteResident: authorizedByStaff(),
67+
// // redeemCredits: authorizedByStaff(),
68+
// // createTask: authorizedByAllUserTypes(),
69+
// // updateTask: authorizedByAllUserTypes(),
70+
// // deleteTask: authorizedByAllUserTypes(),
71+
// // assignTask: authorizedByStaff(),
72+
// // changeTaskStatus: authorizedByStaff(),
73+
// },
74+
// };
6975

70-
export default applyMiddleware(executableSchema, graphQLMiddlewares);
76+
// export default applyMiddleware(executableSchema, graphQLMiddlewares);

backend/graphql/resolvers/announcementResolver.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// import NotificationService from "../../services/implementation/announcementImplementation";
1+
// import NotificationService from "../../services/implementations/notificationService";
22
// import INotificationService, {
33
// NotificationDTO,
44
// NotificationGroupDTO,
55
// NotificationReceivedDTO,
66
// UpdateNotificationDTO,
77
// CreateNotificationDTO,
8-
// } from "../../services/interface/notificationService";
9-
// import IResidentService from "../../services/interface/residentService";
10-
// import ResidentService from "../../services/implementation/residentService";
8+
// } from "../../services/interfaces/notificationService";
9+
// import IResidentService from "../../services/interfaces/residentService";
10+
// import ResidentService from "../../services/implementations/residentService";
1111

1212
// const residentService: IResidentService = new ResidentService();
1313
// const notificationService: INotificationService = new NotificationService(
@@ -131,4 +131,4 @@
131131
// },
132132
// };
133133

134-
// export default notificationResolvers;
134+
// export default notificationResolvers;

backend/graphql/resolvers/helloResolver.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import MiscService from "../../services/implementation/miscImplementation";
2+
import IMiscService from "../../services/interface/miscInterface";
3+
4+
const miscService: IMiscService = new MiscService();
5+
const miscResolvers = {
6+
Query: {
7+
getAvailableRooms: async (): Promise<number[]> => {
8+
return miscService.getAvailableRooms();
9+
}
10+
}
11+
};
12+
13+
export default miscResolvers;

backend/graphql/resolvers/participantResolver.ts

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,50 @@
1-
// import ResidentService from "../../services/implementation/residentService";
1+
import ParticipantService from "../../services/implementation/participantImplementation";
2+
import IParticipantService from "../../services/interface/participantInterface";
3+
import { Participant } from "@prisma/client";
4+
5+
const participantService: IParticipantService = new ParticipantService();
6+
const participantResolvers = {
7+
Query: {
8+
getAllParticipants: async (): Promise<Participant[]> => {
9+
return participantService.getAllParticipants();
10+
},
11+
getParticipantById: async (
12+
_parent: undefined,
13+
{ participantId }: { participantId: string },
14+
): Promise<Participant | null> => {
15+
return participantService.getParticipantById(participantId);
16+
},
17+
},
18+
Mutation: {
19+
createParticipant: async (
20+
_parent: undefined,
21+
{
22+
participantId,
23+
roomNumber,
24+
arrival,
25+
password
26+
} : {
27+
participantId: string;
28+
roomNumber: number;
29+
arrival: string;
30+
password: string;
31+
}
32+
): Promise<boolean> => {
33+
return participantService.createParticipant(participantId, roomNumber, arrival, password);
34+
35+
}
36+
}
37+
};
38+
39+
export default participantResolvers;
40+
241
// import IResidentService, {
342
// ResidentDTO,
443
// CreateResidentDTO,
544
// UpdateResidentDTO,
645
// RedeemCreditsResponse,
746
// } from "../../services/interface/residentService";
847

9-
// const residentService: IResidentService = new ResidentService();
10-
1148
// const residentResolvers = {
1249
// Query: {
1350
// getResidentsByIds: async (
@@ -69,5 +106,3 @@
69106
// },
70107
// },
71108
// };
72-
73-
// export default residentResolvers;

backend/graphql/resolvers/taskResolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// import { Status, TaskType } from "../../prisma";
2-
// import TaskService from "../../services/implementation/taskService";
2+
// import TaskService from "../../services/implementations/taskService";
33
// import ITaskService, {
44
// TaskDTO,
55
// InputTaskDTO,
66
// InputTaskAssignedDTO,
77
// TaskAssignedDTO,
8-
// } from "../../services/interface/taskService";
8+
// } from "../../services/interfaces/taskService";
99

1010
// const taskService: ITaskService = new TaskService();
1111

backend/graphql/types/enums.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ const customTypes = gql`
99
enum TaskType {
1010
REQUIRED
1111
OPTIONAL
12-
CHORE
1312
}
1413
1514
enum TaskStatus {
1615
UNASSIGNED
1716
ASSIGNED
1817
INCOMPLETE
18+
PENDING
1919
COMPLETE
2020
EXCUSED
2121
}

backend/graphql/types/models.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,29 @@ import { gql } from "apollo-server-express";
22

33
const dataModels = gql`
44
type Participant {
5-
participant_id: Int!
6-
room_number: Int!
7-
arrival: DateTime!
8-
departure: DateTime
9-
is_active: Boolean!
5+
participantId: String!
6+
roomNumber: Int!
7+
arrival: String!
8+
departure: String
109
password: String!
11-
credit_earned: Int!
10+
credit: Int!
1211
}
1312
1413
type Announcement {
15-
announcement_id: Int!
14+
announcementId: Int!
1615
from: StaffType!
1716
to: [Int!]!
1817
createdAt: DateTime!
1918
message: String!
2019
}
2120
2221
type Task {
23-
task_id: Int!
24-
room_number: Int
22+
taskId: Int!
23+
roomNumber: Int
2524
type: TaskType!
2625
status: TaskStatus!
2726
name: String!
28-
is_recurring: Boolean!
27+
isRecurring: Boolean!
2928
start: DateTime!
3029
end: DateTime!
3130
credit: Int!

backend/graphql/types/resolvers.ts

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

33
const resolverTypes = gql`
44
type Query {
5-
hello: String!
5+
getAllParticipants: [Participant]
6+
getParticipantById(participantId: String): Participant
7+
getAvailableRooms: [Int]
68
}
79
810
type Mutation {
9-
_empty: String
11+
createParticipant(participantId: String, roomNumber: Int, arrival: String, password: String): Boolean
1012
}
1113
`;
1214

0 commit comments

Comments
 (0)