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 16 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
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /app

COPY package.json yarn.lock tsconfig.json ./

RUN apt-get update && apt-get install -y libssl-dev
RUN apt-get update && apt-get install -y libcurl3
sherryhli marked this conversation as resolved.
Show resolved Hide resolved

RUN yarn install

Expand Down
13 changes: 13 additions & 0 deletions backend/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ 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 postingResolvers from "./resolvers/postingResolvers";
import postingType from "./types/postingType";
import skillResolvers from "./resolvers/skillResolvers";
import skillType from "./types/skillType";

const query = gql`
scalar Date
type Query {
_empty: String
}
Expand All @@ -33,13 +36,16 @@ const executableSchema = makeExecutableSchema({
authType,
entityType,
userType,
shiftType,
skillType,
skillType,
postingType,
],
resolvers: merge(
authResolvers,
entityResolvers,
userResolvers,
shiftResolvers,
postingResolvers,
skillResolvers,
),
Expand All @@ -56,6 +62,8 @@ const graphQLMiddlewares = {
userById: authorizedByAdmin(),
userByEmail: authorizedByAdmin(),
users: authorizedByAdmin(),
shift: authorizedByAdmin(),
shifts: authorizedByAdmin(),
posting: authorizedByAdmin(),
postings: authorizedByAdmin(),
skill: authorizedByAdmin(),
Expand All @@ -70,6 +78,11 @@ const graphQLMiddlewares = {
deleteUserById: authorizedByAdmin(),
deleteUserByEmail: authorizedByAdmin(),
logout: isAuthorizedByUserId("userId"),
createShifts: authorizedByAdmin(),
updateShift: authorizedByAdmin(),
updateShifts: authorizedByAdmin(),
deleteShift: authorizedByAdmin(),
deleteShifts: authorizedByAdmin(),
createPosting: authorizedByAdmin(),
updatePosting: authorizedByAdmin(),
deletePosting: 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,
{ shiftId, shift }: { shiftId: string; shift: ShiftRequestDTO },
): Promise<ShiftResponseDTO | null> => {
return shiftService.updateShift(shiftId, shift);
},
updateShifts: async (
_parent: undefined,
{ postingId, shifts }: { postingId: string; shifts: ShiftBulkRequestDTO },
): Promise<ShiftResponseDTO[] | null> => {
return shiftService.updateShifts(postingId, shifts);
},
deleteShift: async (
_parent: undefined,
{ shiftId }: { shiftId: string },
): Promise<string> => {
return shiftService.deleteShift(shiftId);
},
deleteShifts: async (
_parent: undefined,
{ postingId }: { postingId: string },
): Promise<string> => {
return shiftService.deleteShifts(postingId);
},
},
};

export default shiftResolvers;
9 changes: 0 additions & 9 deletions backend/graphql/types/postingType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ const postingType = gql`
numVolunteers: Int!
}

scalar Date

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

type BranchResponseDTO {
id: ID!
name: String!
Expand Down
53 changes: 53 additions & 0 deletions backend/graphql/types/shiftType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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(shiftId: ID!, shift: ShiftRequestDTO!): ShiftResponseDTO!
updateShifts(
postingId: ID!
shifts: ShiftBulkRequestDTO!
): [ShiftResponseDTO!]!
deleteShift(shiftId: ID!): ID
deleteShifts(postingId: ID!): ID
}
`;

export default shiftType;
3 changes: 3 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@prisma/client": "^3.3.0",
"apollo-server": "^2.22.2",
"apollo-server-express": "^2.22.2",
"bluebird": "^3.7.2",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
Expand All @@ -28,6 +29,7 @@
"graphql-upload": "^12.0.0",
"json2csv": "^5.0.6",
"lodash": "^4.17.21",
"moment": "^2.29.1",
"multer": "^1.4.2",
"node-fetch": "^2.6.1",
"nodemailer": "^6.5.0",
Expand All @@ -37,6 +39,7 @@
"winston": "^3.3.3"
},
"devDependencies": {
"@types/bluebird": "^3.5.36",
"@types/cookie-parser": "^1.4.2",
"@types/cors": "^2.8.10",
"@types/dotenv": "^8.2.0",
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 @@ -104,8 +105,6 @@ model Shift {
posting Posting @relation(fields: [postingId], references: [id], onDelete: Cascade)
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