Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #125 from jonyw4/Fixes
Browse files Browse the repository at this point in the history
fix: patch shipping packages on update
  • Loading branch information
jonyw4 authored Nov 19, 2020
2 parents 34b56cf + 53c6100 commit d1270e1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
26 changes: 13 additions & 13 deletions packages/core/src/api/admin.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ const adminApiExtensions = gql`
name: String!
massUnit: MassUnit!
distanceUnit: DistanceUnit!
width: Int!
height: Int!
length: Int!
weight: Int!
width: Float!
height: Float!
length: Float!
weight: Float!
enabled: Boolean!
}
input CreatePackageInput {
name: String!
massUnit: MassUnit!
distanceUnit: DistanceUnit!
width: Int!
height: Int!
length: Int!
weight: Int!
width: Float!
height: Float!
length: Float!
weight: Float!
enabled: Boolean!
}
Expand All @@ -40,15 +40,15 @@ const adminApiExtensions = gql`
name: String
massUnit: MassUnit
distanceUnit: DistanceUnit
width: Int
height: Int
length: Int
weight: Int
width: Float
height: Float
length: Float
weight: Float
enabled: Boolean
}
type PackageList implements PaginatedList {
items: [Package!]!
totalItems: Int!
totalItems: Float!
}
extend type Query {
packages(options: PackageListOptions): PackageList!
Expand Down
28 changes: 20 additions & 8 deletions packages/core/src/services/shipping-packages.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { ID, Order, Product, EntityNotFoundError } from '@vendure/core';
import {
ID,
Order,
Product,
EntityNotFoundError,
patchEntity
} from '@vendure/core';
import { Injectable } from '@nestjs/common';
import { InjectConnection } from '@nestjs/typeorm';
import { Connection } from 'typeorm';
Expand Down Expand Up @@ -34,18 +40,24 @@ export class ShippingPackagesService {
}

async create(order: Order): Promise<ShippingPackages> {
const shippingPackages = await this.getOrderShippingPackages(order.id);

const newShippingPackages = new ShippingPackages({
id: shippingPackages?.id || undefined,
const shippingPackagesInput = {
order: order,
packages: await this.getPackagesForShipping(order)
});
};

if (!order.id) {
return newShippingPackages;
return new ShippingPackages(shippingPackagesInput);
}
return this.connection.manager.save(newShippingPackages);

const currentShippingPackages = await this.getOrderShippingPackages(
order.id
);

return this.connection.manager.save(
currentShippingPackages
? patchEntity(currentShippingPackages, shippingPackagesInput)
: new ShippingPackages(shippingPackagesInput)
);
}

/**
Expand Down

0 comments on commit d1270e1

Please sign in to comment.