@social-mail/social-mail-web-server 1.4.890 → 1.4.892

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.890",
3
+ "version": "1.4.892",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "@aws-sdk/client-s3": "^3.609.0",
23
23
  "@azure/storage-blob": "^12.23.0",
24
- "@entity-access/entity-access": "^1.0.349",
24
+ "@entity-access/entity-access": "^1.0.350",
25
25
  "@entity-access/server-pages": "^1.1.222",
26
26
  "@otplib/preset-v11": "^12.0.1",
27
27
  "@social-mail/noto-emoji-svg": "^2.0.42",
@@ -1,9 +1,26 @@
1
1
  import { IEntityQuery } from "@entity-access/entity-access/dist/model/IFilterWithParameter.js";
2
2
  import { StoreTag } from "../entities/Store.js";
3
3
  import AuthenticatedEvents from "./AuthenticatedEvents.js";
4
+ import External from "@entity-access/server-pages/dist/decorators/External.js";
5
+ import Page from "@entity-access/server-pages/dist/Page.js";
6
+ import { ServiceProvider } from "@entity-access/entity-access/dist/di/di.js";
7
+ import SocialMailContext from "../SocialMailContext.js";
4
8
 
5
9
  export default class StoreTagEvents extends AuthenticatedEvents<StoreTag> {
6
10
 
11
+ @External
12
+ storeQuery() {
13
+ const page = ServiceProvider.resolve(this, Page as any) as Page;
14
+ const host = page.request.host;
15
+
16
+ const db = ServiceProvider.resolve(this, SocialMailContext);
17
+ const q = db.storeTags.where({ host }, (p) => (x) => x.store.storeWebsites
18
+ .some((w) => w.website.hosts
19
+ .some((h) => h.host === p.host)));
20
+ return q;
21
+ }
22
+
23
+
7
24
  filter(query: IEntityQuery<StoreTag>): IEntityQuery<StoreTag> {
8
25
  return query;
9
26
  }
@@ -3,7 +3,7 @@ import semver from "semver";
3
3
 
4
4
  export default async function seedUI(config: DBConfig) {
5
5
 
6
- const version = "1.2.363";
6
+ const version = "1.2.365";
7
7
 
8
8
  const existing = await config.getValue(UIPackageConfig, false);
9
9
  if (existing) {
@@ -11,28 +11,39 @@ export default class StoreTagCountService {
11
11
 
12
12
  async updateCounts(entity: StoreItem, diff: number) {
13
13
  const { db } = this;
14
- const { storeItemID } = entity;
15
- const updated = await db.storeTags.where(entity, (p) => (x) => x.storeID === p.storeID)
16
- .where(entity, (p) => (x) => x.tag.storeItemTags.some((sit) => sit.storeItemID === p.storeItemID))
17
- .update({ diff, storeItemID }, (p) => (x) => ({
18
- count: x.count + Sql.cast.asInteger(p.diff) * Sql.coll.sum(x.store.storeItems
19
- .filter((si) => si.storeItemID === p.storeItemID)
20
- .map((si) => Sql.coll.sum(si.storeItemTags
21
- .filter((t) => t.tagID === x.tagID)
22
- .map((t) => 1))))
23
- }));
24
- if (!updated) {
25
- // insert...
26
- await db.storeItemTags.where(entity, (p) => (x) => x.storeItemID === p.storeItemID)
27
- .select({ diff }, (p) => (x) => ({
28
- storeID: x.storeItem.storeID,
29
- tagID: x.tagID,
30
- count: Sql.cast.asInteger(p.diff) * Sql.coll.sum(x.tag.storeItemTags
31
- .filter((sit) => sit.storeItem.storeID === x.storeItem.storeID)
32
- .map((sit) => 1))
33
- }))
34
- .insertInTo(db.storeTags);
14
+ const { storeItemID, storeID } = entity;
15
+
16
+ const items = await db.storeItemTags.where(entity, (p) => (x) => x.storeItemID === p.storeItemID)
17
+ .toArray();
18
+
19
+ for (const { tagID } of items) {
20
+ const ti = { tagID , storeID };
21
+ const count = diff * (await db.storeItemTags.where(ti, (p) => (x) => x.tagID === p.tagID && x.storeItem.storeID === p.storeID)
22
+ .count());
23
+ await db.storeTags.statements.upsert({ tagID, storeID, count}, void 0, { tagID, storeID });
35
24
  }
25
+
26
+ // const updated = await db.storeTags.where(entity, (p) => (x) => x.storeID === p.storeID)
27
+ // .where(entity, (p) => (x) => x.tag.storeItemTags.some((sit) => sit.storeItemID === p.storeItemID))
28
+ // .update({ diff, storeItemID }, (p) => (x) => ({
29
+ // count: x.count + Sql.cast.asInteger(p.diff) * Sql.coll.sum(x.store.storeItems
30
+ // .filter((si) => si.storeItemID === p.storeItemID)
31
+ // .map((si) => Sql.coll.sum(si.storeItemTags
32
+ // .filter((t) => t.tagID === x.tagID)
33
+ // .map((t) => 1))))
34
+ // }));
35
+ // if (!updated) {
36
+ // // insert...
37
+ // await db.storeItemTags.where(entity, (p) => (x) => x.storeItemID === p.storeItemID)
38
+ // .select({ diff }, (p) => (x) => ({
39
+ // storeID: x.storeItem.storeID,
40
+ // tagID: x.tagID,
41
+ // count: Sql.cast.asInteger(p.diff) * Sql.coll.sum(x.tag.storeItemTags
42
+ // .filter((sit) => sit.storeItem.storeID === x.storeItem.storeID)
43
+ // .map((sit) => 1))
44
+ // }))
45
+ // .insertInTo(db.storeTags);
46
+ // }
36
47
  }
37
48
 
38
49
  }