Skip to content

Commit

Permalink
feat(fulfilment): submit fulfilment
Browse files Browse the repository at this point in the history
  • Loading branch information
belsman committed Oct 25, 2024
1 parent b34640a commit 30318e2
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 20 deletions.
12 changes: 12 additions & 0 deletions packages/core/graphql/src/lib/documents/fragments/fulfillment.gql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ fragment FulfillmentFragment on IoRestorecommerceFulfillmentFulfillment {
customerId
shopId
userId
labels {
pdf
png
shipmentNumber
state
parcelId
url
status {
code
message
}
}
packaging {
exportType
notify
Expand Down
68 changes: 68 additions & 0 deletions packages/core/graphql/src/lib/generated/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5993,6 +5993,20 @@ export type FulfillmentFragmentFragment = {
shopId?: string | null;
userId?: string | null;
fulfillmentState?: IoRestorecommerceFulfillmentFulfillmentState | null;
labels?: Array<{
__typename?: 'IoRestorecommerceFulfillmentLabel';
pdf?: string | null;
png?: string | null;
shipmentNumber?: string | null;
state?: IoRestorecommerceFulfillmentFulfillmentState | null;
parcelId?: string | null;
url?: string | null;
status?: {
__typename?: 'IoRestorecommerceStatusStatus';
code?: number | null;
message?: string | null;
} | null;
}> | null;
packaging?: {
__typename?: 'IoRestorecommerceFulfillmentPackaging';
exportType?: string | null;
Expand Down Expand Up @@ -7319,6 +7333,20 @@ export type FulfillmentFulfillmentMutateMutation = {
shopId?: string | null;
userId?: string | null;
fulfillmentState?: IoRestorecommerceFulfillmentFulfillmentState | null;
labels?: Array<{
__typename?: 'IoRestorecommerceFulfillmentLabel';
pdf?: string | null;
png?: string | null;
shipmentNumber?: string | null;
state?: IoRestorecommerceFulfillmentFulfillmentState | null;
parcelId?: string | null;
url?: string | null;
status?: {
__typename?: 'IoRestorecommerceStatusStatus';
code?: number | null;
message?: string | null;
} | null;
}> | null;
packaging?: {
__typename?: 'IoRestorecommerceFulfillmentPackaging';
exportType?: string | null;
Expand Down Expand Up @@ -7460,6 +7488,20 @@ export type FulfillmentFulfillmentReadQuery = {
shopId?: string | null;
userId?: string | null;
fulfillmentState?: IoRestorecommerceFulfillmentFulfillmentState | null;
labels?: Array<{
__typename?: 'IoRestorecommerceFulfillmentLabel';
pdf?: string | null;
png?: string | null;
shipmentNumber?: string | null;
state?: IoRestorecommerceFulfillmentFulfillmentState | null;
parcelId?: string | null;
url?: string | null;
status?: {
__typename?: 'IoRestorecommerceStatusStatus';
code?: number | null;
message?: string | null;
} | null;
}> | null;
packaging?: {
__typename?: 'IoRestorecommerceFulfillmentPackaging';
exportType?: string | null;
Expand Down Expand Up @@ -7576,6 +7618,20 @@ export type FulfillmentFulfillmentSubmitMutation = {
shopId?: string | null;
userId?: string | null;
fulfillmentState?: IoRestorecommerceFulfillmentFulfillmentState | null;
labels?: Array<{
__typename?: 'IoRestorecommerceFulfillmentLabel';
pdf?: string | null;
png?: string | null;
shipmentNumber?: string | null;
state?: IoRestorecommerceFulfillmentFulfillmentState | null;
parcelId?: string | null;
url?: string | null;
status?: {
__typename?: 'IoRestorecommerceStatusStatus';
code?: number | null;
message?: string | null;
} | null;
}> | null;
packaging?: {
__typename?: 'IoRestorecommerceFulfillmentPackaging';
exportType?: string | null;
Expand Down Expand Up @@ -10718,6 +10774,18 @@ export const FulfillmentFragmentFragmentDoc = gql`
customerId
shopId
userId
labels {
pdf
png
shipmentNumber
state
parcelId
url
status {
code
message
}
}
packaging {
exportType
notify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const fulfillmentCreateFail = createAction(

export const fulfillmentSubmitRequest = createAction(
'[FULFILLMENT] Submit request',
props<{ payload: IIoRestorecommerceResourcebaseReadRequest }>()
props<{ payload: { id: string } }>()
);

export const fulfillmentSubmitSuccess = createAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,25 +206,34 @@ export class FulfillmentEffects {
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 })
this.fulfillmentService
.submit({
items: [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;

console.log('Payload:', payload);

return fulfillmentActions.fulfillmentSubmitSuccess({ payload });
}),
catchError((error: Error) =>
of(
fulfillmentActions.fulfillmentSubmitFail({
error: error.message,
})
)
)
)
)
)
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export class FulfillmentFacade {
);

// TODO Submit a fulfilment.
submit = (payload: { id: string }) =>
this.store.dispatch(
fulfillmentActions.fulfillmentSubmitRequest({ payload })
);

constructor(private readonly store: Store) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class FulfillmentTemplateComponent implements OnInit, OnDestroy {
return;
}

// TODO this.fulfillmentFacade.submitFulfilment(id);
this.fulfillmentFacade.submit({ id });
})
);

Expand Down Expand Up @@ -126,6 +126,7 @@ export class FulfillmentTemplateComponent implements OnInit, OnDestroy {
triggerRead: this.triggerRead$,
triggerSelectId: this.triggerSelectId$,
triggerRemove: this.triggerRemove$,
triggerSubmitFulfillment: this.triggerSubmitFulfillment$,
});

private readonly subscriptions = new SubSink();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
isTriggerSubmitFulfillment &&
[EUrlSegment.View].includes(urlSegment)
"
(click)="onCreateFulfillment(id)"
(click)="onSubmitFulfillment(id)"
vcl-button
rc-append
class="square half-transparent button"
Expand Down

0 comments on commit 30318e2

Please sign in to comment.