Skip to content

Commit

Permalink
feat: create new actions for fulfilment submission
Browse files Browse the repository at this point in the history
  • Loading branch information
belsman committed Oct 14, 2024
1 parent 143c6f4 commit 876e381
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
FulfillmentFulfillmentMutateMutation,
FulfillmentFulfillmentReadGQL,
FulfillmentFulfillmentReadQuery,
FulfillmentFulfillmentSubmitGQL,
FulfillmentFulfillmentSubmitMutation,
} from '@console-core/graphql';

@Injectable({
Expand All @@ -22,6 +24,7 @@ export class FulfillmentService {
constructor(
private readonly invoicingFulfillmentReadGQL: FulfillmentFulfillmentReadGQL,
private readonly invoicingFulfillmentMutateGQL: FulfillmentFulfillmentMutateGQL,
private readonly fulfillmentSubmitGQL: FulfillmentFulfillmentSubmitGQL,
private readonly invoicingFulfillmentDeleteMutateGQL: FulfillmentFulfillmentDeleteMutateGQL
) {}

Expand All @@ -41,6 +44,14 @@ export class FulfillmentService {
});
}

submit(
payload: IIoRestorecommerceFulfillmentFulfillmentList
): Observable<MutationResult<FulfillmentFulfillmentSubmitMutation>> {
return this.fulfillmentSubmitGQL.mutate({
input: payload,
});
}

remove(
payload: IIoRestorecommerceResourcebaseDeleteRequest
): Observable<MutationResult<FulfillmentFulfillmentDeleteMutateMutation>> {
Expand Down

0 comments on commit 876e381

Please sign in to comment.