Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Shift CRUD Methods and GraphQL Resolvers #55

Merged
merged 17 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion backend/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ import entityResolvers from "./resolvers/entityResolvers";
import entityType from "./types/entityType";
import userResolvers from "./resolvers/userResolvers";
import userType from "./types/userType";
import shiftResolvers from "./resolvers/shiftResolvers";
import shiftType from "./types/shiftType";
import skillResolvers from "./resolvers/skillResolvers";
import skillType from "./types/skillType";

const query = gql`
scalar Date
type Query {
_empty: String
}
Expand All @@ -29,11 +32,20 @@ const mutation = gql`
`;

const executableSchema = makeExecutableSchema({
typeDefs: [query, mutation, authType, entityType, userType, skillType],
typeDefs: [
query,
mutation,
authType,
entityType,
userType,
shiftType,
skillType,
],
resolvers: merge(
authResolvers,
entityResolvers,
userResolvers,
shiftResolvers,
skillResolvers,
),
});
Expand All @@ -49,6 +61,8 @@ const graphQLMiddlewares = {
userById: authorizedByAdmin(),
userByEmail: authorizedByAdmin(),
users: authorizedByAdmin(),
shift: authorizedByAdmin(),
shifts: authorizedByAdmin(),
skill: authorizedByAdmin(),
skills: authorizedByAdmin(),
},
Expand All @@ -61,6 +75,12 @@ const graphQLMiddlewares = {
deleteUserById: authorizedByAdmin(),
deleteUserByEmail: authorizedByAdmin(),
logout: isAuthorizedByUserId("userId"),
resetPassword: isAuthorizedByEmail("email"),
sherryhli marked this conversation as resolved.
Show resolved Hide resolved
createShifts: authorizedByAdmin(),
updateShift: authorizedByAdmin(),
updateShifts: authorizedByAdmin(),
deleteShift: authorizedByAdmin(),
deleteShifts: authorizedByAdmin(),
createSkill: authorizedByAdmin(),
updateSkill: authorizedByAdmin(),
deleteSkill: authorizedByAdmin(),
Expand Down
58 changes: 58 additions & 0 deletions backend/graphql/resolvers/shiftResolvers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import ShiftService from "../../services/implementations/shiftService";
import IShiftService from "../../services/interfaces/IShiftService";
import {
ShiftBulkRequestDTO,
ShiftRequestDTO,
ShiftResponseDTO,
} from "../../types";

const shiftService: IShiftService = new ShiftService();

const shiftResolvers = {
Query: {
shift: async (
_parent: undefined,
{ id }: { id: string },
): Promise<ShiftResponseDTO> => {
return shiftService.getShift(id);
},
shifts: async (): Promise<ShiftResponseDTO[]> => {
return shiftService.getShifts();
},
},
Mutation: {
createShifts: async (
_parent: undefined,
{ shifts }: { shifts: ShiftBulkRequestDTO },
): Promise<ShiftResponseDTO[]> => {
const newShifts = await shiftService.createShifts(shifts);
return newShifts;
},
updateShift: async (
_parent: undefined,
{ id, shift }: { id: string; shift: ShiftRequestDTO },
sherryhli marked this conversation as resolved.
Show resolved Hide resolved
): Promise<ShiftResponseDTO | null> => {
return shiftService.updateShift(id, shift);
},
updateShifts: async (
_parent: undefined,
{ id, shifts }: { id: string; shifts: ShiftBulkRequestDTO },
sherryhli marked this conversation as resolved.
Show resolved Hide resolved
): Promise<ShiftResponseDTO[] | null> => {
return shiftService.updateShifts(id, shifts);
},
deleteShift: async (
_parent: undefined,
{ id }: { id: string },
): Promise<void> => {
return shiftService.deleteShift(id);
},
deleteShifts: async (
_parent: undefined,
{ id }: { id: string },
): Promise<void> => {
return shiftService.deleteShifts(id);
},
},
sherryhli marked this conversation as resolved.
Show resolved Hide resolved
};

export default shiftResolvers;
50 changes: 50 additions & 0 deletions backend/graphql/types/shiftType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { gql } from "apollo-server-express";

const shiftType = gql`
enum RecurrenceInterval {
WEEKLY
BIWEEKLY
MONTHLY
NONE
}

input TimeBlockDTO {
date: String!
startTime: String!
endTime: String!
}

input ShiftBulkRequestDTO {
postingId: String!
times: [TimeBlockDTO!]!
endDate: String!
recurrenceInterval: RecurrenceInterval!
}

input ShiftRequestDTO {
startTime: Date!
endTime: Date!
}

type ShiftResponseDTO {
id: ID!
postingId: String!
startTime: Date!
endTime: Date!
}

extend type Query {
shift(id: ID!): ShiftResponseDTO!
shifts: [ShiftResponseDTO!]!
}

extend type Mutation {
createShifts(shifts: ShiftBulkRequestDTO!): [ShiftResponseDTO!]!
updateShift(id: ID!, shift: ShiftRequestDTO!): ShiftResponseDTO!
updateShifts(id: ID!, shifts: ShiftBulkRequestDTO!): [ShiftResponseDTO!]!
deleteShift(id: ID!): ID
deleteShifts(id: ID!): ID
sherryhli marked this conversation as resolved.
Show resolved Hide resolved
}
`;

export default shiftType;
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"graphql-upload": "^12.0.0",
"json2csv": "^5.0.6",
"lodash": "^4.17.21",
"moment": "^2.29.1",
"mongoose": "^5.12.12",
"multer": "^1.4.2",
"node-fetch": "^2.6.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Warnings:

- You are about to drop the column `repeat_end` on the `shifts` table. All the data in the column will be lost.
- You are about to drop the column `repeat_interval` on the `shifts` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "shifts" DROP COLUMN "repeat_end",
DROP COLUMN "repeat_interval";
3 changes: 1 addition & 2 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["interactiveTransactions"]
}

datasource db {
Expand Down Expand Up @@ -109,8 +110,6 @@ model Shift {
posting Posting @relation(fields: [postingId], references: [id])
startTime DateTime @map("start_time")
endTime DateTime @map("end_time")
repeatInterval Int? @map("repeat_interval")
repeatEnd DateTime? @map("repeat_end")
signups Signup[]

@@map("shifts")
Expand Down