Skip to content

Commit

Permalink
chore: add updatedAt to schema (#547)
Browse files Browse the repository at this point in the history
* chore: add updatedAt to schema

* chore: update types
  • Loading branch information
larwaa authored Mar 14, 2024
1 parent 3ecb005 commit 1754f7c
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 32 deletions.
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type BookingContact {
id: ID!
name: String!
phoneNumber: String!
updatedAt: DateTime!
}

type BookingContactResponse {
Expand All @@ -61,6 +62,7 @@ type BookingSemester {
id: ID!
semester: Semester!
startAt: DateTime!
updatedAt: DateTime!
}

type BookingSemestersResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe("Cabin mutations", () => {
name,
email,
phoneNumber,
updatedAt: new Date(),
});

const { errors } = await client.mutate(
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/cabins/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ type BookingContact {
name: String!
email: String!
phoneNumber: String!
updatedAt: DateTime!
}

enum Semester {
Expand All @@ -158,6 +159,7 @@ type BookingSemester {
endAt: DateTime!
bookingsEnabled: Boolean!
semester: Semester!
updatedAt: DateTime!
}

input UpdateBookingSemesterInput {
Expand Down
3 changes: 0 additions & 3 deletions src/graphql/events/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ enum SignUpAvailability {
ON_WAITLIST
}

type EventsResponse {
events: [Event!]!
}

type CreateEventResponse {
event: Event!
Expand Down
6 changes: 4 additions & 2 deletions src/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ interface ICabinService {
): Promise<BookingSemester>;
getBookingSemester(semester: Semester): Promise<BookingSemester | null>;
getBookingContact(): Promise<
Pick<BookingContact, "email" | "name" | "phoneNumber" | "id">
Pick<BookingContact, "email" | "name" | "phoneNumber" | "id" | "updatedAt">
>;
updateBookingContact(
ctx: Context,
Expand All @@ -262,7 +262,9 @@ interface ICabinService {
phoneNumber: string | null;
email: string | null;
}>,
): Promise<Pick<BookingContact, "email" | "name" | "phoneNumber" | "id">>;
): Promise<
Pick<BookingContact, "email" | "name" | "phoneNumber" | "id" | "updatedAt">
>;
createCabin(
ctx: Context,
params: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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,
}),
);
});
});

Expand Down Expand Up @@ -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 () => {
Expand All @@ -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: "",
}),
);
});
});
});
9 changes: 7 additions & 2 deletions src/repositories/cabins/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,16 @@ export class CabinRepository implements ICabinRepository {
*/
async updateBookingContact(
data: Partial<{ name: string; email: string; phoneNumber: string }>,
): Promise<Pick<BookingContact, "email" | "name" | "id" | "phoneNumber">> {
): Promise<
Pick<BookingContact, "email" | "name" | "id" | "phoneNumber" | "updatedAt">
> {
return await this.db.bookingContact.upsert({
select: {
id: true,
name: true,
email: true,
phoneNumber: true,
updatedAt: true,
},
where: {
id: "booking-contact",
Expand All @@ -517,14 +520,15 @@ 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<BookingContact, "email" | "id" | "name" | "phoneNumber">
Pick<BookingContact, "email" | "id" | "name" | "phoneNumber" | "updatedAt">
> {
const bookingContact = await this.db.bookingContact.findUnique({
select: {
id: true,
name: true,
email: true,
phoneNumber: true,
updatedAt: true,
},
where: {
id: "booking-contact",
Expand All @@ -537,6 +541,7 @@ export class CabinRepository implements ICabinRepository {
name: "",
email: "",
phoneNumber: "",
updatedAt: new Date(),
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/cabins/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1754f7c

Please sign in to comment.