Skip to content

Commit

Permalink
expose method to create booking
Browse files Browse the repository at this point in the history
  • Loading branch information
choden-dev committed Mar 26, 2024
1 parent 307599d commit 827dc78
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
5 changes: 3 additions & 2 deletions server/src/data-layer/adapters/FirestoreCollections.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// credit https://plainenglish.io/blog/using-firestore-with-typescript-in-the-v9-sdk-cf36851bb099
import "dotenv/config"
import { UserAdditionalInfo } from "data-layer/models/firebase"
import { Booking, UserAdditionalInfo } from "data-layer/models/firebase"
import { admin } from "business-layer/security/Firebase"

const converter = <T>() => ({
Expand All @@ -23,7 +23,8 @@ const firestore = Object.assign(
)

const db = {
users: firestore.collection<UserAdditionalInfo>("users")
users: firestore.collection<UserAdditionalInfo>("users"),
bookings: firestore.collection<Booking>("bookings")
} as const

export default db
24 changes: 24 additions & 0 deletions server/src/data-layer/services/BookingDataService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { cleanFirestore } from "test-config/TestUtils"
import BookingDataService from "./BookingDataService"
import FirestoreCollections from "data-layer/adapters/FirestoreCollections"

describe("BookingDataService", () => {
afterEach(async () => {
await cleanFirestore()
})

it("Should create a booking in firestore", async () => {
const { id } = await new BookingDataService().createBooking({
user_id: "asds",
booking_slot_id: "asdds"
})
const doc = await FirestoreCollections.bookings.doc(id).get()
const data = doc.data()

expect(data).not.toBe(undefined)
expect(data).toEqual({
user_id: "asds",
booking_slot_id: "asdds"
})
})
})
12 changes: 12 additions & 0 deletions server/src/data-layer/services/BookingDataService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Booking } from "data-layer/models/firebase"
import FirestoreCollections from "data-layer/adapters/FirestoreCollections"

export default class BookingDataService {
// Create
public async createBooking(bookingData: Booking) {
return await FirestoreCollections.bookings.add(bookingData)
}
// Read
// Update
// Delete
}

0 comments on commit 827dc78

Please sign in to comment.