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

Commit b44b6a8

Browse files
authored
fix: update shippingPackages in postgres
1 parent f1fc888 commit b44b6a8

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

packages/core/src/services/shipping-packages.service.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff 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
/**

0 commit comments

Comments
 (0)