This repository was archived by the owner on Jan 15, 2022. It is now read-only.
File tree Expand file tree Collapse file tree
packages/core/src/services Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,24 +40,29 @@ export class ShippingPackagesService {
4040 }
4141
4242 async create ( order : Order ) : Promise < ShippingPackages > {
43- const shippingPackagesInput = {
43+ const packages = await this . getPackagesForShipping ( order ) ;
44+ const newShippingPackages = new ShippingPackages ( {
4445 order : order ,
45- packages : await this . getPackagesForShipping ( order )
46- } ;
47-
46+ packages
47+ } ) ;
48+
4849 if ( ! order . id ) {
49- return new ShippingPackages ( shippingPackagesInput ) ;
50+ return newShippingPackages ;
5051 }
5152
5253 const currentShippingPackages = await this . getOrderShippingPackages (
5354 order . id
5455 ) ;
5556
56- return this . connection . manager . save (
57- currentShippingPackages
58- ? patchEntity ( currentShippingPackages , shippingPackagesInput )
59- : new ShippingPackages ( shippingPackagesInput )
60- ) ;
57+ // UPDATE
58+ if ( currentShippingPackages ) {
59+ this . connection . manager . merge ( currentShippingPackages , { packages } ) ;
60+ // Fix the update problem in postgres https://github.com/typeorm/typeorm/issues/4122
61+ delete currentShippingPackages . order ;
62+ return this . connection . manager . save ( currentShippingPackages ) ;
63+ }
64+ // SAVE
65+ return this . connection . manager . save ( newShippingPackages ) ;
6166 }
6267
6368 /**
You can’t perform that action at this time.
0 commit comments