pim-import 4.12.4 → 4.13.1
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/families.js +1 -0
- package/dist/algolia/families.js.map +1 -1
- package/dist/algolia/models.js +1 -0
- package/dist/algolia/models.js.map +1 -1
- package/dist/algolia/subFamilies.js +1 -0
- package/dist/algolia/subFamilies.js.map +1 -1
- package/dist/algolia/subModels.js +1 -0
- package/dist/algolia/subModels.js.map +1 -1
- package/dist/pim/methods/families.js +4 -0
- package/dist/pim/methods/families.js.map +1 -1
- package/dist/pim/methods/models.js +4 -0
- package/dist/pim/methods/models.js.map +1 -1
- package/dist/pim/methods/products.js +34 -17
- package/dist/pim/methods/products.js.map +1 -1
- package/dist/pim/methods/subfamilies.js +4 -0
- package/dist/pim/methods/subfamilies.js.map +1 -1
- package/package.json +1 -1
- package/src/algolia/families.ts +5 -0
- package/src/algolia/models.ts +5 -0
- package/src/algolia/subFamilies.ts +4 -0
- package/src/algolia/subModels.ts +5 -0
- package/src/pim/methods/families.ts +13 -3
- package/src/pim/methods/models.ts +9 -4
- package/src/pim/methods/products.ts +185 -120
- package/src/pim/methods/subfamilies.ts +13 -5
- package/types/algolia/families.d.ts +2 -0
- package/types/algolia/models.d.ts +1 -0
- package/types/algolia/subFamilies.d.ts +1 -0
- package/types/algolia/subModels.d.ts +1 -0
- package/types/pim/methods/products.d.ts +3 -1
|
@@ -325,19 +325,23 @@ const notVisibleToWebProduct = async (code: string): Promise<void> => {
|
|
|
325
325
|
}
|
|
326
326
|
};
|
|
327
327
|
|
|
328
|
-
const setHideInRegionField = async (
|
|
329
|
-
|
|
328
|
+
export const setHideInRegionField = async (
|
|
329
|
+
destinations: string[],
|
|
330
330
|
pageData: CreateEntryProps
|
|
331
331
|
) => {
|
|
332
332
|
const env = await getEnvironment();
|
|
333
333
|
const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
334
334
|
|
|
335
|
-
const productRegions =
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
335
|
+
const productRegions = destinations
|
|
336
|
+
?.filter(
|
|
337
|
+
(item: any) =>
|
|
338
|
+
item?.code?.includes("PROFESSIONAL_") ||
|
|
339
|
+
(typeof item === "string" && item?.includes("PROFESSIONAL_"))
|
|
340
|
+
)
|
|
339
341
|
.map((item: any) => {
|
|
340
|
-
const region =
|
|
342
|
+
const region =
|
|
343
|
+
item?.code?.replace("PROFESSIONAL_", "")?.toLowerCase() ||
|
|
344
|
+
item?.replace("PROFESSIONAL_", "")?.toLowerCase();
|
|
341
345
|
return region === "china" ? "cn" : region;
|
|
342
346
|
});
|
|
343
347
|
|
|
@@ -354,6 +358,7 @@ const setHideInRegionField = async (
|
|
|
354
358
|
let count = 0;
|
|
355
359
|
for (const item of items) {
|
|
356
360
|
const region = item?.fields?.region?.[defEnvLocaleCode];
|
|
361
|
+
|
|
357
362
|
if (!productRegions.includes(region)) {
|
|
358
363
|
log(`Hide in region: ${region}`);
|
|
359
364
|
pageData.fields = await addToRelationFields(
|
|
@@ -382,6 +387,7 @@ const getProductPageData = async (
|
|
|
382
387
|
productEntry: Entry,
|
|
383
388
|
productPageEntry: Entry
|
|
384
389
|
): Promise<CreateEntryProps> => {
|
|
390
|
+
const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
385
391
|
const pageData: CreateEntryProps = {
|
|
386
392
|
fields: productPageEntry?.fields || {},
|
|
387
393
|
};
|
|
@@ -400,7 +406,9 @@ const getProductPageData = async (
|
|
|
400
406
|
);
|
|
401
407
|
|
|
402
408
|
// hideInRegions
|
|
403
|
-
|
|
409
|
+
const destinations =
|
|
410
|
+
productEntry?.fields?.productFields?.[defEnvLocaleCode]?.destinations;
|
|
411
|
+
pageData.fields = await setHideInRegionField(destinations, pageData);
|
|
404
412
|
return pageData;
|
|
405
413
|
};
|
|
406
414
|
|
|
@@ -1066,10 +1074,14 @@ const getProductData = async (
|
|
|
1066
1074
|
);
|
|
1067
1075
|
|
|
1068
1076
|
// Destinations
|
|
1069
|
-
if(productDetails?.destinations?.length){
|
|
1077
|
+
if (productDetails?.destinations?.length) {
|
|
1070
1078
|
log(`set destinations`);
|
|
1071
|
-
data.fields = await addFieldValue(
|
|
1072
|
-
|
|
1079
|
+
data.fields = await addFieldValue(
|
|
1080
|
+
data,
|
|
1081
|
+
"destinations",
|
|
1082
|
+
productDetails.destinations.map((item) => item.code)
|
|
1083
|
+
);
|
|
1084
|
+
} else {
|
|
1073
1085
|
log(`destinations not found`, "WARN");
|
|
1074
1086
|
}
|
|
1075
1087
|
|
|
@@ -1631,7 +1643,15 @@ export const getAllProductEntriesByCatalog = async (
|
|
|
1631
1643
|
return allItems;
|
|
1632
1644
|
};
|
|
1633
1645
|
|
|
1634
|
-
const productAudit = async (
|
|
1646
|
+
const productAudit = async (
|
|
1647
|
+
audit: Audit,
|
|
1648
|
+
productEntries: Entry[],
|
|
1649
|
+
catalog: AvailableCatalogs,
|
|
1650
|
+
defaultEnvironmentLocaleCode: string,
|
|
1651
|
+
current: number,
|
|
1652
|
+
allAudit: Audit[],
|
|
1653
|
+
productPageEntries: Entry[]
|
|
1654
|
+
) => {
|
|
1635
1655
|
log(`Search product entry with id ${audit.product}...`);
|
|
1636
1656
|
let productEntry = productEntries.find(
|
|
1637
1657
|
(currentEntry) =>
|
|
@@ -1653,7 +1673,7 @@ const productAudit = async (audit: Audit, productEntries: Entry[], catalog: Avai
|
|
|
1653
1673
|
const progress = Math.floor((++current / allAudit.length) * 100);
|
|
1654
1674
|
serverUtils.updateProgress(progress);
|
|
1655
1675
|
}
|
|
1656
|
-
return {current, continue: true}
|
|
1676
|
+
return { current, continue: true };
|
|
1657
1677
|
}
|
|
1658
1678
|
|
|
1659
1679
|
log(`Founded product with id ${productEntry.sys.id}`);
|
|
@@ -1671,17 +1691,14 @@ const productAudit = async (audit: Audit, productEntries: Entry[], catalog: Avai
|
|
|
1671
1691
|
}
|
|
1672
1692
|
|
|
1673
1693
|
log(`Get product catalogs...`);
|
|
1674
|
-
const productCatalogs: AvailableCatalogs[] =
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
);
|
|
1694
|
+
const productCatalogs: AvailableCatalogs[] = productEntry?.fields?.catalogs?.[
|
|
1695
|
+
defaultEnvironmentLocaleCode
|
|
1696
|
+
].map((entryCatalog: FieldItem) => {
|
|
1697
|
+
return entryCatalog.sys.id;
|
|
1698
|
+
});
|
|
1680
1699
|
|
|
1681
1700
|
if (catalog && !productCatalogs.includes(catalog)) {
|
|
1682
|
-
log(
|
|
1683
|
-
`Product ${audit.product} does not belong to the ${catalog} catalog`
|
|
1684
|
-
);
|
|
1701
|
+
log(`Product ${audit.product} does not belong to the ${catalog} catalog`);
|
|
1685
1702
|
} else if (["PRODUCT_UNPUBLISH", "PRODUCT_WEBOFF"].includes(audit.what)) {
|
|
1686
1703
|
log(`Set the product status as archive...`);
|
|
1687
1704
|
// Set the product status as archive
|
|
@@ -1699,11 +1716,7 @@ const productAudit = async (audit: Audit, productEntries: Entry[], catalog: Avai
|
|
|
1699
1716
|
`Creating redirect from ${audit.product} to ${audit.upgradeProduct}`
|
|
1700
1717
|
);
|
|
1701
1718
|
const pageEntryToId = getProductPageIdByCode(audit.upgradeProduct);
|
|
1702
|
-
const pageEntryTo = await getEntryByID(
|
|
1703
|
-
pageEntryToId,
|
|
1704
|
-
"page",
|
|
1705
|
-
"sys.id"
|
|
1706
|
-
);
|
|
1719
|
+
const pageEntryTo = await getEntryByID(pageEntryToId, "page", "sys.id");
|
|
1707
1720
|
|
|
1708
1721
|
if (pageEntryTo) {
|
|
1709
1722
|
// Save redirect
|
|
@@ -1730,7 +1743,7 @@ const productAudit = async (audit: Audit, productEntries: Entry[], catalog: Avai
|
|
|
1730
1743
|
for (const item of audit?.catalogs) {
|
|
1731
1744
|
if (!item?.where) {
|
|
1732
1745
|
log(
|
|
1733
|
-
`catalogs.where field not exists. Product: ${audit.product} `,
|
|
1746
|
+
`catalogs.where field not exists. Product: ${audit.product} `,
|
|
1734
1747
|
"WARN"
|
|
1735
1748
|
);
|
|
1736
1749
|
} else {
|
|
@@ -1763,8 +1776,7 @@ const productAudit = async (audit: Audit, productEntries: Entry[], catalog: Avai
|
|
|
1763
1776
|
);
|
|
1764
1777
|
}
|
|
1765
1778
|
if (item?.models) {
|
|
1766
|
-
const modelsFieldKey =
|
|
1767
|
-
"models" + capitalizeFirstLetter(item.where);
|
|
1779
|
+
const modelsFieldKey = "models" + capitalizeFirstLetter(item.where);
|
|
1768
1780
|
productEntry.fields = await removeFromRelationFields(
|
|
1769
1781
|
productEntry,
|
|
1770
1782
|
modelsFieldKey,
|
|
@@ -1792,15 +1804,20 @@ const productAudit = async (audit: Audit, productEntries: Entry[], catalog: Avai
|
|
|
1792
1804
|
}
|
|
1793
1805
|
}
|
|
1794
1806
|
} else {
|
|
1795
|
-
log(
|
|
1796
|
-
`It has not yet been defined how to process the state ${audit.what}`
|
|
1797
|
-
);
|
|
1807
|
+
log(`It has not yet been defined how to process the state ${audit.what}`);
|
|
1798
1808
|
}
|
|
1799
1809
|
|
|
1800
|
-
return {current, continue: false}
|
|
1801
|
-
}
|
|
1810
|
+
return { current, continue: false };
|
|
1811
|
+
};
|
|
1802
1812
|
|
|
1803
|
-
const familyAudit = async (
|
|
1813
|
+
const familyAudit = async (
|
|
1814
|
+
audit: Audit,
|
|
1815
|
+
familyEntries: Entry[],
|
|
1816
|
+
catalog: AvailableCatalogs,
|
|
1817
|
+
defaultEnvironmentLocaleCode: string,
|
|
1818
|
+
current: number,
|
|
1819
|
+
allAudit: Audit[]
|
|
1820
|
+
) => {
|
|
1804
1821
|
log(`Search family entry with id ${audit.product}...`);
|
|
1805
1822
|
let familyEntry = familyEntries.find(
|
|
1806
1823
|
(currentEntry) =>
|
|
@@ -1822,35 +1839,34 @@ const familyAudit = async (audit: Audit, familyEntries: Entry[], catalog: Availa
|
|
|
1822
1839
|
const progress = Math.floor((++current / allAudit.length) * 100);
|
|
1823
1840
|
serverUtils.updateProgress(progress);
|
|
1824
1841
|
}
|
|
1825
|
-
return {current, continue: true}
|
|
1842
|
+
return { current, continue: true };
|
|
1826
1843
|
}
|
|
1827
1844
|
|
|
1828
1845
|
log(`Founded family with id ${familyEntry.sys.id}`);
|
|
1829
1846
|
|
|
1830
1847
|
log(`Get family catalogs...`);
|
|
1831
|
-
const familyCatalogs: AvailableCatalogs[] =
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
);
|
|
1848
|
+
const familyCatalogs: AvailableCatalogs[] = familyEntry?.fields?.catalogs?.[
|
|
1849
|
+
defaultEnvironmentLocaleCode
|
|
1850
|
+
].map((entryCatalog: FieldItem) => {
|
|
1851
|
+
return entryCatalog.sys.id;
|
|
1852
|
+
});
|
|
1837
1853
|
|
|
1838
1854
|
if (catalog && !familyCatalogs.includes(catalog)) {
|
|
1839
|
-
log(
|
|
1840
|
-
`Family ${audit.product} does not belong to the ${catalog} catalog`
|
|
1841
|
-
);
|
|
1855
|
+
log(`Family ${audit.product} does not belong to the ${catalog} catalog`);
|
|
1842
1856
|
} else if (audit.what === "REMOVE_FAMILY_RELATIONS") {
|
|
1843
1857
|
for (const item of audit?.catalogs) {
|
|
1844
1858
|
if (!item?.where) {
|
|
1845
1859
|
log(
|
|
1846
|
-
`catalogs.where field not exists. Family: ${audit.product} `,
|
|
1860
|
+
`catalogs.where field not exists. Family: ${audit.product} `,
|
|
1847
1861
|
"WARN"
|
|
1848
1862
|
);
|
|
1849
1863
|
} else {
|
|
1850
|
-
if(item.where === "DESIGNERS" && item?.codes){
|
|
1851
|
-
const designers = item.codes.split(
|
|
1852
|
-
for(const designer of designers){
|
|
1853
|
-
log(
|
|
1864
|
+
if (item.where === "DESIGNERS" && item?.codes) {
|
|
1865
|
+
const designers = item.codes.split(",");
|
|
1866
|
+
for (const designer of designers) {
|
|
1867
|
+
log(
|
|
1868
|
+
`Remove ${designer} designer to ${familyEntry.sys.id} family if exists`
|
|
1869
|
+
);
|
|
1854
1870
|
familyEntry.fields = await removeFromRelationFields(
|
|
1855
1871
|
familyEntry,
|
|
1856
1872
|
"designer",
|
|
@@ -1863,15 +1879,20 @@ const familyAudit = async (audit: Audit, familyEntries: Entry[], catalog: Availa
|
|
|
1863
1879
|
}
|
|
1864
1880
|
}
|
|
1865
1881
|
} else {
|
|
1866
|
-
log(
|
|
1867
|
-
`It has not yet been defined how to process the state ${audit.what}`
|
|
1868
|
-
);
|
|
1882
|
+
log(`It has not yet been defined how to process the state ${audit.what}`);
|
|
1869
1883
|
}
|
|
1870
1884
|
|
|
1871
|
-
return {current, continue: false}
|
|
1872
|
-
}
|
|
1885
|
+
return { current, continue: false };
|
|
1886
|
+
};
|
|
1873
1887
|
|
|
1874
|
-
const subFamilyAudit = async (
|
|
1888
|
+
const subFamilyAudit = async (
|
|
1889
|
+
audit: Audit,
|
|
1890
|
+
subfamilyEntries: Entry[],
|
|
1891
|
+
catalog: AvailableCatalogs,
|
|
1892
|
+
defaultEnvironmentLocaleCode: string,
|
|
1893
|
+
current: number,
|
|
1894
|
+
allAudit: Audit[]
|
|
1895
|
+
) => {
|
|
1875
1896
|
log(`Search subFamily entry with id ${audit.product}...`);
|
|
1876
1897
|
let subFamilyEntry = subfamilyEntries.find(
|
|
1877
1898
|
(currentEntry) =>
|
|
@@ -1893,30 +1914,31 @@ const subFamilyAudit = async (audit: Audit, subfamilyEntries: Entry[], catalog:
|
|
|
1893
1914
|
const progress = Math.floor((++current / allAudit.length) * 100);
|
|
1894
1915
|
serverUtils.updateProgress(progress);
|
|
1895
1916
|
}
|
|
1896
|
-
return {current, continue: true}
|
|
1917
|
+
return { current, continue: true };
|
|
1897
1918
|
}
|
|
1898
1919
|
|
|
1899
1920
|
log(`Founded subFamily with id ${subFamilyEntry.sys.id}`);
|
|
1900
1921
|
|
|
1901
1922
|
log(`Get subFamily catalogs...`);
|
|
1902
|
-
const subFamilyCatalog: AvailableCatalogs =
|
|
1923
|
+
const subFamilyCatalog: AvailableCatalogs =
|
|
1924
|
+
subFamilyEntry?.fields?.catalog?.[defaultEnvironmentLocaleCode].sys.id;
|
|
1903
1925
|
|
|
1904
1926
|
if (catalog && subFamilyCatalog !== catalog) {
|
|
1905
|
-
log(
|
|
1906
|
-
`SubFamily ${audit.product} does not belong to the ${catalog} catalog`
|
|
1907
|
-
);
|
|
1927
|
+
log(`SubFamily ${audit.product} does not belong to the ${catalog} catalog`);
|
|
1908
1928
|
} else if (audit.what === "REMOVE_SUBFAMILY_RELATIONS") {
|
|
1909
1929
|
for (const item of audit?.catalogs) {
|
|
1910
1930
|
if (!item?.where) {
|
|
1911
1931
|
log(
|
|
1912
|
-
`catalogs.where field not exists. SubFamily: ${audit.product} `,
|
|
1932
|
+
`catalogs.where field not exists. SubFamily: ${audit.product} `,
|
|
1913
1933
|
"WARN"
|
|
1914
1934
|
);
|
|
1915
1935
|
} else {
|
|
1916
|
-
if(item.where === "DESIGNERS" && item?.codes){
|
|
1917
|
-
const designers = item.codes.split(
|
|
1918
|
-
for(const designer of designers){
|
|
1919
|
-
log(
|
|
1936
|
+
if (item.where === "DESIGNERS" && item?.codes) {
|
|
1937
|
+
const designers = item.codes.split(",");
|
|
1938
|
+
for (const designer of designers) {
|
|
1939
|
+
log(
|
|
1940
|
+
`Remove ${designer} designer to ${subFamilyEntry.sys.id} subFamily if exists`
|
|
1941
|
+
);
|
|
1920
1942
|
subFamilyEntry.fields = await removeFromRelationFields(
|
|
1921
1943
|
subFamilyEntry,
|
|
1922
1944
|
"designer",
|
|
@@ -1929,13 +1951,11 @@ const subFamilyAudit = async (audit: Audit, subfamilyEntries: Entry[], catalog:
|
|
|
1929
1951
|
}
|
|
1930
1952
|
}
|
|
1931
1953
|
} else {
|
|
1932
|
-
log(
|
|
1933
|
-
`It has not yet been defined how to process the state ${audit.what}`
|
|
1934
|
-
);
|
|
1954
|
+
log(`It has not yet been defined how to process the state ${audit.what}`);
|
|
1935
1955
|
}
|
|
1936
1956
|
|
|
1937
|
-
return {current, continue: false}
|
|
1938
|
-
}
|
|
1957
|
+
return { current, continue: false };
|
|
1958
|
+
};
|
|
1939
1959
|
|
|
1940
1960
|
/**
|
|
1941
1961
|
*
|
|
@@ -2002,10 +2022,20 @@ export const audit = async (
|
|
|
2002
2022
|
const defaultEnvironmentLocaleCode =
|
|
2003
2023
|
await getEnvironmentDefaultLocaleCode();
|
|
2004
2024
|
|
|
2005
|
-
const productAuditWhat = [
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2025
|
+
const productAuditWhat = [
|
|
2026
|
+
"PRODUCT_UNPUBLISH",
|
|
2027
|
+
"PRODUCT_WEBOFF",
|
|
2028
|
+
"REMOVE_PRODUCT_RELATIONS",
|
|
2029
|
+
];
|
|
2030
|
+
const productCodes = allAudit
|
|
2031
|
+
.filter((item) => productAuditWhat.includes(item.what))
|
|
2032
|
+
.map((audit) => audit.product);
|
|
2033
|
+
const familyCodes = allAudit
|
|
2034
|
+
.filter((item) => item.what === "REMOVE_FAMILY_RELATIONS")
|
|
2035
|
+
.map((audit) => audit.product);
|
|
2036
|
+
const subFamilyCodes = allAudit
|
|
2037
|
+
.filter((item) => item.what === "REMOVE_SUBFAMILY_RELATIONS")
|
|
2038
|
+
.map((audit) => audit.product);
|
|
2009
2039
|
const otherFilters = [];
|
|
2010
2040
|
if (catalog) {
|
|
2011
2041
|
otherFilters.push({ key: "fields.catalogs.sys.id[in]", value: catalog });
|
|
@@ -2020,8 +2050,8 @@ export const audit = async (
|
|
|
2020
2050
|
);
|
|
2021
2051
|
log(`Founded ${productEntries.length} topicProduct`);
|
|
2022
2052
|
|
|
2023
|
-
let familyEntries: Entry[] = []
|
|
2024
|
-
if(familyCodes.length){
|
|
2053
|
+
let familyEntries: Entry[] = [];
|
|
2054
|
+
if (familyCodes.length) {
|
|
2025
2055
|
familyEntries = await getAllEntriesByCodes(
|
|
2026
2056
|
familyCodes,
|
|
2027
2057
|
"topicFamily",
|
|
@@ -2032,8 +2062,8 @@ export const audit = async (
|
|
|
2032
2062
|
}
|
|
2033
2063
|
log(`Founded ${familyEntries.length} topicFamily`);
|
|
2034
2064
|
|
|
2035
|
-
let subFamilyEntries: Entry[] = []
|
|
2036
|
-
if(subFamilyCodes.length){
|
|
2065
|
+
let subFamilyEntries: Entry[] = [];
|
|
2066
|
+
if (subFamilyCodes.length) {
|
|
2037
2067
|
subFamilyEntries = await getAllEntriesByCodes(
|
|
2038
2068
|
subFamilyCodes,
|
|
2039
2069
|
"topicSubFamily",
|
|
@@ -2044,7 +2074,11 @@ export const audit = async (
|
|
|
2044
2074
|
}
|
|
2045
2075
|
log(`Founded ${subFamilyEntries.length} topicSubFamily`);
|
|
2046
2076
|
|
|
2047
|
-
if (
|
|
2077
|
+
if (
|
|
2078
|
+
!productEntries.length &&
|
|
2079
|
+
!familyEntries.length &&
|
|
2080
|
+
!subFamilyEntries.length
|
|
2081
|
+
) {
|
|
2048
2082
|
log(
|
|
2049
2083
|
`No items found between offset: ${offset} and limit: ${limit}. Total: ${total}`
|
|
2050
2084
|
);
|
|
@@ -2092,23 +2126,45 @@ export const audit = async (
|
|
|
2092
2126
|
log(`${++count} of ${total}`);
|
|
2093
2127
|
log(`I process the item ${audit.product} with status ${audit.what}`);
|
|
2094
2128
|
|
|
2095
|
-
if(productAuditWhat.includes(audit.what)){
|
|
2096
|
-
const result = await productAudit(
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2129
|
+
if (productAuditWhat.includes(audit.what)) {
|
|
2130
|
+
const result = await productAudit(
|
|
2131
|
+
audit,
|
|
2132
|
+
productEntries,
|
|
2133
|
+
catalog,
|
|
2134
|
+
defaultEnvironmentLocaleCode,
|
|
2135
|
+
current,
|
|
2136
|
+
allAudit,
|
|
2137
|
+
productPageEntries
|
|
2138
|
+
);
|
|
2139
|
+
current = result.current;
|
|
2140
|
+
if (result.continue) {
|
|
2141
|
+
continue;
|
|
2100
2142
|
}
|
|
2101
|
-
}else if(audit.what === "REMOVE_FAMILY_RELATIONS"){
|
|
2102
|
-
const result = await familyAudit(
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2143
|
+
} else if (audit.what === "REMOVE_FAMILY_RELATIONS") {
|
|
2144
|
+
const result = await familyAudit(
|
|
2145
|
+
audit,
|
|
2146
|
+
familyEntries,
|
|
2147
|
+
catalog,
|
|
2148
|
+
defaultEnvironmentLocaleCode,
|
|
2149
|
+
current,
|
|
2150
|
+
allAudit
|
|
2151
|
+
);
|
|
2152
|
+
current = result.current;
|
|
2153
|
+
if (result.continue) {
|
|
2154
|
+
continue;
|
|
2106
2155
|
}
|
|
2107
|
-
}else if(audit.what === "REMOVE_SUBFAMILY_RELATIONS"){
|
|
2108
|
-
const result = await subFamilyAudit(
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2156
|
+
} else if (audit.what === "REMOVE_SUBFAMILY_RELATIONS") {
|
|
2157
|
+
const result = await subFamilyAudit(
|
|
2158
|
+
audit,
|
|
2159
|
+
subFamilyEntries,
|
|
2160
|
+
catalog,
|
|
2161
|
+
defaultEnvironmentLocaleCode,
|
|
2162
|
+
current,
|
|
2163
|
+
allAudit
|
|
2164
|
+
);
|
|
2165
|
+
current = result.current;
|
|
2166
|
+
if (result.continue) {
|
|
2167
|
+
continue;
|
|
2112
2168
|
}
|
|
2113
2169
|
}
|
|
2114
2170
|
|
|
@@ -2130,7 +2186,8 @@ export const audit = async (
|
|
|
2130
2186
|
completed: limit === -1 || count >= total,
|
|
2131
2187
|
s3FilePath,
|
|
2132
2188
|
total,
|
|
2133
|
-
processedEntries:
|
|
2189
|
+
processedEntries:
|
|
2190
|
+
productEntries.length + familyEntries.length + subFamilyEntries.length,
|
|
2134
2191
|
};
|
|
2135
2192
|
} else {
|
|
2136
2193
|
log(`Execution completed`);
|
|
@@ -2890,44 +2947,52 @@ export const reimportAuditProducts = async (
|
|
|
2890
2947
|
};
|
|
2891
2948
|
};
|
|
2892
2949
|
|
|
2893
|
-
|
|
2894
2950
|
export const populateDestinations = async (offset: number, limit: number) => {
|
|
2895
2951
|
const env = await getEnvironment();
|
|
2896
2952
|
const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
2897
2953
|
|
|
2898
2954
|
const opts = {
|
|
2899
|
-
content_type:
|
|
2955
|
+
content_type: "topicProduct",
|
|
2900
2956
|
skip: offset,
|
|
2901
2957
|
limit,
|
|
2902
2958
|
locale: defEnvLocaleCode,
|
|
2903
2959
|
// select: 'sys.id,fields',
|
|
2904
2960
|
"sys.archivedAt[exists]": false,
|
|
2961
|
+
// "fields.destinations[exists]": false,
|
|
2905
2962
|
};
|
|
2906
|
-
|
|
2963
|
+
|
|
2964
|
+
const { items, total } = await env.getEntries(opts);
|
|
2907
2965
|
|
|
2908
2966
|
let count: number = offset;
|
|
2909
2967
|
for (let productEntry of items) {
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2968
|
+
log(`${++count} of ${total}`);
|
|
2969
|
+
log(`Product: ${productEntry.sys.id}`);
|
|
2970
|
+
const destinations =
|
|
2971
|
+
productEntry.fields.productFields[defEnvLocaleCode]?.destinations?.map(
|
|
2972
|
+
(destination: any) => destination.code
|
|
2973
|
+
) || [];
|
|
2974
|
+
|
|
2975
|
+
if (destinations.length) {
|
|
2976
|
+
log(`Set destinations: ${destinations.join(", ")}`);
|
|
2977
|
+
productEntry.fields = await addFieldValue(
|
|
2978
|
+
productEntry,
|
|
2979
|
+
"destinations",
|
|
2980
|
+
destinations
|
|
2981
|
+
);
|
|
2982
|
+
productEntry = await productEntry.update();
|
|
2983
|
+
} else {
|
|
2984
|
+
log(`No destinations found.`, "WARN");
|
|
2920
2985
|
}
|
|
2921
2986
|
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
}
|
|
2987
|
+
if (productEntry.isPublished()) {
|
|
2988
|
+
try {
|
|
2989
|
+
productEntry = await productEntry.publish();
|
|
2990
|
+
} catch (err) {
|
|
2991
|
+
log(`Cannot publish entry.`);
|
|
2992
|
+
log(err);
|
|
2993
|
+
}
|
|
2930
2994
|
}
|
|
2995
|
+
}
|
|
2931
2996
|
|
|
2932
|
-
|
|
2933
|
-
}
|
|
2997
|
+
return { completed: !total || total === count + offset, offset, limit };
|
|
2998
|
+
};
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
import { updateSubFamiliesRelToEntry, getCategoryTopicCode } from "./catalogs";
|
|
38
38
|
import { pageResponse } from "../../algolia/families";
|
|
39
39
|
import { addDesignerData } from "./designers";
|
|
40
|
+
import { setHideInRegionField } from "./products";
|
|
40
41
|
|
|
41
42
|
const getComponentModelPagesData = async (
|
|
42
43
|
componentID: string,
|
|
@@ -116,6 +117,7 @@ const getSubFamilyPageData = async (
|
|
|
116
117
|
subFamilyEntry: Entry,
|
|
117
118
|
subFamilyPageEntry: Entry
|
|
118
119
|
): Promise<CreateEntryProps> => {
|
|
120
|
+
const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
119
121
|
const pageData: CreateEntryProps = {
|
|
120
122
|
fields: subFamilyPageEntry?.fields || {},
|
|
121
123
|
};
|
|
@@ -142,6 +144,10 @@ const getSubFamilyPageData = async (
|
|
|
142
144
|
true
|
|
143
145
|
);
|
|
144
146
|
|
|
147
|
+
const destinations =
|
|
148
|
+
subFamilyEntry?.fields?.destinations?.[defEnvLocaleCode] || [];
|
|
149
|
+
pageData.fields = await setHideInRegionField(destinations, pageData);
|
|
150
|
+
|
|
145
151
|
return pageData;
|
|
146
152
|
};
|
|
147
153
|
|
|
@@ -397,18 +403,20 @@ const getTopicSubFamilyData = async (
|
|
|
397
403
|
}
|
|
398
404
|
|
|
399
405
|
// Destinations
|
|
400
|
-
if(subFamily?.destinations?.length){
|
|
406
|
+
if (subFamily?.destinations?.length) {
|
|
401
407
|
log(`set destinations`);
|
|
402
|
-
data.fields = await addFieldValue(
|
|
403
|
-
|
|
408
|
+
data.fields = await addFieldValue(
|
|
409
|
+
data,
|
|
410
|
+
"destinations",
|
|
411
|
+
subFamily.destinations
|
|
412
|
+
);
|
|
413
|
+
} else {
|
|
404
414
|
log(`destinations not found`, "WARN");
|
|
405
415
|
}
|
|
406
416
|
|
|
407
417
|
// lastPimSyncDate
|
|
408
418
|
data.fields = await addFieldValue(data, "lastPimSyncDate", getLocalISOTime());
|
|
409
419
|
|
|
410
|
-
|
|
411
|
-
|
|
412
420
|
return data;
|
|
413
421
|
};
|
|
414
422
|
|
|
@@ -17,6 +17,7 @@ export declare type AlgoliaFamilyRecord = {
|
|
|
17
17
|
productFields: TopicProductFieldsResponse[];
|
|
18
18
|
isNew: boolean;
|
|
19
19
|
priority: number;
|
|
20
|
+
destinations?: string[];
|
|
20
21
|
lastSyncDate: string;
|
|
21
22
|
};
|
|
22
23
|
export declare const reindexFamilies: (offset?: number, limit?: number, catalogCode?: AvailableCatalogs | undefined) => Promise<{
|
|
@@ -42,6 +43,7 @@ export declare const reindexFamily: (topicFamilyEntryId: string) => Promise<fals
|
|
|
42
43
|
productFields: TopicProductFieldsResponse[];
|
|
43
44
|
isNew: boolean;
|
|
44
45
|
priority: number;
|
|
46
|
+
destinations?: string[] | undefined;
|
|
45
47
|
lastSyncDate: string;
|
|
46
48
|
taskID: number;
|
|
47
49
|
}>;
|
|
@@ -18,6 +18,7 @@ export declare const reindexModel: (topicModelId: string) => Promise<{
|
|
|
18
18
|
colors?: string[] | undefined;
|
|
19
19
|
designer?: TopicDetailsResponse | undefined;
|
|
20
20
|
lastSyncDate?: string | undefined;
|
|
21
|
+
destinations?: string[] | undefined;
|
|
21
22
|
taskID: number;
|
|
22
23
|
}>;
|
|
23
24
|
export declare const reindexModels: (offset?: number, limit?: number, catalogCode?: AvailableCatalogs | undefined) => Promise<{
|
|
@@ -22,6 +22,7 @@ export declare const reindexSubFamily: (topicSubFamilyEntryId: string) => Promis
|
|
|
22
22
|
productFields: import("../types").TopicProductFieldsResponse[];
|
|
23
23
|
isNew: boolean;
|
|
24
24
|
priority: number;
|
|
25
|
+
destinations?: string[] | undefined;
|
|
25
26
|
lastSyncDate: string;
|
|
26
27
|
taskID: number;
|
|
27
28
|
}>;
|
|
@@ -13,6 +13,7 @@ export declare const reindexSubModel: (topicSubModelId: string) => Promise<{
|
|
|
13
13
|
isNew?: boolean | undefined;
|
|
14
14
|
priority?: number | undefined;
|
|
15
15
|
productCounter?: number | undefined;
|
|
16
|
+
destinations?: string[] | undefined;
|
|
16
17
|
lastSyncDate?: string | undefined;
|
|
17
18
|
taskID: number;
|
|
18
19
|
}>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ProductDetails } from "../../resources/ProductDetails";
|
|
2
2
|
import { AvailableCatalogs } from "../../types";
|
|
3
|
-
import type { Entry } from "contentful-management/dist/typings/entities/entry";
|
|
3
|
+
import type { Entry, CreateEntryProps } from "contentful-management/dist/typings/entities/entry";
|
|
4
|
+
import { KeyValueMap } from "contentful-management/dist/typings/common-types";
|
|
4
5
|
export declare type AvailableProductStatus = "To be review" | "Published" | "Unpublished";
|
|
5
6
|
export declare type AvailableRelationFieldKeys = "accessories" | "accessoryOf" | "bulbOf" | "sparepartOf" | "bulbs" | "spareparts";
|
|
7
|
+
export declare const setHideInRegionField: (destinations: string[], pageData: CreateEntryProps) => Promise<KeyValueMap>;
|
|
6
8
|
export declare const certificationFields: string[];
|
|
7
9
|
export declare const excludeCertificationFieldsKeys: string[];
|
|
8
10
|
export declare const getProductPageIdByCode: (productCode: string) => string;
|