@websolutespa/bom-mixer-models 1.5.2 → 1.5.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @websolutespa/bom-mixer-models
2
2
 
3
+ ## 1.5.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified: RouteService
8
+ - Updated dependencies
9
+ - @websolutespa/bom-mixer-store@1.4.1
10
+ - @websolutespa/bom-core@0.6.3
11
+
3
12
  ## 1.5.2
4
13
 
5
14
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -303,8 +303,8 @@ declare function getRoutesForTemplates(templates: string[], market?: string, loc
303
303
  declare function getStaticPathsForSchema(schema: string): Promise<StaticPath[]>;
304
304
  declare function getBreadcrumbFromSegments(segments: ICategory[], market: string, locale: string): Promise<IRouteLink[]>;
305
305
  declare function getRouteLinkTree(market: string, locale: string): Promise<IRouteLink | undefined>;
306
+ declare function categoryToRouteLink(routes: IRoute[], categories: ICategory[], category: ICategory, locale: string): IRouteLink | undefined;
306
307
  declare function newRouteLink(category: ICategory, route: IRoute | undefined, locale: string): IRouteLink;
307
- declare function categoryToRouteLink(routes: IRoute[], categories: ICategory[], category: ICategory, locale: string): IRouteLink;
308
308
  declare function resolveRoute(route: IRoute & {
309
309
  splat?: string;
310
310
  }): string;
package/dist/index.js CHANGED
@@ -265,6 +265,22 @@ async function getRouteLinkTree(market, locale) {
265
265
  }
266
266
  return void 0;
267
267
  }
268
+ function categoryToRouteLink(routes, categories, category, locale) {
269
+ const route = routes.find(
270
+ (r) => r.category === category.id && r.isDefault
271
+ );
272
+ if (!route) {
273
+ return void 0;
274
+ }
275
+ const rootCategory = (0, import_bom_core2.getRootCategory)(categories);
276
+ const childCategories = categories.filter((x) => {
277
+ const parentId = x.category && typeof x.category === "object" ? x.category["id"] : x.category;
278
+ return rootCategory && category.id === rootCategory.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
279
+ });
280
+ const routeLink = newRouteLink(category, route, locale);
281
+ routeLink.items = childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale)).filter((x) => x !== void 0);
282
+ return routeLink;
283
+ }
268
284
  function newRouteLink(category, route, locale) {
269
285
  const href = route && route.id ? route.id.toString() : "/";
270
286
  const id = route?.page || category.id;
@@ -282,19 +298,6 @@ function newRouteLink(category, route, locale) {
282
298
  };
283
299
  return routeLink;
284
300
  }
285
- function categoryToRouteLink(routes, categories, category, locale) {
286
- const route = routes.find(
287
- (r) => r.category === category.id
288
- );
289
- const rootCategory = (0, import_bom_core2.getRootCategory)(categories);
290
- const childCategories = categories.filter((x) => {
291
- const parentId = x.category && typeof x.category === "object" ? x.category["id"] : x.category;
292
- return rootCategory && category.id === rootCategory.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
293
- });
294
- const routeLink = newRouteLink(category, route, locale);
295
- routeLink.items = childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale));
296
- return routeLink;
297
- }
298
301
  function resolveRoute(route) {
299
302
  const routepath = route.template ? route.template : route.schema;
300
303
  const resolvedPathname = `/${route.market}/${route.locale}/${routepath}/${route.page}${route.splat || ""}`;
package/dist/index.mjs CHANGED
@@ -176,6 +176,22 @@ async function getRouteLinkTree(market, locale) {
176
176
  }
177
177
  return void 0;
178
178
  }
179
+ function categoryToRouteLink(routes, categories, category, locale) {
180
+ const route = routes.find(
181
+ (r) => r.category === category.id && r.isDefault
182
+ );
183
+ if (!route) {
184
+ return void 0;
185
+ }
186
+ const rootCategory = getRootCategory(categories);
187
+ const childCategories = categories.filter((x) => {
188
+ const parentId = x.category && typeof x.category === "object" ? x.category["id"] : x.category;
189
+ return rootCategory && category.id === rootCategory.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
190
+ });
191
+ const routeLink = newRouteLink(category, route, locale);
192
+ routeLink.items = childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale)).filter((x) => x !== void 0);
193
+ return routeLink;
194
+ }
179
195
  function newRouteLink(category, route, locale) {
180
196
  const href = route && route.id ? route.id.toString() : "/";
181
197
  const id = route?.page || category.id;
@@ -193,19 +209,6 @@ function newRouteLink(category, route, locale) {
193
209
  };
194
210
  return routeLink;
195
211
  }
196
- function categoryToRouteLink(routes, categories, category, locale) {
197
- const route = routes.find(
198
- (r) => r.category === category.id
199
- );
200
- const rootCategory = getRootCategory(categories);
201
- const childCategories = categories.filter((x) => {
202
- const parentId = x.category && typeof x.category === "object" ? x.category["id"] : x.category;
203
- return rootCategory && category.id === rootCategory.id ? x.id !== rootCategory.id && (parentId === category.id || !parentId) : parentId === category.id;
204
- });
205
- const routeLink = newRouteLink(category, route, locale);
206
- routeLink.items = childCategories.map((x) => categoryToRouteLink(routes, categories, x, locale));
207
- return routeLink;
208
- }
209
212
  function resolveRoute(route) {
210
213
  const routepath = route.template ? route.template : route.schema;
211
214
  const resolvedPathname = `/${route.market}/${route.locale}/${routepath}/${route.page}${route.splat || ""}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-models",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Mixer Models module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -109,7 +109,7 @@ export async function getBreadcrumbFromSegments(segments: ICategory[], market: s
109
109
 
110
110
  export async function getRouteLinkTree(market: string, locale: string): Promise<IRouteLink | undefined> {
111
111
  const store = await getStore<IModelStore>();
112
- // console.log('getRouteLinkTree.store');
112
+ // console.log('getRouteLinkTree.store', store);
113
113
  const routes = await store.route.findMany({
114
114
  where: {
115
115
  market: {
@@ -120,11 +120,11 @@ export async function getRouteLinkTree(market: string, locale: string): Promise<
120
120
  },
121
121
  }, market, locale,
122
122
  });
123
- // console.log('getRouteLinkTree.routes');
123
+ // console.log('getRouteLinkTree.routes', routes);
124
124
  const categories = await store.category.findMany();
125
- // console.log('getRouteLinkTree.categories');
125
+ // console.log('getRouteLinkTree.categories', categories);
126
126
  const rootCategory = getRootCategory(categories);
127
- // console.log('getRouteLinkTree.rootCategory');
127
+ // console.log('getRouteLinkTree.rootCategory', rootCategory);
128
128
  if (rootCategory) {
129
129
  const root = categoryToRouteLink(routes, categories, rootCategory, locale);
130
130
  // console.log('getRouteLinkTree', root);
@@ -133,6 +133,33 @@ export async function getRouteLinkTree(market: string, locale: string): Promise<
133
133
  return undefined;
134
134
  }
135
135
 
136
+ // !!! todo refactor: only category with linked route.isDefault on tree.
137
+ export function categoryToRouteLink(routes: IRoute[], categories: ICategory[], category: ICategory, locale: string): IRouteLink | undefined {
138
+ const route = routes.find(r =>
139
+ r.category === category.id &&
140
+ r.isDefault
141
+ );
142
+ if (!route) {
143
+ return undefined;
144
+ }
145
+ const rootCategory = getRootCategory(categories);
146
+ const childCategories = categories.filter(x => {
147
+ const parentId = x.category && typeof x.category === 'object' ? x.category['id'] : x.category;
148
+ return rootCategory && category.id === rootCategory.id ?
149
+ (x.id !== rootCategory.id && (parentId === category.id || !parentId)) :
150
+ parentId === category.id;
151
+ });
152
+ // console.log('childCategories', category.id, childCategories);
153
+ const routeLink = newRouteLink(category, route, locale);
154
+ // const title = localize(category.title || 'untitled', locale);
155
+ // const href = (route && route.id) ? route.id.toString() : '/';
156
+ // console.log('categoryToRouteLink', href, category.id, route);
157
+ routeLink.items = childCategories
158
+ .map(x => categoryToRouteLink(routes, categories, x, locale))
159
+ .filter(x => x !== undefined) as IRouteLink[];
160
+ return routeLink;
161
+ }
162
+
136
163
  export function newRouteLink(category: ICategory, route: IRoute | undefined, locale: string): IRouteLink {
137
164
  const href = (route && route.id) ? route.id.toString() : '/';
138
165
  const id = route?.page || category.id;
@@ -151,26 +178,6 @@ export function newRouteLink(category: ICategory, route: IRoute | undefined, loc
151
178
  return routeLink;
152
179
  }
153
180
 
154
- export function categoryToRouteLink(routes: IRoute[], categories: ICategory[], category: ICategory, locale: string): IRouteLink {
155
- const route = routes.find(r =>
156
- r.category === category.id
157
- );
158
- const rootCategory = getRootCategory(categories);
159
- const childCategories = categories.filter(x => {
160
- const parentId = x.category && typeof x.category === 'object' ? x.category['id'] : x.category;
161
- return rootCategory && category.id === rootCategory.id ?
162
- (x.id !== rootCategory.id && (parentId === category.id || !parentId)) :
163
- parentId === category.id;
164
- });
165
- // console.log('childCategories', category.id, childCategories);
166
- const routeLink = newRouteLink(category, route, locale);
167
- // const title = localize(category.title || 'untitled', locale);
168
- // const href = (route && route.id) ? route.id.toString() : '/';
169
- // console.log('categoryToRouteLink', href, category.id, route);
170
- routeLink.items = childCategories.map(x => categoryToRouteLink(routes, categories, x, locale));
171
- return routeLink;
172
- }
173
-
174
181
  export function resolveRoute(route: IRoute & { splat?: string }) {
175
182
  // console.log('resolveRoute', route);
176
183
  const routepath: string = route.template ? route.template : route.schema;