diff --git a/packages/core/state/src/lib/+state/fulfillment/fulfillment.actions.ts b/packages/core/state/src/lib/+state/fulfillment/fulfillment.actions.ts index 6103a83b..cb8eef7f 100644 --- a/packages/core/state/src/lib/+state/fulfillment/fulfillment.actions.ts +++ b/packages/core/state/src/lib/+state/fulfillment/fulfillment.actions.ts @@ -41,6 +41,21 @@ export const fulfillmentCreateFail = createAction( props<{ error: string }>() ); +export const fulfillmentSubmitRequest = createAction( + '[FULFILLMENT] Submit request', + props<{ payload: IIoRestorecommerceResourcebaseReadRequest }>() +); + +export const fulfillmentSubmitSuccess = createAction( + '[FULFILLMENT] Fulfillment Submit success', + props<{ payload: IFulfillment }>() +); + +export const fulfillmentSubmitFail = createAction( + '[FULFILLMENT] Fulfillment Submit fail', + props<{ error: string }>() +); + export const fulfillmentUpdateRequest = createAction( '[FULFILLMENT] Fulfillment update request', props<{ payload: IIoRestorecommerceFulfillmentFulfillmentList }>() diff --git a/packages/core/state/src/lib/+state/fulfillment/fulfillment.effects.ts b/packages/core/state/src/lib/+state/fulfillment/fulfillment.effects.ts index 4a85a315..336eab36 100644 --- a/packages/core/state/src/lib/+state/fulfillment/fulfillment.effects.ts +++ b/packages/core/state/src/lib/+state/fulfillment/fulfillment.effects.ts @@ -202,6 +202,33 @@ export class FulfillmentEffects { { dispatch: false } ); + fulfillmentSubmitRequest$ = createEffect(() => { + return this.actions$.pipe( + ofType(fulfillmentActions.fulfillmentSubmitRequest), + switchMap(({ payload }) => + this.fulfillmentService.submit(payload).pipe( + tap((result) => { + this.errorHandlingService.checkStatusAndThrow( + result?.data?.fulfillment?.fulfillment?.Submit?.details + ?.operationStatus as TOperationStatus + ); + }), + map((result) => { + const payload = + result?.data?.fulfillment?.fulfillment?.Submit?.details?.items?.pop() + ?.payload as IFulfillment; + return fulfillmentActions.fulfillmentSubmitSuccess({ payload }); + }), + catchError((error: Error) => + of( + fulfillmentActions.fulfillmentSubmitFail({ error: error.message }) + ) + ) + ) + ) + ); + }); + constructor( private readonly router: Router, private readonly actions$: Actions, diff --git a/packages/core/state/src/lib/services/fulfillment/fulfillment.service.ts b/packages/core/state/src/lib/services/fulfillment/fulfillment.service.ts index d746a412..716952d2 100644 --- a/packages/core/state/src/lib/services/fulfillment/fulfillment.service.ts +++ b/packages/core/state/src/lib/services/fulfillment/fulfillment.service.ts @@ -13,6 +13,8 @@ import { FulfillmentFulfillmentMutateMutation, FulfillmentFulfillmentReadGQL, FulfillmentFulfillmentReadQuery, + FulfillmentFulfillmentSubmitGQL, + FulfillmentFulfillmentSubmitMutation, } from '@console-core/graphql'; @Injectable({ @@ -22,6 +24,7 @@ export class FulfillmentService { constructor( private readonly invoicingFulfillmentReadGQL: FulfillmentFulfillmentReadGQL, private readonly invoicingFulfillmentMutateGQL: FulfillmentFulfillmentMutateGQL, + private readonly fulfillmentSubmitGQL: FulfillmentFulfillmentSubmitGQL, private readonly invoicingFulfillmentDeleteMutateGQL: FulfillmentFulfillmentDeleteMutateGQL ) {} @@ -41,6 +44,14 @@ export class FulfillmentService { }); } + submit( + payload: IIoRestorecommerceFulfillmentFulfillmentList + ): Observable> { + return this.fulfillmentSubmitGQL.mutate({ + input: payload, + }); + } + remove( payload: IIoRestorecommerceResourcebaseDeleteRequest ): Observable> {