-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojections.ts
35 lines (34 loc) · 1.05 KB
/
projections.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {Projector} from "./common";
import {insertOne, updateOne} from "./mongoProjectors";
import {BookingFullyPaid, PaymentRegistered, RoomBooked} from "./eventTypes";
export const mongoHandlers: Projector = [
insertOne<RoomBooked>(
"V1.RoomBooked",
event => ({
document: {
_id: event.bookingId,
roomId: event.roomId,
guestId: event.guestId,
checkInDate: event.checkIn,
checkOutDate: event.checkOut,
bookingPrice: event.bookingPrice,
paidAmount: event.prepaidAmount,
paid: false
}
})
),
updateOne<PaymentRegistered>(
"V1.PaymentRecorded",
event => ({
filter: {_id: event.bookingId},
update: { $set: { outstanding: event.outstanding, } }
})
),
updateOne<BookingFullyPaid>(
"V1.FullyPaid",
event => ({
filter: {_id: event.bookingId},
update: { $set: { paid: true } }
})
)
];