Skip to content

Commit

Permalink
fix(core): Handle relation customFields when creating Fulfillments
Browse files Browse the repository at this point in the history
Fixes #816
  • Loading branch information
michaelbromley committed Apr 12, 2021
1 parent 5e181ea commit 9559e34
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions packages/core/src/service/services/fulfillment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { OrderItem } from '../../entity/order-item/order-item.entity';
import { Order } from '../../entity/order/order.entity';
import { EventBus } from '../../event-bus/event-bus';
import { FulfillmentStateTransitionEvent } from '../../event-bus/events/fulfillment-state-transition-event';
import { CustomFieldRelationService } from '../helpers/custom-field-relation/custom-field-relation.service';
import { FulfillmentState } from '../helpers/fulfillment-state-machine/fulfillment-state';
import { FulfillmentStateMachine } from '../helpers/fulfillment-state-machine/fulfillment-state-machine';
import { TransactionalConnection } from '../transaction/transactional-connection';
Expand All @@ -27,6 +28,7 @@ export class FulfillmentService {
private fulfillmentStateMachine: FulfillmentStateMachine,
private eventBus: EventBus,
private configService: ConfigService,
private customFieldRelationService: CustomFieldRelationService,
) {}

async create(
Expand Down Expand Up @@ -56,15 +58,24 @@ export class FulfillmentService {
}
return new CreateFulfillmentError(message);
}
const newFulfillment = new Fulfillment({
method: '',
trackingCode: '',
...fulfillmentPartial,
orderItems: items,
state: this.fulfillmentStateMachine.getInitialState(),
handlerCode: fulfillmentHandler.code,
});
return this.connection.getRepository(ctx, Fulfillment).save(newFulfillment);

const newFulfillment = await this.connection.getRepository(ctx, Fulfillment).save(
new Fulfillment({
method: '',
trackingCode: '',
...fulfillmentPartial,
orderItems: items,
state: this.fulfillmentStateMachine.getInitialState(),
handlerCode: fulfillmentHandler.code,
}),
);
await this.customFieldRelationService.updateRelations(
ctx,
Fulfillment,
fulfillmentPartial,
newFulfillment,
);
return newFulfillment;
}

async findOneOrThrow(
Expand Down

0 comments on commit 9559e34

Please sign in to comment.