Skip to content

Commit

Permalink
feature: Add service methods, actions, and query for invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
belsman committed Aug 12, 2024
1 parent a8366e2 commit e0393dc
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
mutation OrderingInvoiceCreate(
$input: IIoRestorecommerceOrderOrderingInvoiceRequestList!
) {
ordering {
order {
CreateInvoice(input: $input) {
details {
items {
payload {
id
invoiceNumber
paymentState
}
}
}
}
}
}
}
5 changes: 5 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 @@ -85,3 +85,8 @@ export const orderRemoveFail = createAction(
'[ORDER] Order remove fail',
props<{ error: string }>()
);

export const orderCreateInvoiceRequest = createAction(
'[ORDER] Create an invoice request',
props<{ payload: string }>()
);
7 changes: 7 additions & 0 deletions packages/core/state/src/lib/+state/order/order.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,12 @@ export class OrderFacade {
remove = (payload: { id: string }) =>
this.store.dispatch(orderActions.orderRemoveRequest({ payload }));

createOrderInvoice = (payload: string) =>
this.store.dispatch(
orderActions.orderCreateInvoiceRequest({
payload,
})
);

constructor(private readonly store: Store) {}
}
26 changes: 25 additions & 1 deletion packages/core/state/src/lib/services/ordering/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
IIoRestorecommerceOrderOrderList,
IIoRestorecommerceResourcebaseDeleteRequest,
IIoRestorecommerceResourcebaseReadRequest,
OrderingInvoiceCreateGQL,
OrderingInvoiceCreateMutation,
IIoRestorecommerceOrderOrderingInvoiceRequestList,
OrderingOrderDeleteMutateGQL,
OrderingOrderDeleteMutateMutation,
OrderingOrderMutateGQL,
Expand All @@ -22,7 +25,8 @@ export class OrderService {
constructor(
private readonly orderingOrderReadGQL: OrderingOrderReadGQL,
private readonly orderingOrderMutateGQL: OrderingOrderMutateGQL,
private readonly orderingOrderDeleteMutateGQL: OrderingOrderDeleteMutateGQL
private readonly orderingOrderDeleteMutateGQL: OrderingOrderDeleteMutateGQL,
private readonly orderingInvoiceCreateGQL: OrderingInvoiceCreateGQL
) {}

read(
Expand All @@ -48,4 +52,24 @@ export class OrderService {
input: payload,
});
}

createOrderInvoice(
payload: string
): Observable<MutationResult<OrderingInvoiceCreateMutation>> {
const orderInvoiceInput: IIoRestorecommerceOrderOrderingInvoiceRequestList =
{};
orderInvoiceInput.items = [
{
sections: [
{
orderId: payload,
},
],
},
];

return this.orderingInvoiceCreateGQL.mutate({
input: orderInvoiceInput,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export class OrderTemplateComponent implements OnInit, OnDestroy {
'[Log] ~ file: order-template.component.ts:107 ~ OrderTemplateComponent ~ tap ~ console: triggerCreateInvoice --->',
id
);

console.log('*** Action for creating an invoice for this', id);

this.orderFacade.createOrderInvoice(id);
})
);

Expand Down

0 comments on commit e0393dc

Please sign in to comment.