Skip to content

Commit

Permalink
Denormalize signup res and query types
Browse files Browse the repository at this point in the history
  • Loading branch information
MatoPlus committed Mar 18, 2022
1 parent da88911 commit 981f3e9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions backend/graphql/types/shiftSignupType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const shiftSignupType = gql`
type ShiftSignupResponseDTO {
shiftId: ID!
shiftStartTime: DateTime!
shiftEndTime: DateTime!
userId: ID!
numVolunteers: Int!
note: String!
Expand Down
22 changes: 20 additions & 2 deletions backend/services/implementations/shiftSignupService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PrismaClient, Signup, SignupStatus } from "@prisma/client";
import { Prisma } from ".prisma/client";
import { Prisma, Shift } from ".prisma/client";

import IShiftSignupService from "../interfaces/shiftSignupService";
import {
Expand All @@ -24,6 +24,19 @@ class ShiftSignupService implements IShiftSignupService {
};
};

convertSignupResponseToDTO = (
signup: Signup,
shift: Shift,
): ShiftSignupResponseDTO => {
return {
...signup,
shiftId: String(signup.shiftId),
userId: String(signup.userId),
shiftStartTime: shift.startTime,
shiftEndTime: shift.endTime,
};
};

async getShiftSignupsForUser(
userId: string,
signupStatus: SignupStatus | null,
Expand All @@ -43,8 +56,13 @@ class ShiftSignupService implements IShiftSignupService {
};
const shiftSignups = await prisma.signup.findMany({
where: filter,
include: {
shift: true,
},
});
return shiftSignups.map((signup) => this.convertSignupToDTO(signup));
return shiftSignups.map((signup) =>
this.convertSignupResponseToDTO(signup, signup.shift),
);
} catch (error: unknown) {
Logger.error(
`Failed to shift signups. Reason = ${getErrorMessage(error)}`,
Expand Down
5 changes: 4 additions & 1 deletion backend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ export type UpdateShiftSignupRequestDTO = Omit<
"shiftId" | "userId"
>;

export type ShiftSignupResponseDTO = ShiftSignupDTO;
export type ShiftSignupResponseDTO = {
shiftStartTime: Date;
shiftEndTime: Date;
} & ShiftSignupDTO;

export type SkillDTO = {
id: string;
Expand Down

0 comments on commit 981f3e9

Please sign in to comment.