Skip to content

Commit

Permalink
feature: add effects for handling invoice creation for order
Browse files Browse the repository at this point in the history
  • Loading branch information
belsman committed Aug 12, 2024
1 parent d0cc853 commit e348434
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const environment: Readonly<IEnvironment> = {
oidcKey: 'VEVTVF9DTElFTlRfSUQ6VEVTVF9DTElFTlRfU0VDUkVU=',
storagePrefix: 'console.dev.',
urls: {
api: 'http://192.168.1.38:5000',
graphql: 'http://192.168.1.38:5000/graphql',
api: 'http://127.0.0.1:5000',
graphql: 'http://127.0.0.1:5000/graphql',
},
};
10 changes: 10 additions & 0 deletions packages/core/state/src/lib/+state/order/order.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,13 @@ export const orderCreateInvoiceRequest = createAction(
'[ORDER] Create an invoice request',
props<{ payload: string }>()
);

export const orderCreateInvoiceSuccess = createAction(
'[ORDER] Create an invoice success',
props<{ payload: string }>()
);

export const orderCreateInvoiceFail = createAction(
'[ORDER] Create an invoice fail',
props<{ error: string }>()
);
25 changes: 24 additions & 1 deletion packages/core/state/src/lib/+state/order/order.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,28 @@ export class OrderEffects {
{ dispatch: false }
);

orderCreateInvoiceRequest$ = createEffect(() => {
return this.actions$.pipe(
ofType(orderActions.orderCreateInvoiceRequest),
switchMap(({ payload }) =>
this.orderService.createOrderInvoice(payload).pipe(
map((result) => {
const payload = (
result.data?.ordering.order.CreateInvoice?.details?.items || []
).map((item) => item?.payload);

return orderActions.orderCreateInvoiceSuccess({
payload: JSON.stringify(payload),
});
}),
catchError((error: Error) =>
of(orderActions.orderCreateInvoiceFail({ error: error.message }))
)
)
)
);
});

handleNotificationErrors$ = createEffect(
() => {
return this.actions$.pipe(
Expand All @@ -227,7 +249,8 @@ export class OrderEffects {
orderActions.orderReadOneByIdRequestFail,
orderActions.orderCreateFail,
orderActions.orderUpdateFail,
orderActions.orderRemoveFail
orderActions.orderRemoveFail,
orderActions.orderCreateInvoiceFail
),
tap(({ error }) => {
this.appFacade.addNotification({
Expand Down

0 comments on commit e348434

Please sign in to comment.