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

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.
Files changed (42) hide show
  1. package/dist/server/model/SocialMailContext.d.ts +2 -2
  2. package/dist/server/model/SocialMailContext.d.ts.map +1 -1
  3. package/dist/server/model/SocialMailContext.js +3 -2
  4. package/dist/server/model/SocialMailContext.js.map +1 -1
  5. package/dist/server/model/SocialMailContextEvents.d.ts.map +1 -1
  6. package/dist/server/model/SocialMailContextEvents.js +4 -3
  7. package/dist/server/model/SocialMailContextEvents.js.map +1 -1
  8. package/dist/server/model/entities/Store.d.ts +12 -19
  9. package/dist/server/model/entities/Store.d.ts.map +1 -1
  10. package/dist/server/model/entities/Store.js +28 -34
  11. package/dist/server/model/entities/Store.js.map +1 -1
  12. package/dist/server/model/events/StoreItemPriceEvents.d.ts.map +1 -1
  13. package/dist/server/model/events/StoreItemPriceEvents.js +9 -0
  14. package/dist/server/model/events/StoreItemPriceEvents.js.map +1 -1
  15. package/dist/server/model/events/StoreItemTaxEvents.d.ts +13 -0
  16. package/dist/server/model/events/StoreItemTaxEvents.d.ts.map +1 -0
  17. package/dist/server/model/events/StoreItemTaxEvents.js +37 -0
  18. package/dist/server/model/events/StoreItemTaxEvents.js.map +1 -0
  19. package/dist/server/services/accounts/sales/SalesInvoiceService.d.ts +4 -3
  20. package/dist/server/services/accounts/sales/SalesInvoiceService.d.ts.map +1 -1
  21. package/dist/server/services/accounts/sales/SalesInvoiceService.js +16 -4
  22. package/dist/server/services/accounts/sales/SalesInvoiceService.js.map +1 -1
  23. package/dist/tests/store/create-order.d.ts.map +1 -1
  24. package/dist/tests/store/create-order.js +1 -2
  25. package/dist/tests/store/create-order.js.map +1 -1
  26. package/dist/tests/store/create-store.js +21 -13
  27. package/dist/tests/store/create-store.js.map +1 -1
  28. package/dist/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +1 -1
  30. package/src/server/model/SocialMailContext.ts +4 -2
  31. package/src/server/model/SocialMailContextEvents.ts +5 -3
  32. package/src/server/model/entities/Store.ts +27 -43
  33. package/src/server/model/events/StoreItemPriceEvents.ts +10 -0
  34. package/src/server/model/events/StoreItemTaxEvents.ts +47 -0
  35. package/src/server/services/accounts/sales/SalesInvoiceService.ts +14 -5
  36. package/src/tests/store/create-order.ts +1 -2
  37. package/src/tests/store/create-store.ts +24 -15
  38. package/dist/server/model/events/StorePriceAddOnEvents.d.ts +0 -17
  39. package/dist/server/model/events/StorePriceAddOnEvents.d.ts.map +0 -1
  40. package/dist/server/model/events/StorePriceAddOnEvents.js +0 -60
  41. package/dist/server/model/events/StorePriceAddOnEvents.js.map +0 -1
  42. package/src/server/model/events/StorePriceAddOnEvents.ts +0 -75
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-web-server",
3
- "version": "1.4.686",
3
+ "version": "1.4.688",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -37,7 +37,7 @@ import EmailEngagement from "./entities/EmailEngagement.js";
37
37
  import MailboxContactTag from "./entities/MailboxContactTag.js";
38
38
  import ChannelConfig from "./entities/ChannelConfig.js";
39
39
  import UserPushSubscription from "./entities/UserSubscriptions.js";
40
- import Store, { StoreConfig, StoreInsight, StoreItem, StoreItemFolder, StoreItemPrice, StoreItemTag, StoreJournal, StoreJournalEntry, StoreJournalLineItem, StoreLedger, StoreMediaFile, StorePriceAddOn, StoreUser } from "./entities/Store.js";
40
+ import Store, { StoreConfig, StoreInsight, StoreItem, StoreItemFolder, StoreItemPrice, StoreItemTag, StoreItemTax, StoreJournal, StoreJournalEntry, StoreJournalLineItem, StoreLedger, StoreMediaFile, StoreUser } from "./entities/Store.js";
41
41
  import RateLimitToken from "./entities/RateLimitToken.js";
42
42
  import AccessToken from "./entities/AccessToken.js";
43
43
  import ServerActivity from "./entities/ServerActivity.js";
@@ -135,7 +135,7 @@ export default class SocialMailContext extends EntityContext {
135
135
 
136
136
  public storeItemPrices = this.model.register(StoreItemPrice);
137
137
 
138
- public storePriceAddOns = this.model.register(StorePriceAddOn);
138
+ // public storePriceAddOns = this.model.register(StorePriceAddOn);
139
139
 
140
140
  public storeMediaFiles = this.model.register(StoreMediaFile);
141
141
 
@@ -149,6 +149,8 @@ export default class SocialMailContext extends EntityContext {
149
149
 
150
150
  public storeJournalLineItems = this.model.register(StoreJournalLineItem);
151
151
 
152
+ public storeItemTaxes = this.model.register(StoreItemTax);
153
+
152
154
  // public storeOrders = this.model.register(StoreBill);
153
155
 
154
156
  // public storeOrderItem = this.model.register(StoreBillLine);
@@ -68,7 +68,7 @@ import UserPushSubscription from "./entities/UserSubscriptions.js";
68
68
  import UserPushSubscriptionEvents from "./events/UserPushSubscriptionEvents.js";
69
69
  import EmailEngagement from "./entities/EmailEngagement.js";
70
70
  import EmailEngagementEvents from "./events/EmailEngagementEvents.js";
71
- import Store, { StoreConfig, StoreInsight, StoreItem, StoreItemFolder, StoreItemPrice, StoreItemTag, StoreJournal, StoreJournalEntry, StoreJournalLineItem, StoreLedger, StoreMediaFile, StorePriceAddOn, StoreUser } from "./entities/Store.js";
71
+ import Store, { StoreConfig, StoreInsight, StoreItem, StoreItemFolder, StoreItemPrice, StoreItemTag, StoreItemTax, StoreJournal, StoreJournalEntry, StoreJournalLineItem, StoreLedger, StoreMediaFile, StoreUser } from "./entities/Store.js";
72
72
  import StoreEvents from "./events/StoreEvents.js";
73
73
  import StoreItemEvents from "./events/StoreItemEvents.js";
74
74
  // import StoreOrderEvents from "./events/StoreOrderEvents.js";
@@ -87,7 +87,8 @@ import StoreJournalLineItemEvents from "./events/StoreJournalLineItemEvents.js";
87
87
  import StoreItemFolderEvents from "./events/StoreItemFolderEvents.js";
88
88
  import StoreConfigEvents from "./events/StoreConfigEvents.js";
89
89
  import StoreMediaFileEvents from "./events/StoreMediaFileEvents.js";
90
- import StorePriceAddOnEvents from "./events/StorePriceAddOnEvents.js";
90
+ import StorePriceAddOnEvents from "./events/StoreItemTaxEvents.js";
91
+ import StoreItemTaxEvents from "./events/StoreItemTaxEvents.js";
91
92
 
92
93
  @RegisterSingleton
93
94
  export default class SocialMailContextEvents extends ContextEvents {
@@ -137,7 +138,8 @@ export default class SocialMailContextEvents extends ContextEvents {
137
138
  this.register(StoreItemFolder, StoreItemFolderEvents);
138
139
  this.register(StoreMediaFile, StoreMediaFileEvents);
139
140
  this.register(StoreConfig, StoreConfigEvents);
140
- this.register(StorePriceAddOn, StorePriceAddOnEvents);
141
+ this.register(StoreItemTax, StoreItemTaxEvents);
142
+ // this.register(StorePriceAddOn, StorePriceAddOnEvents);
141
143
  // this.register(StoreBill, StoreOrderEvents);
142
144
  // this.register(StoreBillLine, StoreOrderItemEvents);
143
145
  this.register(StoreItemTag, StoreItemTagEvents);
@@ -22,10 +22,7 @@ export type orderStatusType = typeof orderStatuses[number];
22
22
  const journalTypeArray = [ "order", "purchase-order", "sales-invoice", "journal", "purchase-bill", "payment"] as const;
23
23
  export type journalTypeArrayType = typeof journalTypeArray[number];
24
24
 
25
- const lineItemTypeArray = ["commission", "fee", "tax", "variant", "size"] as const;
26
- export type lineItemTypeArrayType = typeof lineItemTypeArray[number];
27
-
28
- const itemTypeArray = ["product", "service", "tax", "fee", "commission", "variant", "size"] as const;
25
+ const itemTypeArray = ["product", "e-product", "shipping", "service", "tax", "fee", "commission", "variant", "size"] as const;
29
26
  export type itemTypeArrayType = typeof itemTypeArray[number];
30
27
 
31
28
  @Table("Stores")
@@ -244,6 +241,15 @@ export class StoreJournal {
244
241
  })
245
242
  folderID: number;
246
243
 
244
+ @Column({ dataType: "Boolean", default: () => false })
245
+ taxExempt: boolean;
246
+
247
+ @Column({ dataType: "Char", nullable: true})
248
+ taxExemptNotes: string;
249
+
250
+ @Column({ dataType: "Char", nullable: true})
251
+ taxExemptTaxID: string;
252
+
247
253
  buyer: Contact;
248
254
  seller: Contact;
249
255
 
@@ -382,7 +388,6 @@ export class StoreItemFolder {
382
388
  parent: StoreItemFolder;
383
389
  children: StoreItemFolder[];
384
390
  items: StoreItem[];
385
- taxLineItems: StoreJournalLineItem[];
386
391
  }
387
392
 
388
393
 
@@ -490,7 +495,8 @@ export class StoreItem {
490
495
  ledgers: StoreLedger[];
491
496
  itemFolder: StoreItemFolder;
492
497
  mediaFiles: StoreMediaFile[];
493
- priceAddOns: StorePriceAddOn[];
498
+ taxes: StoreItemTax[];
499
+ taxItems: StoreItemTax[];
494
500
 
495
501
  [GraphService.init](sp) {
496
502
  const ss = ServiceProvider.resolve(sp, SignerService);
@@ -706,41 +712,36 @@ export class StoreItemPrice {
706
712
  @Column({ dataType: "Boolean", default: () => true})
707
713
  active: boolean;
708
714
 
709
- @Column({ dataType: "Decimal", default: () => 0})
710
- addonsAmount: number;
711
-
712
715
  storeItem: StoreItem;
713
716
  lineItems: StoreJournalLineItem[];
714
- addons: StorePriceAddOn[];
715
717
  // storeOrderItems: StoreBillLine[];
716
718
 
717
719
  }
718
720
 
719
- @Table("StorePriceAddOns")
720
- export class StorePriceAddOn {
721
-
722
- @Column({ dataType: "BigInt", key: true })
723
- @RelateTo(StoreItemPrice, {
724
- property: (x) => x.price,
725
- inverseProperty: (x) => x.addons
721
+ @Table("StoreItemTaxes")
722
+ export class StoreItemTax {
723
+ @Column({dataType: "BigInt", key: true})
724
+ @RelateTo(StoreItem, {
725
+ property: (x) => x.storeItem,
726
+ inverseProperty: (x) => x.taxes
726
727
  })
727
- priceID: number;
728
+ storeItemID: number;
729
+ storeItem: StoreItem;
728
730
 
729
731
  @Column({ dataType: "BigInt", key: true })
730
732
  @RelateTo(StoreItem, {
731
- property: (x) => x.addOnItem,
732
- inverseProperty: (x) => x.priceAddOns
733
+ property: (x) => x.taxItem,
734
+ inverseProperty: (x) => x.taxItems
733
735
  })
734
- addOnItemID: number;
736
+ taxItemID: number;
737
+ taxItem: StoreItem;
735
738
 
736
- @Column({ dataType: "Boolean", default: () => false })
739
+ @Column({ dataType: "Boolean", default: () => false})
737
740
  inclusive: boolean;
738
741
 
739
742
  @Column({ dataType: "Boolean", default: () => true})
740
743
  print: boolean;
741
744
 
742
- price: StoreItemPrice;
743
- addOnItem: StoreItem;
744
745
  }
745
746
 
746
747
  @Table("StoreJournalLineItems")
@@ -786,8 +787,8 @@ export class StoreJournalLineItem {
786
787
  @Column({ dataType: "Boolean", default: () => false})
787
788
  public inclusive: boolean;
788
789
 
789
- @Column({ dataType: "Char", length: 50, nullable: true, enum: lineItemTypeArray })
790
- public itemType: lineItemTypeArrayType;
790
+ @Column({ dataType: "Char", length: 50, nullable: true, enum: itemTypeArray })
791
+ public itemType: itemTypeArrayType;
791
792
 
792
793
  @Column({ dataType: "Boolean", default: () => false})
793
794
  public hide: boolean;
@@ -806,22 +807,6 @@ export class StoreJournalLineItem {
806
807
  })
807
808
  public sourceID: number;
808
809
 
809
- /**
810
- * This is for reference only,
811
- * However, relations are configured to assist in UI
812
- */
813
- @Column({ dataType: "BigInt", nullable: true })
814
- @RelateTo(StoreItemFolder, {
815
- property: (x) => x.taxFolder,
816
- inverseProperty: (x) => x.taxLineItems,
817
- /** This FK is only for reference,
818
- * as we might never lookup items
819
- * based on this index.
820
- */
821
- dotNotCreateIndex: true,
822
- })
823
- public taxFolderID: number;
824
-
825
810
  journal: StoreJournal;
826
811
  vendor: Contact;
827
812
  item: StoreItem;
@@ -829,7 +814,6 @@ export class StoreJournalLineItem {
829
814
  source: StoreJournalLineItem;
830
815
  relatedItems: StoreJournalLineItem[];
831
816
  entries: StoreJournalEntry[];
832
- taxFolder: StoreItemFolder;
833
817
  }
834
818
 
835
819
 
@@ -79,6 +79,16 @@ 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.isModified("active")) {
83
+ throw new EntityAccessError(`Item Price can only be deactivated, it cannot be modified.`);
84
+ }
85
+ if (entry.modified.size > 1) {
86
+ throw new EntityAccessError(`Item Price can only be deactivated, it cannot be modified.`);
87
+ }
88
+ if (entry.isModified("active") && entity.active) {
89
+ throw new EntityAccessError(`Item Price can only be reactivated, add new price again.`);
90
+ }
82
91
  }
83
92
 
93
+
84
94
  }
@@ -0,0 +1,47 @@
1
+ import { IEntityQuery } from "@entity-access/entity-access/dist/model/IFilterWithParameter.js";
2
+ import AuthenticatedEvents from "./AuthenticatedEvents.js";
3
+ import EntityAccessError from "@entity-access/entity-access/dist/common/EntityAccessError.js";
4
+ import { StoreItemTax } from "../entities/Store.js";
5
+ import ChangeEntry from "@entity-access/entity-access/dist/model/changes/ChangeEntry.js";
6
+
7
+ export default class StoreItemTaxEvents extends AuthenticatedEvents<StoreItemTax> {
8
+
9
+ filter(query: IEntityQuery<StoreItemTax>) {
10
+ if (!this.verify) {
11
+ return query;
12
+ }
13
+ const { sessionUser } = this;
14
+ if (sessionUser.isAdmin) {
15
+ return query;
16
+ }
17
+ return query.where(sessionUser, (p) => (x) => x.storeItem.store.storeUsers.some((u) => u.userID === p.userID));
18
+ }
19
+
20
+ modify(query: IEntityQuery<StoreItemTax>) {
21
+ return this.filter(query);
22
+ }
23
+
24
+ delete(query: IEntityQuery<StoreItemTax>): IEntityQuery<StoreItemTax> {
25
+ if (!this.verify) {
26
+ return query;
27
+ }
28
+ const { sessionUser } = this;
29
+ if (sessionUser.isAdmin) {
30
+ return query;
31
+ }
32
+ throw new EntityAccessError("Only admin can delete the store.");
33
+ }
34
+
35
+ includeFilter(query: IEntityQuery<StoreItemTax>, type?: any, key?: string) {
36
+ return query;
37
+ }
38
+
39
+ beforeInsert(entity: StoreItemTax, entry: ChangeEntry<StoreItemTax>) {
40
+ this.sessionUser.ensureLoggedIn();
41
+ }
42
+
43
+ beforeUpdate(entity: StoreItemTax, entry: ChangeEntry<StoreItemTax>) {
44
+ this.sessionUser.ensureLoggedIn();
45
+ }
46
+
47
+ }
@@ -1,6 +1,6 @@
1
1
  import Inject, { RegisterScoped, RegisterTransient } from "@entity-access/entity-access/dist/di/di.js";
2
2
  import ChangeEntry from "@entity-access/entity-access/dist/model/changes/ChangeEntry.js";
3
- import { StoreJournal, StoreLedger } from "../../../model/entities/Store.js";
3
+ import { StoreItemPrice, StoreJournal, StoreLedger } from "../../../model/entities/Store.js";
4
4
  import ChartOfAccounts from "../chart-of-accounts/ChartOfAccounts.js";
5
5
  import { AccountNames } from "../chart-of-accounts/AccountNames.js";
6
6
  import { AccountHeads } from "../chart-of-accounts/AccountHeads.js";
@@ -33,12 +33,9 @@ export default class SalesInvoiceService {
33
33
  itemPrice = itemPrice ?? await this.getPrice(lineItem.itemPriceID);
34
34
  lineItem.amount = itemPrice.amount;
35
35
 
36
- if (!lineItem.taxFolderID) {
37
- continue;
38
- }
39
36
  lineItem.relatedItems ??= [];
40
37
 
41
- const itemPrices = await this.getFolderActivePrices(lineItem.taxFolderID, entity.dateCreated);
38
+ const itemPrices = await this.getTaxes(itemPrice.priceID, itemPrice.currency);
42
39
 
43
40
  let itemTotal = Number(lineItem.amount) * Number(lineItem.quantity);
44
41
 
@@ -80,6 +77,18 @@ export default class SalesInvoiceService {
80
77
  entity.balance = total;
81
78
  }
82
79
 
80
+ @cacheFor()
81
+ getTaxes(priceID, currency) {
82
+ return this.db.storeItemPrices
83
+ .where({ priceID, currency }, (p) => (x) => x.currency === p.currency
84
+ && x.storeItem.taxItems
85
+ .some((ti) => ti.storeItem.storeItemPrices
86
+ .some((pi) => pi.priceID === p.priceID
87
+ && pi.currency === p.currency
88
+ )))
89
+ .toArray();
90
+ }
91
+
83
92
  @cacheFor()
84
93
  async getPrice(itemPriceID: number) {
85
94
  return await this.db.storeItemPrices
@@ -27,8 +27,7 @@ export default async function() {
27
27
  db.storeJournalLineItems.add({
28
28
  itemID: personal.storeItemID,
29
29
  itemPriceID: personal.storeItemPrices[0].priceID,
30
- taxFolderID: centerGST.itemFolderID,
31
- quantity: 1
30
+ quantity: 1,
32
31
  })
33
32
  ]
34
33
  });
@@ -29,21 +29,6 @@ async function createStore() {
29
29
 
30
30
  const { storeID } = store;
31
31
 
32
- const personal = db.storeItems.add({
33
- name: "Personal",
34
- store,
35
- storeItemPrices: [
36
- db.storeItemPrices.add({
37
- startDate: DateTime.today,
38
- active: true,
39
- amount: 2000,
40
- currency: "INR"
41
- })
42
- ]
43
- });
44
-
45
- await db.saveChanges();
46
-
47
32
  const centerGST = db.storeItemFolders.add({
48
33
  name: "Center GST",
49
34
  store,
@@ -75,6 +60,30 @@ async function createStore() {
75
60
 
76
61
  await db.saveChanges();
77
62
 
63
+ const personal = db.storeItems.add({
64
+ name: "Personal",
65
+ store,
66
+ taxes: [
67
+ db.storeItemTaxes.add({
68
+ taxItem: centerGST.items[0]
69
+ }),
70
+ db.storeItemTaxes.add({
71
+ taxItem: centerGST.items[1]
72
+ })
73
+ ],
74
+ storeItemPrices: [
75
+ db.storeItemPrices.add({
76
+ startDate: DateTime.today,
77
+ active: true,
78
+ amount: 2000,
79
+ currency: "INR",
80
+ })
81
+ ]
82
+ });
83
+
84
+ await db.saveChanges();
85
+
86
+
78
87
  return {
79
88
  centerGST,
80
89
  personal,
@@ -1,17 +0,0 @@
1
- import { IEntityQuery } from "@entity-access/entity-access/dist/model/IFilterWithParameter.js";
2
- import AuthenticatedEvents from "./AuthenticatedEvents.js";
3
- import { StorePriceAddOn } from "../entities/Store.js";
4
- import ChangeEntry from "@entity-access/entity-access/dist/model/changes/ChangeEntry.js";
5
- export default class StorePriceAddOnEvents extends AuthenticatedEvents<StorePriceAddOn> {
6
- filter(query: IEntityQuery<StorePriceAddOn>): IEntityQuery<StorePriceAddOn>;
7
- modify(query: IEntityQuery<StorePriceAddOn>): IEntityQuery<StorePriceAddOn>;
8
- delete(query: IEntityQuery<StorePriceAddOn>): IEntityQuery<StorePriceAddOn>;
9
- includeFilter(query: IEntityQuery<StorePriceAddOn>, type?: any, key?: string): IEntityQuery<StorePriceAddOn>;
10
- beforeInsert(entity: StorePriceAddOn, entry: ChangeEntry<StorePriceAddOn>): void;
11
- beforeUpdate(entity: StorePriceAddOn, entry: ChangeEntry<StorePriceAddOn>): void;
12
- afterInsert(entity: StorePriceAddOn, entry: ChangeEntry<StorePriceAddOn>): Promise<void>;
13
- afterUpdate(entity: StorePriceAddOn, entry: ChangeEntry<StorePriceAddOn>): Promise<void>;
14
- afterDelete(entity: StorePriceAddOn, entry: ChangeEntry<StorePriceAddOn>): Promise<void>;
15
- private updatePrices;
16
- }
17
- //# sourceMappingURL=StorePriceAddOnEvents.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StorePriceAddOnEvents.d.ts","sourceRoot":"","sources":["../../../../src/server/model/events/StorePriceAddOnEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iEAAiE,CAAC;AAC/F,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,WAAW,MAAM,gEAAgE,CAAC;AAMzF,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,mBAAmB,CAAC,eAAe,CAAC;IAEnF,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,eAAe,CAAC;IAW3C,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,eAAe,CAAC;IAI3C,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,eAAe,CAAC,GAAG,YAAY,CAAC,eAAe,CAAC;IAW3E,aAAa,CAAC,KAAK,EAAE,YAAY,CAAC,eAAe,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM;IAI5E,YAAY,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,CAAC,eAAe,CAAC;IAIzE,YAAY,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,CAAC,eAAe,CAAC;IAInE,WAAW,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,CAAC,eAAe,CAAC;IAIxE,WAAW,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,CAAC,eAAe,CAAC;IAIxE,WAAW,CAAC,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,CAAC,eAAe,CAAC;YAIhE,YAAY;CAY7B"}
@@ -1,60 +0,0 @@
1
- import AuthenticatedEvents from "./AuthenticatedEvents.js";
2
- import EntityAccessError from "@entity-access/entity-access/dist/common/EntityAccessError.js";
3
- import { ServiceProvider } from "@entity-access/entity-access/dist/di/di.js";
4
- import SocialMailContext from "../SocialMailContext.js";
5
- import Sql from "@entity-access/entity-access/dist/sql/Sql.js";
6
- export default class StorePriceAddOnEvents extends AuthenticatedEvents {
7
- filter(query) {
8
- if (!this.verify) {
9
- return query;
10
- }
11
- const { sessionUser } = this;
12
- if (sessionUser.isAdmin) {
13
- return query;
14
- }
15
- return query.where(sessionUser, (p) => (x) => x.price.storeItem.store.storeUsers.some((u) => u.userID === p.userID));
16
- }
17
- modify(query) {
18
- return this.filter(query);
19
- }
20
- delete(query) {
21
- if (!this.verify) {
22
- return query;
23
- }
24
- const { sessionUser } = this;
25
- if (sessionUser.isAdmin) {
26
- return query;
27
- }
28
- throw new EntityAccessError("Only admin can delete the store.");
29
- }
30
- includeFilter(query, type, key) {
31
- return query;
32
- }
33
- beforeInsert(entity, entry) {
34
- this.sessionUser.ensureLoggedIn();
35
- }
36
- beforeUpdate(entity, entry) {
37
- this.sessionUser.ensureLoggedIn();
38
- }
39
- async afterInsert(entity, entry) {
40
- await this.updatePrices(entity);
41
- }
42
- async afterUpdate(entity, entry) {
43
- await this.updatePrices(entity);
44
- }
45
- async afterDelete(entity, entry) {
46
- await this.updatePrices(entity);
47
- }
48
- async updatePrices(entity) {
49
- const db = ServiceProvider.resolve(this, SocialMailContext);
50
- await db.storeItemPrices.where(entity, (p) => (x) => x.priceID === p.priceID)
51
- .update(entity, (p) => (x) => ({
52
- addonsAmount: x.amount * Sql.coll.sum(x.addons
53
- .map((m) => Sql.coll.sum(m.addOnItem
54
- .storeItemPrices
55
- .filter((ap) => ap.currency === x.currency)
56
- .map((ap) => ap.amount))))
57
- }));
58
- }
59
- }
60
- //# sourceMappingURL=StorePriceAddOnEvents.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StorePriceAddOnEvents.js","sourceRoot":"","sources":["../../../../src/server/model/events/StorePriceAddOnEvents.ts"],"names":[],"mappings":"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"}
@@ -1,75 +0,0 @@
1
- import { IEntityQuery } from "@entity-access/entity-access/dist/model/IFilterWithParameter.js";
2
- import AuthenticatedEvents from "./AuthenticatedEvents.js";
3
- import EntityAccessError from "@entity-access/entity-access/dist/common/EntityAccessError.js";
4
- import { StorePriceAddOn } from "../entities/Store.js";
5
- import ChangeEntry from "@entity-access/entity-access/dist/model/changes/ChangeEntry.js";
6
- import DateTime from "@entity-access/entity-access/dist/types/DateTime.js";
7
- import { ServiceProvider } from "@entity-access/entity-access/dist/di/di.js";
8
- import SocialMailContext from "../SocialMailContext.js";
9
- import Sql from "@entity-access/entity-access/dist/sql/Sql.js";
10
-
11
- export default class StorePriceAddOnEvents extends AuthenticatedEvents<StorePriceAddOn> {
12
-
13
- filter(query: IEntityQuery<StorePriceAddOn>) {
14
- if (!this.verify) {
15
- return query;
16
- }
17
- const { sessionUser } = this;
18
- if (sessionUser.isAdmin) {
19
- return query;
20
- }
21
- return query.where(sessionUser, (p) => (x) => x.price.storeItem.store.storeUsers.some((u) => u.userID === p.userID));
22
- }
23
-
24
- modify(query: IEntityQuery<StorePriceAddOn>) {
25
- return this.filter(query);
26
- }
27
-
28
- delete(query: IEntityQuery<StorePriceAddOn>): IEntityQuery<StorePriceAddOn> {
29
- if (!this.verify) {
30
- return query;
31
- }
32
- const { sessionUser } = this;
33
- if (sessionUser.isAdmin) {
34
- return query;
35
- }
36
- throw new EntityAccessError("Only admin can delete the store.");
37
- }
38
-
39
- includeFilter(query: IEntityQuery<StorePriceAddOn>, type?: any, key?: string) {
40
- return query;
41
- }
42
-
43
- beforeInsert(entity: StorePriceAddOn, entry: ChangeEntry<StorePriceAddOn>) {
44
- this.sessionUser.ensureLoggedIn();
45
- }
46
-
47
- beforeUpdate(entity: StorePriceAddOn, entry: ChangeEntry<StorePriceAddOn>) {
48
- this.sessionUser.ensureLoggedIn();
49
- }
50
-
51
- async afterInsert(entity: StorePriceAddOn, entry: ChangeEntry<StorePriceAddOn>) {
52
- await this.updatePrices(entity);
53
- }
54
-
55
- async afterUpdate(entity: StorePriceAddOn, entry: ChangeEntry<StorePriceAddOn>) {
56
- await this.updatePrices(entity);
57
- }
58
-
59
- async afterDelete(entity: StorePriceAddOn, entry: ChangeEntry<StorePriceAddOn>) {
60
- await this.updatePrices(entity);
61
- }
62
-
63
- private async updatePrices(entity: StorePriceAddOn) {
64
- const db = ServiceProvider.resolve(this, SocialMailContext);
65
- await db.storeItemPrices.where(entity, (p) => (x) => x.priceID === p.priceID)
66
- .update(entity, (p) => (x) => ({
67
- addonsAmount: x.amount * Sql.coll.sum(x.addons
68
- .map((m) => Sql.coll.sum(m.addOnItem
69
- .storeItemPrices
70
- .filter((ap) => ap.currency === x.currency)
71
- .map((ap) => ap.amount))))
72
- }));
73
- }
74
-
75
- }