Skip to content

Commit

Permalink
feat: qr code webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
UnderKoen committed Oct 31, 2024
1 parent faeaafe commit 379b3bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/models/WebhookRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
IBatchStatusUpdateWebhookRequest,
ICouponCodeUsedWebhookRequest,
IOrderStatusUpdateWebhookRequest,
IQrCodeScannedWebhookRequest,
ITemplatePreviewRenderedWebhookRequest,
IWebhookRequest,
} from "~/models/_interfaces/IWebhookRequest";
Expand Down Expand Up @@ -32,7 +33,8 @@ export type WebhookRequest =
| OrderStatusUpdateWebhookRequest
| TemplatePreviewRenderedWebhookRequest
| BatchStatusUpdateWebhookRequest
| CouponCodeUsedWebhookRequest;
| CouponCodeUsedWebhookRequest
| QrCodeScannedWebhookRequest;

export function webhookRequestFactory(
_protected: Protected,
Expand All @@ -49,6 +51,8 @@ export function webhookRequestFactory(
return new BatchStatusUpdateWebhookRequest(_protected, data);
case "coupon_code_used":
return new CouponCodeUsedWebhookRequest(_protected, data);
case "qr_code_scanned":
return new QrCodeScannedWebhookRequest(_protected, data);
default:
throw new Error(`Unknown webhook event: ${event}`);
}
Expand Down Expand Up @@ -89,3 +93,12 @@ export class CouponCodeUsedWebhookRequest extends AbstractWebhookRequest<
return new CouponCode(this._protected, this._data.data);
}
}

export class QrCodeScannedWebhookRequest extends AbstractWebhookRequest<
Order,
IQrCodeScannedWebhookRequest
> {
get data(): Order {
return new Order(this._protected, this._data.data);
}
}
7 changes: 6 additions & 1 deletion src/models/_interfaces/IWebhookRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export type IWebhookRequest =
| IOrderStatusUpdateWebhookRequest
| ITemplatePreviewRenderedWebhookRequest
| IBatchStatusUpdateWebhookRequest
| ICouponCodeUsedWebhookRequest;
| ICouponCodeUsedWebhookRequest
| IQrCodeScannedWebhookRequest;

type IWebhookBaseRequest<TEvent extends string, TData> = {
data: TData;
Expand All @@ -31,3 +32,7 @@ export type ICouponCodeUsedWebhookRequest = IWebhookBaseRequest<
"coupon_code_used",
ICouponCode
>;
export type IQrCodeScannedWebhookRequest = IWebhookBaseRequest<
"qr_code_scanned",
IOrder
>;

0 comments on commit 379b3bd

Please sign in to comment.