-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from alwinsimon/v1
V1 - Completed Basic Back-end Implementation.
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Message } from "node-nats-streaming"; | ||
import { | ||
Listener, | ||
EventSubjects, | ||
PaymentCreatedEvent, | ||
NotFoundError, | ||
OrderStatus, | ||
} from "@bookmyseat/common"; | ||
|
||
import { queueGroupName } from "../order-service-queue-group-name"; | ||
import { Order } from "../../models/order"; | ||
|
||
export class PaymentCreatedListener extends Listener<PaymentCreatedEvent> { | ||
readonly subject = EventSubjects.PaymentCreated; | ||
|
||
queueGroupName = queueGroupName; | ||
|
||
async onMessage(data: PaymentCreatedEvent["data"], msg: Message) { | ||
try { | ||
// Destructure the ticket id, title, and price from data argument. | ||
const { id, version, orderId, stripeId } = data; | ||
|
||
const order = await Order.findById(data.orderId); | ||
|
||
if (!order) { | ||
throw new NotFoundError(); | ||
} | ||
|
||
order.set({ status: OrderStatus.Complete }); | ||
|
||
await order.save(); | ||
|
||
// Acknowledge the Payment Created event to NATS server. | ||
msg.ack(); | ||
} catch (error) { | ||
console.error("Error processing PaymentCreatedEvent", error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters