@social-mail/social-mail-web-server 1.4.688 → 1.4.690

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-web-server",
3
- "version": "1.4.688",
3
+ "version": "1.4.690",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -709,6 +709,10 @@ export class StoreItemPrice {
709
709
  @Column({ dataType: "Decimal", nullable: true })
710
710
  maxAmount: number;
711
711
 
712
+ @Column({ dataType: "Decimal", default: () => 0})
713
+ @ReadOnlyJsonProperty
714
+ readonly taxAmount: number;
715
+
712
716
  @Column({ dataType: "Boolean", default: () => true})
713
717
  active: boolean;
714
718
 
@@ -79,6 +79,9 @@ export default class StoreItemPriceEvents extends AuthenticatedEvents<StoreItemP
79
79
 
80
80
  beforeUpdate(entity: StoreItemPrice, entry: ChangeEntry<StoreItemPrice>) {
81
81
  this.sessionUser.ensureLoggedIn();
82
+ if (entry.modified.size === 0) {
83
+ return;
84
+ }
82
85
  if (!entry.isModified("active")) {
83
86
  throw new EntityAccessError(`Item Price can only be deactivated, it cannot be modified.`);
84
87
  }
@@ -3,6 +3,9 @@ import AuthenticatedEvents from "./AuthenticatedEvents.js";
3
3
  import EntityAccessError from "@entity-access/entity-access/dist/common/EntityAccessError.js";
4
4
  import { StoreItemTax } from "../entities/Store.js";
5
5
  import ChangeEntry from "@entity-access/entity-access/dist/model/changes/ChangeEntry.js";
6
+ import SocialMailContext from "../SocialMailContext.js";
7
+ import { ServiceProvider } from "@entity-access/entity-access/dist/di/di.js";
8
+ import Sql from "@entity-access/entity-access/dist/sql/Sql.js";
6
9
 
7
10
  export default class StoreItemTaxEvents extends AuthenticatedEvents<StoreItemTax> {
8
11
 
@@ -44,4 +47,24 @@ export default class StoreItemTaxEvents extends AuthenticatedEvents<StoreItemTax
44
47
  this.sessionUser.ensureLoggedIn();
45
48
  }
46
49
 
47
- }
50
+ afterInsert(entity: StoreItemTax, entry: ChangeEntry<StoreItemTax>) {
51
+ return this.updatePrices(entity);
52
+ }
53
+
54
+ afterUpdate(entity: StoreItemTax, entry: ChangeEntry<StoreItemTax>) {
55
+ return this.updatePrices(entity);
56
+ }
57
+
58
+ afterDelete(entity: StoreItemTax, entry: ChangeEntry<StoreItemTax>) {
59
+ return this.updatePrices(entity);
60
+ }
61
+
62
+ async updatePrices(entity: StoreItemTax) {
63
+ const db = ServiceProvider.resolve(this, SocialMailContext);
64
+ await db.storeItemPrices.where(entity, (p) => (x) => x.storeItemID === p.storeItemID)
65
+ .update(void 0, (p) => (x) => ({
66
+ taxAmount: x.amount * Sql.coll.sum(x.storeItem.taxes
67
+ .map((t) => Sql.coll.sum(t.taxItem.storeItemPrices.map((tp) => tp.amount))))
68
+ }));
69
+ }
70
+ }