@studyportals/fawkes 8.2.4-12 → 8.2.4-13

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.
@@ -20,10 +20,17 @@ export class CountryAreaCity extends OrganisationsSeoIndexabilityPolicy {
20
20
  .getInstance(this.dependencies.searchApiClient)
21
21
  .getFragments();
22
22
  const paths = [];
23
- for (const city of cityFragments) {
23
+ const filteredFragmentsForCountryAreaCity = cityFragments.filter(city => city.areaId !== null && city.areaId !== undefined);
24
+ console.warn(`Filtered down to ${filteredFragmentsForCountryAreaCity.length} city fragments for CountryAreaCity policy.`);
25
+ console.warn('Filtered city fragments for CountryAreaCity policy:', JSON.stringify(filteredFragmentsForCountryAreaCity));
26
+ for (const city of filteredFragmentsForCountryAreaCity) {
27
+ const areaId = city.areaId?.toString() || '';
28
+ if (areaId === '') {
29
+ continue;
30
+ }
24
31
  const filterKeyValues = new Map([
25
32
  [FilterKey.CITY, [city.id]],
26
- [FilterKey.AREA, [city.areaId]],
33
+ [FilterKey.AREA, [areaId]],
27
34
  [FilterKey.COUNTRY, [city.countryId]]
28
35
  ]);
29
36
  const result = await this.checkRulesForSitemap(filterKeyValues);
@@ -19,7 +19,10 @@ export class CountryCity extends OrganisationsSeoIndexabilityPolicy {
19
19
  .getInstance(this.dependencies.searchApiClient)
20
20
  .getFragments();
21
21
  const paths = [];
22
- for (const city of cityFragments) {
22
+ const filteredFragmentsForCountryCity = cityFragments.filter(city => city.areaId === null || city.areaId === undefined);
23
+ console.warn(`Filtered down to ${filteredFragmentsForCountryCity.length} city fragments for CountryCity policy.`);
24
+ console.warn('Filtered city fragments for CountryCity policy:', JSON.stringify(filteredFragmentsForCountryCity));
25
+ for (const city of filteredFragmentsForCountryCity) {
23
26
  const filterKeyValues = new Map([
24
27
  [FilterKey.CITY, [city.id]],
25
28
  [FilterKey.COUNTRY, [city.countryId]]
@@ -10,4 +10,5 @@ export declare class CityPresenter {
10
10
  static getInstance(searchApiClient: ISearchApiClient): CityPresenter;
11
11
  getFragments(): Promise<ICityFragment[]>;
12
12
  private fetchCities;
13
+ private processCity;
13
14
  }
@@ -28,35 +28,8 @@ export class CityPresenter {
28
28
  console.error('searchApiClient.getCities is not found');
29
29
  throw new Error('searchApiClient.getCities is not found');
30
30
  }
31
- const data = await this.searchApiClient.getCities();
32
- console.warn(`Fetched ${data.length} cities from search API.`);
33
- console.warn('cities', JSON.stringify(data));
34
- const cityFragments = data.map(city => {
35
- const country = countriesExtendedAll.find(item => item.iso?.toLowerCase() === city.countryIsoCode?.toLowerCase());
36
- let cityPath = ``;
37
- const countryPath = countryGetIsoCodePath(country?.iso || '');
38
- if (city.areaId === null || city.areaId === undefined) {
39
- cityPath += `${countryPath}/`;
40
- }
41
- else {
42
- const area = areaGetPath(city.areaId?.toString() || '');
43
- if (area && area !== '') {
44
- cityPath += `${area}/`;
45
- }
46
- else {
47
- cityPath += `${countryPath}/`;
48
- }
49
- }
50
- cityPath += `${city.virtualPath}`;
51
- return {
52
- id: city.id.toString(),
53
- path: cityPath,
54
- areaId: city.areaId?.toString(),
55
- countryId: country ? country.id.toString() : '',
56
- };
57
- });
58
- console.warn(`Processed ${cityFragments.length} city fragments.`);
59
- console.warn('cityFragments', JSON.stringify(cityFragments));
31
+ const cities = await this.searchApiClient.getCities();
32
+ const cityFragments = cities.map(city => this.processCity(city));
60
33
  return cityFragments;
61
34
  }
62
35
  catch (error) {
@@ -64,4 +37,18 @@ export class CityPresenter {
64
37
  throw error;
65
38
  }
66
39
  }
40
+ processCity(city) {
41
+ const country = countriesExtendedAll.find(item => item.iso?.toLowerCase() === city.countryIsoCode?.toLowerCase());
42
+ const countryPath = countryGetIsoCodePath(country?.iso || '');
43
+ const areaPath = city.areaId != null ? areaGetPath(city.areaId.toString()) : '';
44
+ const useAreaPath = areaPath && areaPath.trim() !== '';
45
+ // AreaPath do also includes country, for that reason, we do not need to add countryPath if area exists
46
+ const cityPath = `${useAreaPath ? areaPath : countryPath}/${city.virtualPath}`;
47
+ return {
48
+ id: city.id.toString(),
49
+ path: cityPath,
50
+ areaId: useAreaPath ? city.areaId?.toString() : null,
51
+ countryId: country ? country.id.toString() : '',
52
+ };
53
+ }
67
54
  }
@@ -1,5 +1,5 @@
1
1
  import { IFragment } from './IFragment';
2
2
  export interface ICityFragment extends IFragment {
3
- areaId: string;
3
+ areaId?: string | null;
4
4
  countryId: string;
5
5
  }
@@ -0,0 +1,7 @@
1
+ export interface ICity {
2
+ id: number;
3
+ name: string;
4
+ virtualPath: string;
5
+ areaId: number | null;
6
+ countryIsoCode: string;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studyportals/fawkes",
3
- "version": "8.2.4-12",
3
+ "version": "8.2.4-13",
4
4
  "description": "A package to centralize SEO related logic for SBLP and Sitemap Generator.",
5
5
  "files": [
6
6
  "./dist"