From 1754f7cae022540b65424276c0c5f0682c6c26cc Mon Sep 17 00:00:00 2001 From: Lars Waage <46653859+larwaa@users.noreply.github.com> Date: Thu, 14 Mar 2024 15:40:10 +0100 Subject: [PATCH] chore: add updatedAt to schema (#547) * chore: add updatedAt to schema * chore: update types --- schema.graphql | 2 + .../updateBookingContact.unit.test.ts | 1 + src/graphql/cabins/schema.graphql | 2 + src/graphql/events/schema.graphql | 3 - src/lib/server.ts | 6 +- .../integration/booking-contact.test.ts | 56 +++++++++++-------- src/repositories/cabins/repository.ts | 9 ++- src/services/cabins/service.ts | 2 +- 8 files changed, 49 insertions(+), 32 deletions(-) diff --git a/schema.graphql b/schema.graphql index 9f640dd3..4518a548 100644 --- a/schema.graphql +++ b/schema.graphql @@ -49,6 +49,7 @@ type BookingContact { id: ID! name: String! phoneNumber: String! + updatedAt: DateTime! } type BookingContactResponse { @@ -61,6 +62,7 @@ type BookingSemester { id: ID! semester: Semester! startAt: DateTime! + updatedAt: DateTime! } type BookingSemestersResponse { diff --git a/src/graphql/cabins/resolvers/Mutation/updateBookingContact.unit.test.ts b/src/graphql/cabins/resolvers/Mutation/updateBookingContact.unit.test.ts index dce5a12c..aede3bba 100644 --- a/src/graphql/cabins/resolvers/Mutation/updateBookingContact.unit.test.ts +++ b/src/graphql/cabins/resolvers/Mutation/updateBookingContact.unit.test.ts @@ -54,6 +54,7 @@ describe("Cabin mutations", () => { name, email, phoneNumber, + updatedAt: new Date(), }); const { errors } = await client.mutate( diff --git a/src/graphql/cabins/schema.graphql b/src/graphql/cabins/schema.graphql index a86ea846..1615b486 100644 --- a/src/graphql/cabins/schema.graphql +++ b/src/graphql/cabins/schema.graphql @@ -145,6 +145,7 @@ type BookingContact { name: String! email: String! phoneNumber: String! + updatedAt: DateTime! } enum Semester { @@ -158,6 +159,7 @@ type BookingSemester { endAt: DateTime! bookingsEnabled: Boolean! semester: Semester! + updatedAt: DateTime! } input UpdateBookingSemesterInput { diff --git a/src/graphql/events/schema.graphql b/src/graphql/events/schema.graphql index 737c1263..b5275c2b 100644 --- a/src/graphql/events/schema.graphql +++ b/src/graphql/events/schema.graphql @@ -205,9 +205,6 @@ enum SignUpAvailability { ON_WAITLIST } -type EventsResponse { - events: [Event!]! -} type CreateEventResponse { event: Event! diff --git a/src/lib/server.ts b/src/lib/server.ts index b19fcabd..6202d90a 100644 --- a/src/lib/server.ts +++ b/src/lib/server.ts @@ -253,7 +253,7 @@ interface ICabinService { ): Promise; getBookingSemester(semester: Semester): Promise; getBookingContact(): Promise< - Pick + Pick >; updateBookingContact( ctx: Context, @@ -262,7 +262,9 @@ interface ICabinService { phoneNumber: string | null; email: string | null; }>, - ): Promise>; + ): Promise< + Pick + >; createCabin( ctx: Context, params: { diff --git a/src/repositories/cabins/__tests__/integration/booking-contact.test.ts b/src/repositories/cabins/__tests__/integration/booking-contact.test.ts index 541beaef..9a9d6bfc 100644 --- a/src/repositories/cabins/__tests__/integration/booking-contact.test.ts +++ b/src/repositories/cabins/__tests__/integration/booking-contact.test.ts @@ -23,12 +23,14 @@ describe("CabinRepository", () => { phoneNumber, }); - expect(bookingContact).toEqual({ - id: "booking-contact", - name, - email, - phoneNumber, - }); + expect(bookingContact).toEqual( + expect.objectContaining({ + id: "booking-contact", + name, + email, + phoneNumber, + }), + ); }); it("should update the booking contact if it already exists", async () => { @@ -64,12 +66,14 @@ describe("CabinRepository", () => { * * The booking contact should be updated */ - expect(actual).toEqual({ - id: "booking-contact", - name, - email, - phoneNumber, - }); + expect(actual).toEqual( + expect.objectContaining({ + id: "booking-contact", + name, + email, + phoneNumber, + }), + ); }); }); @@ -102,12 +106,14 @@ describe("CabinRepository", () => { * * The booking contact should be returned */ - expect(actual).toEqual({ - id: "booking-contact", - name, - email, - phoneNumber, - }); + expect(actual).toEqual( + expect.objectContaining({ + id: "booking-contact", + name, + email, + phoneNumber, + }), + ); }); it("should return a blank booking contact if it does not exist", async () => { @@ -130,12 +136,14 @@ describe("CabinRepository", () => { * * A blank booking contact should be returned */ - expect(actual).toEqual({ - id: "booking-contact", - name: "", - email: "", - phoneNumber: "", - }); + expect(actual).toEqual( + expect.objectContaining({ + id: "booking-contact", + name: "", + email: "", + phoneNumber: "", + }), + ); }); }); }); diff --git a/src/repositories/cabins/repository.ts b/src/repositories/cabins/repository.ts index 47504e35..9d6e8739 100644 --- a/src/repositories/cabins/repository.ts +++ b/src/repositories/cabins/repository.ts @@ -492,13 +492,16 @@ export class CabinRepository implements ICabinRepository { */ async updateBookingContact( data: Partial<{ name: string; email: string; phoneNumber: string }>, - ): Promise> { + ): Promise< + Pick + > { return await this.db.bookingContact.upsert({ select: { id: true, name: true, email: true, phoneNumber: true, + updatedAt: true, }, where: { id: "booking-contact", @@ -517,7 +520,7 @@ export class CabinRepository implements ICabinRepository { * getBookingContact returns the booking contact information. If it does not exist, blank strings will be returned. */ async getBookingContact(): Promise< - Pick + Pick > { const bookingContact = await this.db.bookingContact.findUnique({ select: { @@ -525,6 +528,7 @@ export class CabinRepository implements ICabinRepository { name: true, email: true, phoneNumber: true, + updatedAt: true, }, where: { id: "booking-contact", @@ -537,6 +541,7 @@ export class CabinRepository implements ICabinRepository { name: "", email: "", phoneNumber: "", + updatedAt: new Date(), }; } diff --git a/src/services/cabins/service.ts b/src/services/cabins/service.ts index 47c4dce7..e0c71e0f 100644 --- a/src/services/cabins/service.ts +++ b/src/services/cabins/service.ts @@ -31,7 +31,7 @@ import type { EmailQueueDataType } from "../mail/worker.js"; type BookingContact = Pick< PrismaBookingContact, - "email" | "name" | "phoneNumber" | "id" + "email" | "name" | "phoneNumber" | "id" | "updatedAt" >; export interface ICabinRepository {