pim-import 5.0.1 → 5.0.2
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/dist/algolia/clean.js +0 -1
- package/dist/algolia/config.js +0 -1
- package/dist/algolia/downloads.js +0 -1
- package/dist/algolia/families.js +0 -1
- package/dist/algolia/inspirations.js +0 -1
- package/dist/algolia/models.js +0 -1
- package/dist/algolia/news.js +0 -1
- package/dist/algolia/pressRelease.js +0 -1
- package/dist/algolia/pressReview.js +0 -1
- package/dist/algolia/products.js +0 -1
- package/dist/algolia/projects.js +0 -1
- package/dist/algolia/stories.js +0 -1
- package/dist/algolia/subFamilies.js +0 -1
- package/dist/algolia/subModels.js +0 -1
- package/dist/browser.js +0 -1
- package/dist/downloads/classes/manageEntry.js +0 -1
- package/dist/downloads/import.js +0 -1
- package/dist/index.js +0 -1
- package/dist/libs/contentful-cda.js +0 -1
- package/dist/libs/contentful.js +0 -1
- package/dist/libs/imgix.js +0 -1
- package/dist/libs/logs.js +0 -1
- package/dist/libs/netlify.js +0 -1
- package/dist/libs/notifications.js +0 -1
- package/dist/libs/pdf.js +0 -1
- package/dist/libs/s3.js +0 -1
- package/dist/libs/sentry.js +0 -1
- package/dist/pim/config.js +0 -1
- package/dist/pim/endpoints.js +0 -1
- package/dist/pim/methods/bulkPublish.js +0 -1
- package/dist/pim/methods/catalogs.js +0 -1
- package/dist/pim/methods/checkTopicDraftAndPagePublished.js +0 -1
- package/dist/pim/methods/designers.js +0 -1
- package/dist/pim/methods/dictionary.js +0 -1
- package/dist/pim/methods/families.js +0 -1
- package/dist/pim/methods/latestProducts.js +0 -1
- package/dist/pim/methods/migrateEntryFields.js +0 -1
- package/dist/pim/methods/models.js +0 -1
- package/dist/pim/methods/pages/catalogs.js +0 -1
- package/dist/pim/methods/pages/families.js +0 -1
- package/dist/pim/methods/pages/subfamilies.js +0 -1
- package/dist/pim/methods/products.js +0 -1
- package/dist/pim/methods/subfamilies.js +0 -1
- package/dist/pim/methods/submodels.js +0 -1
- package/dist/pim/request.js +0 -1
- package/dist/resources/AllProducts.js +0 -1
- package/dist/resources/Audit.js +0 -1
- package/dist/resources/CatalogDetails.js +0 -1
- package/dist/resources/CollectionModels.js +0 -1
- package/dist/resources/CollectionSubFamilies.js +0 -1
- package/dist/resources/CollectionSubModels.js +0 -1
- package/dist/resources/DProductSubLine.js +0 -1
- package/dist/resources/FamilyDetails.js +0 -1
- package/dist/resources/ProductDetails.js +0 -1
- package/dist/resources/ProductRelation.js +0 -1
- package/dist/resources/cfFields.js +0 -1
- package/dist/types.js +0 -1
- package/dist/utils.js +0 -1
- package/package.json +7 -2
- package/.env.example +0 -45
- package/.nvmrc +0 -1
- package/.vscode/settings.json +0 -21
- package/dist/algolia/clean.js.map +0 -1
- package/dist/algolia/config.js.map +0 -1
- package/dist/algolia/downloads.js.map +0 -1
- package/dist/algolia/families.js.map +0 -1
- package/dist/algolia/inspirations.js.map +0 -1
- package/dist/algolia/models.js.map +0 -1
- package/dist/algolia/news.js.map +0 -1
- package/dist/algolia/pressRelease.js.map +0 -1
- package/dist/algolia/pressReview.js.map +0 -1
- package/dist/algolia/products.js.map +0 -1
- package/dist/algolia/projects.js.map +0 -1
- package/dist/algolia/stories.js.map +0 -1
- package/dist/algolia/subFamilies.js.map +0 -1
- package/dist/algolia/subModels.js.map +0 -1
- package/dist/browser.js.map +0 -1
- package/dist/downloads/classes/manageEntry.js.map +0 -1
- package/dist/downloads/import.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/libs/contentful-cda.js.map +0 -1
- package/dist/libs/contentful.js.map +0 -1
- package/dist/libs/imgix.js.map +0 -1
- package/dist/libs/logs.js.map +0 -1
- package/dist/libs/netlify.js.map +0 -1
- package/dist/libs/notifications.js.map +0 -1
- package/dist/libs/pdf.js.map +0 -1
- package/dist/libs/s3.js.map +0 -1
- package/dist/libs/sentry.js.map +0 -1
- package/dist/pim/config.js.map +0 -1
- package/dist/pim/endpoints.js.map +0 -1
- package/dist/pim/methods/bulkPublish.js.map +0 -1
- package/dist/pim/methods/catalogs.js.map +0 -1
- package/dist/pim/methods/checkTopicDraftAndPagePublished.js.map +0 -1
- package/dist/pim/methods/designers.js.map +0 -1
- package/dist/pim/methods/dictionary.js.map +0 -1
- package/dist/pim/methods/families.js.map +0 -1
- package/dist/pim/methods/latestProducts.js.map +0 -1
- package/dist/pim/methods/migrateEntryFields.js.map +0 -1
- package/dist/pim/methods/models.js.map +0 -1
- package/dist/pim/methods/pages/catalogs.js.map +0 -1
- package/dist/pim/methods/pages/families.js.map +0 -1
- package/dist/pim/methods/pages/subfamilies.js.map +0 -1
- package/dist/pim/methods/products.js.map +0 -1
- package/dist/pim/methods/subfamilies.js.map +0 -1
- package/dist/pim/methods/submodels.js.map +0 -1
- package/dist/pim/request.js.map +0 -1
- package/dist/resources/AllProducts.js.map +0 -1
- package/dist/resources/Audit.js.map +0 -1
- package/dist/resources/CatalogDetails.js.map +0 -1
- package/dist/resources/CollectionModels.js.map +0 -1
- package/dist/resources/CollectionSubFamilies.js.map +0 -1
- package/dist/resources/CollectionSubModels.js.map +0 -1
- package/dist/resources/DProductSubLine.js.map +0 -1
- package/dist/resources/FamilyDetails.js.map +0 -1
- package/dist/resources/ProductDetails.js.map +0 -1
- package/dist/resources/ProductRelation.js.map +0 -1
- package/dist/resources/cfFields.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils.js.map +0 -1
- package/docs/import-data-from-the-dictionary.md +0 -83
- package/docs/import-products.md +0 -61
- package/docs/import-taxonomies-from-the-catalog.md +0 -60
- package/docs/settings.md +0 -47
- package/jest.config.js +0 -16
- package/local-fn/reindex.js +0 -182
- package/src/algolia/clean.ts +0 -164
- package/src/algolia/config.ts +0 -390
- package/src/algolia/downloads.ts +0 -346
- package/src/algolia/families.ts +0 -652
- package/src/algolia/inspirations.ts +0 -315
- package/src/algolia/models.ts +0 -589
- package/src/algolia/news.ts +0 -258
- package/src/algolia/pressRelease.ts +0 -255
- package/src/algolia/pressReview.ts +0 -247
- package/src/algolia/products.ts +0 -731
- package/src/algolia/projects.ts +0 -339
- package/src/algolia/stories.ts +0 -347
- package/src/algolia/subFamilies.ts +0 -709
- package/src/algolia/subModels.ts +0 -359
- package/src/browser.ts +0 -122
- package/src/downloads/classes/manageEntry.ts +0 -99
- package/src/downloads/csv/legal.csv +0 -5
- package/src/downloads/csv/products.csv +0 -373
- package/src/downloads/import.ts +0 -381
- package/src/index.ts +0 -140
- package/src/libs/contentful-cda.ts +0 -543
- package/src/libs/contentful.ts +0 -1453
- package/src/libs/imgix.ts +0 -297
- package/src/libs/logs.ts +0 -121
- package/src/libs/netlify.ts +0 -37
- package/src/libs/notifications.ts +0 -104
- package/src/libs/pdf.ts +0 -107
- package/src/libs/s3.ts +0 -305
- package/src/libs/sentry.ts +0 -33
- package/src/pim/config.ts +0 -84
- package/src/pim/data/productFields.json +0 -1178
- package/src/pim/endpoints.ts +0 -364
- package/src/pim/methods/bulkPublish.ts +0 -266
- package/src/pim/methods/catalogs.ts +0 -586
- package/src/pim/methods/checkTopicDraftAndPagePublished.ts +0 -70
- package/src/pim/methods/designers.ts +0 -128
- package/src/pim/methods/dictionary.ts +0 -611
- package/src/pim/methods/families.ts +0 -345
- package/src/pim/methods/latestProducts.ts +0 -70
- package/src/pim/methods/migrateEntryFields.ts +0 -99
- package/src/pim/methods/models.ts +0 -349
- package/src/pim/methods/pages/catalogs.ts +0 -28
- package/src/pim/methods/pages/families.ts +0 -50
- package/src/pim/methods/pages/subfamilies.ts +0 -98
- package/src/pim/methods/products.ts +0 -3297
- package/src/pim/methods/subfamilies.ts +0 -706
- package/src/pim/methods/submodels.ts +0 -262
- package/src/pim/request.ts +0 -61
- package/src/resources/AllProducts.ts +0 -41
- package/src/resources/Audit.ts +0 -24
- package/src/resources/CatalogDetails.ts +0 -51
- package/src/resources/CollectionModels.ts +0 -42
- package/src/resources/CollectionSubFamilies.ts +0 -45
- package/src/resources/CollectionSubModels.ts +0 -36
- package/src/resources/DProductSubLine.ts +0 -34
- package/src/resources/FamilyDetails.ts +0 -31
- package/src/resources/ProductDetails.ts +0 -352
- package/src/resources/ProductRelation.ts +0 -24
- package/src/resources/cfFields.ts +0 -8
- package/src/types.ts +0 -268
- package/src/utils.ts +0 -553
- package/tsconfig.json +0 -93
- package/tslint.json +0 -22
- package/types/libs/puppeteer.d.ts +0 -17
- package/types/pim/methods/checkIp.d.ts +0 -1
- /package/{types → dist}/algolia/clean.d.ts +0 -0
- /package/{types → dist}/algolia/config.d.ts +0 -0
- /package/{types → dist}/algolia/downloads.d.ts +0 -0
- /package/{types → dist}/algolia/families.d.ts +0 -0
- /package/{types → dist}/algolia/inspirations.d.ts +0 -0
- /package/{types → dist}/algolia/models.d.ts +0 -0
- /package/{types → dist}/algolia/news.d.ts +0 -0
- /package/{types → dist}/algolia/pressRelease.d.ts +0 -0
- /package/{types → dist}/algolia/pressReview.d.ts +0 -0
- /package/{types → dist}/algolia/products.d.ts +0 -0
- /package/{types → dist}/algolia/projects.d.ts +0 -0
- /package/{types → dist}/algolia/stories.d.ts +0 -0
- /package/{types → dist}/algolia/subFamilies.d.ts +0 -0
- /package/{types → dist}/algolia/subModels.d.ts +0 -0
- /package/{types → dist}/browser.d.ts +0 -0
- /package/{types → dist}/downloads/classes/manageEntry.d.ts +0 -0
- /package/{types → dist}/downloads/import.d.ts +0 -0
- /package/{types → dist}/index.d.ts +0 -0
- /package/{types → dist}/libs/contentful-cda.d.ts +0 -0
- /package/{types → dist}/libs/contentful.d.ts +0 -0
- /package/{types → dist}/libs/imgix.d.ts +0 -0
- /package/{types → dist}/libs/logs.d.ts +0 -0
- /package/{types → dist}/libs/netlify.d.ts +0 -0
- /package/{types → dist}/libs/notifications.d.ts +0 -0
- /package/{types → dist}/libs/pdf.d.ts +0 -0
- /package/{types → dist}/libs/s3.d.ts +0 -0
- /package/{types → dist}/libs/sentry.d.ts +0 -0
- /package/{types → dist}/pim/config.d.ts +0 -0
- /package/{types → dist}/pim/endpoints.d.ts +0 -0
- /package/{types → dist}/pim/methods/bulkPublish.d.ts +0 -0
- /package/{types → dist}/pim/methods/catalogs.d.ts +0 -0
- /package/{types → dist}/pim/methods/checkTopicDraftAndPagePublished.d.ts +0 -0
- /package/{types → dist}/pim/methods/designers.d.ts +0 -0
- /package/{types → dist}/pim/methods/dictionary.d.ts +0 -0
- /package/{types → dist}/pim/methods/families.d.ts +0 -0
- /package/{types → dist}/pim/methods/latestProducts.d.ts +0 -0
- /package/{types → dist}/pim/methods/migrateEntryFields.d.ts +0 -0
- /package/{types → dist}/pim/methods/models.d.ts +0 -0
- /package/{types → dist}/pim/methods/pages/catalogs.d.ts +0 -0
- /package/{types → dist}/pim/methods/pages/families.d.ts +0 -0
- /package/{types → dist}/pim/methods/pages/subfamilies.d.ts +0 -0
- /package/{types → dist}/pim/methods/products.d.ts +0 -0
- /package/{types → dist}/pim/methods/subfamilies.d.ts +0 -0
- /package/{types → dist}/pim/methods/submodels.d.ts +0 -0
- /package/{types → dist}/pim/request.d.ts +0 -0
- /package/{types → dist}/resources/AllProducts.d.ts +0 -0
- /package/{types → dist}/resources/Audit.d.ts +0 -0
- /package/{types → dist}/resources/CatalogDetails.d.ts +0 -0
- /package/{types → dist}/resources/CollectionModels.d.ts +0 -0
- /package/{types → dist}/resources/CollectionSubFamilies.d.ts +0 -0
- /package/{types → dist}/resources/CollectionSubModels.d.ts +0 -0
- /package/{types → dist}/resources/DProductSubLine.d.ts +0 -0
- /package/{types → dist}/resources/FamilyDetails.d.ts +0 -0
- /package/{types → dist}/resources/ProductDetails.d.ts +0 -0
- /package/{types → dist}/resources/ProductRelation.d.ts +0 -0
- /package/{types → dist}/resources/cfFields.d.ts +0 -0
- /package/{types → dist}/types.d.ts +0 -0
- /package/{types → dist}/utils.d.ts +0 -0
package/src/algolia/products.ts
DELETED
|
@@ -1,731 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Product index
|
|
3
|
-
*/
|
|
4
|
-
import {
|
|
5
|
-
getClient,
|
|
6
|
-
getEnvironmentDefaultLocaleCode,
|
|
7
|
-
getEntryByID,
|
|
8
|
-
getTopicDetails,
|
|
9
|
-
} from "../libs/contentful-cda";
|
|
10
|
-
import {
|
|
11
|
-
CfLocalizedEntryField,
|
|
12
|
-
TopicDetailsResponse,
|
|
13
|
-
AlgoliaPaginateRecords,
|
|
14
|
-
WrapperImageFields,
|
|
15
|
-
AlgoliaObjectFilter,
|
|
16
|
-
} from "../types";
|
|
17
|
-
import type { Entry } from "contentful-management/dist/typings/entities/entry";
|
|
18
|
-
import { log, serverUtils } from "../libs/logs";
|
|
19
|
-
import { getIndex, AvailableIndicesKey, removeIndexObject } from "./config";
|
|
20
|
-
import {
|
|
21
|
-
getLocalISOTime,
|
|
22
|
-
secondBetweenTwoDate,
|
|
23
|
-
getAllTranslations,
|
|
24
|
-
addProductFieldValueCodesByPimDetails,
|
|
25
|
-
getCertificationFilters,
|
|
26
|
-
} from "../utils";
|
|
27
|
-
import { getWrapperImgixFields } from "../libs/imgix";
|
|
28
|
-
import axios from "@atoms-studio/axios";
|
|
29
|
-
|
|
30
|
-
export type AlgoliaProductRecord = {
|
|
31
|
-
objectID: string;
|
|
32
|
-
name?: string;
|
|
33
|
-
names?: CfLocalizedEntryField;
|
|
34
|
-
code?: string;
|
|
35
|
-
slugs?: {};
|
|
36
|
-
isProtected?: boolean;
|
|
37
|
-
description?: {};
|
|
38
|
-
excerpt?: {};
|
|
39
|
-
autoDescription?: string;
|
|
40
|
-
thumbnailImgix?: WrapperImageFields | {};
|
|
41
|
-
catalogs?: TopicDetailsResponse[];
|
|
42
|
-
categoriesArchitectural?: TopicDetailsResponse[];
|
|
43
|
-
categoriesOutdoor?: TopicDetailsResponse[];
|
|
44
|
-
categoriesDecorative?: TopicDetailsResponse[];
|
|
45
|
-
categories?: TopicDetailsResponse[];
|
|
46
|
-
families?: TopicDetailsResponse[];
|
|
47
|
-
subFamiliesArchitectural?: TopicDetailsResponse[];
|
|
48
|
-
subFamiliesOutdoor?: TopicDetailsResponse[];
|
|
49
|
-
subFamiliesDecorative?: TopicDetailsResponse[];
|
|
50
|
-
subFamilies?: TopicDetailsResponse[];
|
|
51
|
-
modelsArchitectural?: TopicDetailsResponse[];
|
|
52
|
-
modelsOutdoor?: TopicDetailsResponse[];
|
|
53
|
-
modelsDecorative?: TopicDetailsResponse[];
|
|
54
|
-
models?: TopicDetailsResponse[];
|
|
55
|
-
subModelsArchitectural?: TopicDetailsResponse[];
|
|
56
|
-
subModelsOutdoor?: TopicDetailsResponse[];
|
|
57
|
-
subModelsDecorative?: TopicDetailsResponse[];
|
|
58
|
-
// subModels?: TopicDetailsResponse[];
|
|
59
|
-
productLine?: TopicDetailsResponse;
|
|
60
|
-
productSubLine?: TopicDetailsResponse;
|
|
61
|
-
designers?: TopicDetailsResponse[];
|
|
62
|
-
designYear?: string;
|
|
63
|
-
productFields?: any;
|
|
64
|
-
destinations?: string[];
|
|
65
|
-
techSpec?: CfLocalizedEntryField;
|
|
66
|
-
lastSyncDate?: string;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const indexKey: AvailableIndicesKey = "products";
|
|
70
|
-
const topicProductSelect =
|
|
71
|
-
"sys,fields.name,fields.code,fields.catalogs,fields.categoriesArchitectural,fields.categoriesOutdoor,fields.categoriesDecorative,fields.families,fields.subFamiliesArchitectural,fields.subFamiliesOutdoor,fields.subFamiliesDecorative,fields.modelsArchitectural,fields.modelsOutdoor,fields.modelsDecorative,fields.subModelsArchitectural,fields.subModelsOutdoor,fields.subModelsDecorative,fields.productLine,fields.productSubLine,fields.productFields,fields.thumbnailImgix,fields.autoDescription,fields.designers,fields.destinations,fields.techSpec";
|
|
72
|
-
|
|
73
|
-
export const triggerPDFGenerator = async (
|
|
74
|
-
topicProductId: string,
|
|
75
|
-
multipleDestinations: boolean = false
|
|
76
|
-
) => {
|
|
77
|
-
if (
|
|
78
|
-
process.env.FPI_TRIGGER_GEN_PDF_TASK_ID &&
|
|
79
|
-
process.env.FPI_TRIGGER_SECRET_KEY
|
|
80
|
-
) {
|
|
81
|
-
const topicProduct = await getEntryByID(
|
|
82
|
-
topicProductId,
|
|
83
|
-
"topicProduct",
|
|
84
|
-
"fields.destinations"
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const defaultEnvironmentLocaleCode =
|
|
88
|
-
await getEnvironmentDefaultLocaleCode();
|
|
89
|
-
|
|
90
|
-
const defaultData = {
|
|
91
|
-
locale: defaultEnvironmentLocaleCode,
|
|
92
|
-
country: "global",
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
let destinationsData = [];
|
|
96
|
-
if (multipleDestinations) {
|
|
97
|
-
destinationsData = topicProduct.fields.destinations[
|
|
98
|
-
defaultEnvironmentLocaleCode
|
|
99
|
-
]
|
|
100
|
-
.filter((destination: string) =>
|
|
101
|
-
["PROFESSIONAL_GLOBAL", "PROFESSIONAL_US"].includes(destination)
|
|
102
|
-
)
|
|
103
|
-
.map((destination: string) => {
|
|
104
|
-
switch (destination) {
|
|
105
|
-
case "PROFESSIONAL_US":
|
|
106
|
-
return {
|
|
107
|
-
locale: "en-US",
|
|
108
|
-
country: "us",
|
|
109
|
-
};
|
|
110
|
-
default:
|
|
111
|
-
return defaultData;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (!destinationsData.length) {
|
|
117
|
-
destinationsData = [defaultData];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// TODO: Rimuovere dopo il rilascio del country usa
|
|
121
|
-
// if (
|
|
122
|
-
// !topicProduct.fields.destinations[defaultEnvironmentLocaleCode].find(
|
|
123
|
-
// (destination: string) => ["PROFESSIONAL_GLOBAL"].includes(destination)
|
|
124
|
-
// )
|
|
125
|
-
// ) {
|
|
126
|
-
// destinationsData = [];
|
|
127
|
-
// }
|
|
128
|
-
|
|
129
|
-
// if (!destinationsData.length) {
|
|
130
|
-
// log(
|
|
131
|
-
// `No valid destination found for ${topicProductId} topicProductId`,
|
|
132
|
-
// "WARN"
|
|
133
|
-
// );
|
|
134
|
-
// }
|
|
135
|
-
|
|
136
|
-
for (const destinationData of destinationsData) {
|
|
137
|
-
const url = `https://api.trigger.dev/api/v1/tasks/${process.env.FPI_TRIGGER_GEN_PDF_TASK_ID}/trigger`;
|
|
138
|
-
const data = {
|
|
139
|
-
topicProductId,
|
|
140
|
-
...destinationData,
|
|
141
|
-
};
|
|
142
|
-
console.log(data);
|
|
143
|
-
await axios({
|
|
144
|
-
url,
|
|
145
|
-
data: {
|
|
146
|
-
payload: data,
|
|
147
|
-
},
|
|
148
|
-
method: "POST",
|
|
149
|
-
headers: {
|
|
150
|
-
Authorization: `Bearer ${process.env.FPI_TRIGGER_SECRET_KEY}`,
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
log(
|
|
155
|
-
`triggerPDFGenerator - topicProductId: ${topicProductId} locale: ${destinationData.locale} country: ${destinationData.country}`
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
} else {
|
|
159
|
-
log(
|
|
160
|
-
`FPI_TRIGGER_GEN_PDF_TASK_ID or FPI_TRIGGER_SECRET_KEY env vars not found.`,
|
|
161
|
-
"ERROR"
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const isObjectToDelete = (
|
|
167
|
-
object: any,
|
|
168
|
-
defaultEnvironmentLocaleCode: string
|
|
169
|
-
) => {
|
|
170
|
-
return !object?.code || !object?.slugs?.[defaultEnvironmentLocaleCode];
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const getObject = async (
|
|
174
|
-
topicProduct: Entry
|
|
175
|
-
): Promise<AlgoliaProductRecord> => {
|
|
176
|
-
const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
177
|
-
log(`Sync the ${topicProduct.sys.id} topicProduct...`);
|
|
178
|
-
let topicProductWithFields: Entry = topicProduct;
|
|
179
|
-
|
|
180
|
-
if (!topicProductWithFields?.fields) {
|
|
181
|
-
log(`Get the ${topicProduct.sys.id} topicProduct details...`);
|
|
182
|
-
topicProductWithFields = await getEntryByID(
|
|
183
|
-
topicProduct.sys.id,
|
|
184
|
-
"topicProduct",
|
|
185
|
-
topicProductSelect
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (!topicProductWithFields) {
|
|
190
|
-
log(`The topicProduct ${topicProduct.sys.id} not found`, "WARN");
|
|
191
|
-
|
|
192
|
-
const recordFail: AlgoliaProductRecord = {
|
|
193
|
-
objectID: topicProduct?.sys?.id,
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
return recordFail; // return objectID to delete the record if it exists
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
log(`Get page details...`);
|
|
200
|
-
const productPage: Entry = await getEntryByID(
|
|
201
|
-
`${topicProduct.sys.id}_PAGE`,
|
|
202
|
-
"page",
|
|
203
|
-
"sys,fields.slug,fields.protected"
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
const slugs = await getAllTranslations(productPage?.fields?.slug || {});
|
|
207
|
-
const isProtected =
|
|
208
|
-
!!productPage?.fields?.protected?.[defaultEnvironmentLocaleCode];
|
|
209
|
-
|
|
210
|
-
log(`Get catalogs details...`);
|
|
211
|
-
const catalogs = await getTopicDetails(
|
|
212
|
-
topicProductWithFields,
|
|
213
|
-
"catalogs",
|
|
214
|
-
"topicCatalog"
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
log(`Get categoriesArchitectural details...`);
|
|
218
|
-
const categoriesArchitectural = await getTopicDetails(
|
|
219
|
-
topicProductWithFields,
|
|
220
|
-
"categoriesArchitectural",
|
|
221
|
-
"topicCategory"
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
log(`Get categoriesOutdoor details...`);
|
|
225
|
-
const categoriesOutdoor = await getTopicDetails(
|
|
226
|
-
topicProductWithFields,
|
|
227
|
-
"categoriesOutdoor",
|
|
228
|
-
"topicCategory"
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
log(`Get categoriesDecorative details...`);
|
|
232
|
-
const categoriesDecorative = await getTopicDetails(
|
|
233
|
-
topicProductWithFields,
|
|
234
|
-
"categoriesDecorative",
|
|
235
|
-
"topicCategory"
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
const categories = [
|
|
239
|
-
...categoriesArchitectural,
|
|
240
|
-
...categoriesOutdoor,
|
|
241
|
-
...categoriesDecorative,
|
|
242
|
-
];
|
|
243
|
-
|
|
244
|
-
log(`Get families details...`);
|
|
245
|
-
const families = await getTopicDetails(
|
|
246
|
-
topicProductWithFields,
|
|
247
|
-
"families",
|
|
248
|
-
"topicFamily"
|
|
249
|
-
);
|
|
250
|
-
|
|
251
|
-
log(`Get subFamiliesArchitectural details...`);
|
|
252
|
-
const subFamiliesArchitectural = await getTopicDetails(
|
|
253
|
-
topicProductWithFields,
|
|
254
|
-
"subFamiliesArchitectural",
|
|
255
|
-
"topicSubFamily",
|
|
256
|
-
false,
|
|
257
|
-
true,
|
|
258
|
-
true
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
log(`Get subFamiliesOutdoor details...`);
|
|
262
|
-
const subFamiliesOutdoor = await getTopicDetails(
|
|
263
|
-
topicProductWithFields,
|
|
264
|
-
"subFamiliesOutdoor",
|
|
265
|
-
"topicSubFamily",
|
|
266
|
-
false,
|
|
267
|
-
true,
|
|
268
|
-
true
|
|
269
|
-
);
|
|
270
|
-
|
|
271
|
-
log(`Get subFamiliesDecorative details...`);
|
|
272
|
-
const subFamiliesDecorative = await getTopicDetails(
|
|
273
|
-
topicProductWithFields,
|
|
274
|
-
"subFamiliesDecorative",
|
|
275
|
-
"topicSubFamily",
|
|
276
|
-
false,
|
|
277
|
-
true,
|
|
278
|
-
true
|
|
279
|
-
);
|
|
280
|
-
|
|
281
|
-
const subFamilies = [
|
|
282
|
-
...subFamiliesArchitectural,
|
|
283
|
-
...subFamiliesOutdoor,
|
|
284
|
-
...subFamiliesDecorative,
|
|
285
|
-
];
|
|
286
|
-
|
|
287
|
-
log(`Get modelsArchitectural details...`);
|
|
288
|
-
const modelsArchitectural = await getTopicDetails(
|
|
289
|
-
topicProductWithFields,
|
|
290
|
-
"modelsArchitectural",
|
|
291
|
-
"topicModel",
|
|
292
|
-
false,
|
|
293
|
-
true,
|
|
294
|
-
true
|
|
295
|
-
);
|
|
296
|
-
|
|
297
|
-
log(`Get modelsOutdoor details...`);
|
|
298
|
-
const modelsOutdoor = await getTopicDetails(
|
|
299
|
-
topicProductWithFields,
|
|
300
|
-
"modelsOutdoor",
|
|
301
|
-
"topicModel",
|
|
302
|
-
false,
|
|
303
|
-
true,
|
|
304
|
-
true
|
|
305
|
-
);
|
|
306
|
-
|
|
307
|
-
log(`Get modelsDecorative details...`);
|
|
308
|
-
const modelsDecorative = await getTopicDetails(
|
|
309
|
-
topicProductWithFields,
|
|
310
|
-
"modelsDecorative",
|
|
311
|
-
"topicModel",
|
|
312
|
-
false,
|
|
313
|
-
true,
|
|
314
|
-
true
|
|
315
|
-
);
|
|
316
|
-
const models = [
|
|
317
|
-
...modelsArchitectural,
|
|
318
|
-
...modelsOutdoor,
|
|
319
|
-
...modelsDecorative,
|
|
320
|
-
];
|
|
321
|
-
|
|
322
|
-
log(`Get subModelsArchitectural details...`);
|
|
323
|
-
const subModelsArchitectural = await getTopicDetails(
|
|
324
|
-
topicProductWithFields,
|
|
325
|
-
"subModelsArchitectural",
|
|
326
|
-
"topicSubModel",
|
|
327
|
-
false,
|
|
328
|
-
true,
|
|
329
|
-
true
|
|
330
|
-
);
|
|
331
|
-
|
|
332
|
-
log(`Get subModelsOutdoor details...`);
|
|
333
|
-
const subModelsOutdoor = await getTopicDetails(
|
|
334
|
-
topicProductWithFields,
|
|
335
|
-
"subModelsOutdoor",
|
|
336
|
-
"topicSubModel",
|
|
337
|
-
false,
|
|
338
|
-
true,
|
|
339
|
-
true
|
|
340
|
-
);
|
|
341
|
-
|
|
342
|
-
log(`Get subModelsDecorative details...`);
|
|
343
|
-
const subModelsDecorative = await getTopicDetails(
|
|
344
|
-
topicProductWithFields,
|
|
345
|
-
"subModelsDecorative",
|
|
346
|
-
"topicSubModel",
|
|
347
|
-
false,
|
|
348
|
-
true,
|
|
349
|
-
true
|
|
350
|
-
);
|
|
351
|
-
|
|
352
|
-
// const subModels = [
|
|
353
|
-
// ...subModelsArchitectural,
|
|
354
|
-
// ...subModelsOutdoor,
|
|
355
|
-
// ...subModelsDecorative,
|
|
356
|
-
// ];
|
|
357
|
-
|
|
358
|
-
log(`Get productLine details...`);
|
|
359
|
-
const productLine = await getTopicDetails(
|
|
360
|
-
topicProductWithFields,
|
|
361
|
-
"productLine",
|
|
362
|
-
"topicProductLine",
|
|
363
|
-
false,
|
|
364
|
-
true,
|
|
365
|
-
true
|
|
366
|
-
);
|
|
367
|
-
|
|
368
|
-
log(`Get productSubLine details...`);
|
|
369
|
-
const productSubLine = await getTopicDetails(
|
|
370
|
-
topicProductWithFields,
|
|
371
|
-
"productSubLine",
|
|
372
|
-
"topicProductSubLine",
|
|
373
|
-
false,
|
|
374
|
-
true,
|
|
375
|
-
true
|
|
376
|
-
);
|
|
377
|
-
|
|
378
|
-
log(`Get autoDescription...`);
|
|
379
|
-
const autoDescriptionLengthLimit = 100;
|
|
380
|
-
const autoDescription = topicProductWithFields?.fields?.autoDescription ?? {};
|
|
381
|
-
Object.entries(autoDescription).forEach(
|
|
382
|
-
(desc: any) =>
|
|
383
|
-
(autoDescription[desc[0]] =
|
|
384
|
-
desc[1] && desc[1].length > autoDescriptionLengthLimit
|
|
385
|
-
? desc[1].substring(0, autoDescriptionLengthLimit) + " ..."
|
|
386
|
-
: desc[1])
|
|
387
|
-
);
|
|
388
|
-
|
|
389
|
-
log(`Get thumbnail imgix details...`);
|
|
390
|
-
let thumbnailImgix = {};
|
|
391
|
-
const thumbnailImgixWrapperImgixID =
|
|
392
|
-
topicProductWithFields?.fields?.thumbnailImgix?.[
|
|
393
|
-
defaultEnvironmentLocaleCode
|
|
394
|
-
]?.sys.id;
|
|
395
|
-
if (thumbnailImgixWrapperImgixID) {
|
|
396
|
-
thumbnailImgix = await getWrapperImgixFields(thumbnailImgixWrapperImgixID);
|
|
397
|
-
} else {
|
|
398
|
-
log(`No thumbnail imgix found`, "WARN");
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
let productFields =
|
|
402
|
-
topicProductWithFields?.fields?.productFields?.[
|
|
403
|
-
defaultEnvironmentLocaleCode
|
|
404
|
-
] || "";
|
|
405
|
-
|
|
406
|
-
if (!productFields?.photometric) {
|
|
407
|
-
productFields.photometric = {
|
|
408
|
-
realNetFlow: undefined,
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
const realNetFlowValue = Number(productFields.photometric.realNetFlow);
|
|
413
|
-
productFields.photometric.realNetFlow = !isNaN(realNetFlowValue)
|
|
414
|
-
? realNetFlowValue
|
|
415
|
-
: "";
|
|
416
|
-
|
|
417
|
-
log(`Get designers details...`);
|
|
418
|
-
const designers = await getTopicDetails(
|
|
419
|
-
topicProductWithFields,
|
|
420
|
-
"designers",
|
|
421
|
-
"topicDesigner",
|
|
422
|
-
false,
|
|
423
|
-
true,
|
|
424
|
-
true
|
|
425
|
-
);
|
|
426
|
-
|
|
427
|
-
log(`Get certificationIcons details...`);
|
|
428
|
-
if (!productFields?.certificationIcons) {
|
|
429
|
-
productFields.certificationIcons = [];
|
|
430
|
-
}
|
|
431
|
-
if (productFields.certification?.certificates?.length) {
|
|
432
|
-
productFields.certificationIcons = productFields.certificationIcons.concat(
|
|
433
|
-
productFields.certification.certificates
|
|
434
|
-
);
|
|
435
|
-
}
|
|
436
|
-
if (productFields.marking?.markings?.length) {
|
|
437
|
-
productFields.certificationIcons = productFields.certificationIcons.concat(
|
|
438
|
-
productFields.marking.markings
|
|
439
|
-
);
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
log(`Get certificationFilters details...`);
|
|
443
|
-
productFields.certificationFilters = getCertificationFilters(
|
|
444
|
-
topicProductWithFields?.fields?.productFields?.[
|
|
445
|
-
defaultEnvironmentLocaleCode
|
|
446
|
-
]
|
|
447
|
-
);
|
|
448
|
-
|
|
449
|
-
log(`Get filterableCertifications details...`);
|
|
450
|
-
const filterableCertificationsFields = ["enec", "ul", "certificates"];
|
|
451
|
-
for (const filterableCertificationsField of filterableCertificationsFields) {
|
|
452
|
-
productFields = addProductFieldValueCodesByPimDetails(
|
|
453
|
-
topicProductWithFields.fields.productFields?.[
|
|
454
|
-
defaultEnvironmentLocaleCode
|
|
455
|
-
],
|
|
456
|
-
productFields,
|
|
457
|
-
filterableCertificationsField,
|
|
458
|
-
"certification",
|
|
459
|
-
"filterableCertifications",
|
|
460
|
-
false,
|
|
461
|
-
true
|
|
462
|
-
);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
if (!productFields?.certification) {
|
|
466
|
-
productFields.certification = {};
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
productFields.certification.enecCertified =
|
|
470
|
-
!!productFields.certification?.enecCertified;
|
|
471
|
-
|
|
472
|
-
log(`Get designYear details...`);
|
|
473
|
-
const designYear = productFields?.designYear || "";
|
|
474
|
-
|
|
475
|
-
log(`Get destinations details...`);
|
|
476
|
-
const destinations =
|
|
477
|
-
topicProductWithFields?.fields?.destinations?.[
|
|
478
|
-
defaultEnvironmentLocaleCode
|
|
479
|
-
] || [];
|
|
480
|
-
|
|
481
|
-
log(`Get availableTo details...`);
|
|
482
|
-
productFields.availableTo = [];
|
|
483
|
-
if (
|
|
484
|
-
topicProductWithFields?.fields?.productFields?.[
|
|
485
|
-
defaultEnvironmentLocaleCode
|
|
486
|
-
].visibleToShop
|
|
487
|
-
) {
|
|
488
|
-
productFields.availableTo.push("visibleToShop");
|
|
489
|
-
}
|
|
490
|
-
if (
|
|
491
|
-
topicProductWithFields?.fields?.productFields?.[
|
|
492
|
-
defaultEnvironmentLocaleCode
|
|
493
|
-
].quickDelivery
|
|
494
|
-
) {
|
|
495
|
-
productFields.availableTo.push("quickDelivery");
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
// Single record
|
|
499
|
-
const record: AlgoliaProductRecord = {
|
|
500
|
-
objectID: topicProductWithFields.sys.id,
|
|
501
|
-
name:
|
|
502
|
-
topicProductWithFields?.fields?.name?.[defaultEnvironmentLocaleCode] ||
|
|
503
|
-
"",
|
|
504
|
-
names: await getAllTranslations(topicProductWithFields?.fields?.name || {}),
|
|
505
|
-
code:
|
|
506
|
-
topicProductWithFields?.fields?.code?.[defaultEnvironmentLocaleCode] ||
|
|
507
|
-
"",
|
|
508
|
-
slugs,
|
|
509
|
-
isProtected,
|
|
510
|
-
// description: topicProductWithFields?.fields?.description, // Rimosso perché in alcuni prodotti si superava il limite massimo della dimensione del record (10000 bytes). es: F0070054
|
|
511
|
-
// excerpt: topicProductWithFields?.fields?.excerpt, // Rimosso perché in alcuni prodotti si superava il limite massimo della dimensione del record (10000 bytes). es: F0070054
|
|
512
|
-
autoDescription: await getAllTranslations(autoDescription || {}),
|
|
513
|
-
thumbnailImgix,
|
|
514
|
-
catalogs,
|
|
515
|
-
categoriesArchitectural,
|
|
516
|
-
categoriesOutdoor,
|
|
517
|
-
categoriesDecorative,
|
|
518
|
-
categories,
|
|
519
|
-
families,
|
|
520
|
-
subFamiliesArchitectural,
|
|
521
|
-
subFamiliesOutdoor,
|
|
522
|
-
subFamiliesDecorative,
|
|
523
|
-
subFamilies,
|
|
524
|
-
modelsArchitectural,
|
|
525
|
-
modelsOutdoor,
|
|
526
|
-
modelsDecorative,
|
|
527
|
-
models,
|
|
528
|
-
subModelsArchitectural,
|
|
529
|
-
subModelsOutdoor,
|
|
530
|
-
subModelsDecorative,
|
|
531
|
-
// subModels,
|
|
532
|
-
productLine: productLine?.[0],
|
|
533
|
-
productSubLine: productSubLine?.[0],
|
|
534
|
-
productFields,
|
|
535
|
-
designers,
|
|
536
|
-
designYear,
|
|
537
|
-
destinations,
|
|
538
|
-
techSpec: await getAllTranslations(
|
|
539
|
-
topicProductWithFields?.fields?.techSpec || {}
|
|
540
|
-
),
|
|
541
|
-
lastSyncDate: getLocalISOTime(),
|
|
542
|
-
};
|
|
543
|
-
|
|
544
|
-
return record;
|
|
545
|
-
};
|
|
546
|
-
|
|
547
|
-
export const reindexProduct = async (
|
|
548
|
-
topicProductId: string,
|
|
549
|
-
generatePdf: boolean = false
|
|
550
|
-
) => {
|
|
551
|
-
const timeStart = new Date();
|
|
552
|
-
|
|
553
|
-
log(`reindexProduct - entryId: ${topicProductId} `);
|
|
554
|
-
|
|
555
|
-
const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
556
|
-
const topicProduct = await getEntryByID(
|
|
557
|
-
topicProductId,
|
|
558
|
-
"topicProduct",
|
|
559
|
-
topicProductSelect
|
|
560
|
-
);
|
|
561
|
-
|
|
562
|
-
const index = getIndex(indexKey);
|
|
563
|
-
let record = null;
|
|
564
|
-
if (!topicProduct) {
|
|
565
|
-
log(
|
|
566
|
-
`No topicProduct found with id ${topicProductId}. Delete object if exists`,
|
|
567
|
-
"WARN"
|
|
568
|
-
);
|
|
569
|
-
record = await index.deleteObject(topicProductId);
|
|
570
|
-
return { ...record };
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
const object = await getObject(topicProduct);
|
|
574
|
-
// Save record to Algolia
|
|
575
|
-
if (!isObjectToDelete(object, defaultEnvironmentLocaleCode)) {
|
|
576
|
-
log(`Save object`);
|
|
577
|
-
record = await index.saveObject(object);
|
|
578
|
-
if (generatePdf && record?.objectID) {
|
|
579
|
-
log(`Start triggerPDFGenerator`);
|
|
580
|
-
await triggerPDFGenerator(record.objectID, true);
|
|
581
|
-
} else {
|
|
582
|
-
log(`Skip triggerPDFGenerator`);
|
|
583
|
-
}
|
|
584
|
-
} else {
|
|
585
|
-
log(`Delete object`);
|
|
586
|
-
record = await index.deleteObject(object.objectID);
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
const timeEnd = new Date();
|
|
590
|
-
const seconds = secondBetweenTwoDate(timeStart, timeEnd);
|
|
591
|
-
log(`Execution time: ${seconds} seconds`);
|
|
592
|
-
return { ...record, ...object };
|
|
593
|
-
};
|
|
594
|
-
|
|
595
|
-
const getObjects = async (
|
|
596
|
-
filterKey: string,
|
|
597
|
-
filterValue: string,
|
|
598
|
-
offset: number,
|
|
599
|
-
limit: number,
|
|
600
|
-
lastPimSyncDateGte?: string,
|
|
601
|
-
filters: AlgoliaObjectFilter[] = [],
|
|
602
|
-
lastModifiedGte?: string
|
|
603
|
-
): Promise<AlgoliaPaginateRecords> => {
|
|
604
|
-
const client = await getClient();
|
|
605
|
-
|
|
606
|
-
const opts: any = {
|
|
607
|
-
content_type: "topicProduct",
|
|
608
|
-
limit,
|
|
609
|
-
skip: offset,
|
|
610
|
-
select: topicProductSelect,
|
|
611
|
-
};
|
|
612
|
-
opts[filterKey] = filterValue;
|
|
613
|
-
if (lastPimSyncDateGte) {
|
|
614
|
-
opts["fields.lastPimSyncDate[gte]"] = lastPimSyncDateGte;
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
if (lastModifiedGte) {
|
|
618
|
-
opts["sys.updatedAt[gte]"] = lastModifiedGte;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
if (filters?.length) {
|
|
622
|
-
for (const filter of filters) {
|
|
623
|
-
opts[filter.key] = filter.value;
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
const { items, total } = await client.withAllLocales.getEntries(opts);
|
|
628
|
-
|
|
629
|
-
const objects: AlgoliaProductRecord[] = [];
|
|
630
|
-
let count: number = Number(offset);
|
|
631
|
-
let current: number = 0;
|
|
632
|
-
for (const topicProduct of items) {
|
|
633
|
-
log(`${++count} of ${total}`, "INFO");
|
|
634
|
-
const timeStart = new Date();
|
|
635
|
-
const record = await getObject(topicProduct);
|
|
636
|
-
const timeEnd = new Date();
|
|
637
|
-
const seconds = secondBetweenTwoDate(timeStart, timeEnd);
|
|
638
|
-
log(`Execution time: ${seconds} seconds`);
|
|
639
|
-
objects.push(record);
|
|
640
|
-
if (serverUtils) {
|
|
641
|
-
serverUtils.log(topicProduct.sys.id);
|
|
642
|
-
const progress = Math.floor((++current / items.length) * 100);
|
|
643
|
-
serverUtils.updateProgress(progress);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
return {
|
|
648
|
-
objects,
|
|
649
|
-
offset: Number(offset) + Number(limit),
|
|
650
|
-
limit: Number(limit),
|
|
651
|
-
completed: count >= total, // if is true the import is completed
|
|
652
|
-
total,
|
|
653
|
-
};
|
|
654
|
-
};
|
|
655
|
-
|
|
656
|
-
/**
|
|
657
|
-
* Reindex products
|
|
658
|
-
*
|
|
659
|
-
*
|
|
660
|
-
* @param filterKey Eg: "fields.catalogs.sys.id[in]" or "fields.families.sys.id[in]"
|
|
661
|
-
* @param filterValue Eg: "DECORATIVE" or "LIGHTING_IN_THE_RAIN"
|
|
662
|
-
* @param offset
|
|
663
|
-
* @param limit Default: 50
|
|
664
|
-
* @param lastPimSyncDateGte Eg: "2021-11-12T23:00:00.000Z"
|
|
665
|
-
* @param generatePdf
|
|
666
|
-
*/
|
|
667
|
-
export const reindexProducts = async (
|
|
668
|
-
filterKey: string,
|
|
669
|
-
filterValue: string,
|
|
670
|
-
offset: number = 0,
|
|
671
|
-
limit: number = 50,
|
|
672
|
-
lastPimSyncDateGte?: string,
|
|
673
|
-
generatePdf: boolean = false,
|
|
674
|
-
filters: AlgoliaObjectFilter[] = [],
|
|
675
|
-
lastModifiedGte?: string
|
|
676
|
-
) => {
|
|
677
|
-
const timeStart = new Date();
|
|
678
|
-
log(
|
|
679
|
-
`reindexProducts - filterKey: ${filterKey} filterValue: ${filterValue} offset: ${offset} limit: ${limit} lastPimSyncDateGte: ${lastPimSyncDateGte} filters: ${filters
|
|
680
|
-
.map((filter) => `${filter.key}:${filter.value}`)
|
|
681
|
-
.join(", ")}`
|
|
682
|
-
);
|
|
683
|
-
|
|
684
|
-
const records = await getObjects(
|
|
685
|
-
filterKey,
|
|
686
|
-
filterValue,
|
|
687
|
-
offset,
|
|
688
|
-
limit,
|
|
689
|
-
lastPimSyncDateGte,
|
|
690
|
-
filters,
|
|
691
|
-
lastModifiedGte
|
|
692
|
-
);
|
|
693
|
-
const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
694
|
-
const objectsToSave = records.objects.filter(
|
|
695
|
-
(object) => !isObjectToDelete(object, defaultEnvironmentLocaleCode)
|
|
696
|
-
);
|
|
697
|
-
const objectIdsToDelete = records.objects
|
|
698
|
-
.filter((object) => isObjectToDelete(object, defaultEnvironmentLocaleCode))
|
|
699
|
-
.map((object) => object.objectID);
|
|
700
|
-
|
|
701
|
-
// Save records to Algolia
|
|
702
|
-
const index = getIndex(indexKey);
|
|
703
|
-
log(`Save ${objectsToSave.length} objects to ${index.indexName} index`);
|
|
704
|
-
const savedObjectIDs = await index.saveObjects(objectsToSave);
|
|
705
|
-
log(
|
|
706
|
-
`Delete ${objectIdsToDelete.length} objects from ${index.indexName} index`
|
|
707
|
-
);
|
|
708
|
-
const deletedObjectIDs = await index.deleteObjects(objectIdsToDelete);
|
|
709
|
-
|
|
710
|
-
if (generatePdf && savedObjectIDs?.objectIDs) {
|
|
711
|
-
await Promise.all(
|
|
712
|
-
savedObjectIDs.objectIDs.map(async (savedObjectId) => {
|
|
713
|
-
await triggerPDFGenerator(savedObjectId, true);
|
|
714
|
-
})
|
|
715
|
-
);
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
const timeEnd = new Date();
|
|
719
|
-
const seconds = secondBetweenTwoDate(timeStart, timeEnd);
|
|
720
|
-
log(`Execution time: ${seconds} seconds`);
|
|
721
|
-
|
|
722
|
-
return {
|
|
723
|
-
...records,
|
|
724
|
-
savedObjectIDs: savedObjectIDs.objectIDs,
|
|
725
|
-
deletedObjectIDs: deletedObjectIDs.objectIDs,
|
|
726
|
-
};
|
|
727
|
-
};
|
|
728
|
-
|
|
729
|
-
export const removeProductObject = async (topicProductId: string) => {
|
|
730
|
-
return removeIndexObject(topicProductId, indexKey);
|
|
731
|
-
};
|