@infrab4a/connect-angular 5.7.5-beta.11 → 5.7.5-beta.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.
|
@@ -1833,9 +1833,12 @@ class CategorySearchStrategy {
|
|
|
1833
1833
|
const firstProducts = totalResult.data
|
|
1834
1834
|
.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
|
|
1835
1835
|
.sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
|
|
1836
|
-
const
|
|
1837
|
-
|
|
1838
|
-
.
|
|
1836
|
+
const nonPinnedProducts = totalResult.data.filter((product) => !mostRelevants.includes(product.id));
|
|
1837
|
+
const novoProducts = nonPinnedProducts
|
|
1838
|
+
.filter((product) => product.stock?.quantity > 0 && this.isCreatedWithinLastDays(product.createdAt, 30))
|
|
1839
|
+
.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
|
1840
|
+
const restProducts = nonPinnedProducts.filter((product) => !(product.stock?.quantity > 0 && this.isCreatedWithinLastDays(product.createdAt, 30)));
|
|
1841
|
+
const lastProducts = novoProducts.concat(restProducts).concat(mostRelevantWithoutStock);
|
|
1839
1842
|
const categoryMostRelevants = firstProducts.concat(lastProducts);
|
|
1840
1843
|
const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
|
|
1841
1844
|
return {
|
|
@@ -1846,6 +1849,21 @@ class CategorySearchStrategy {
|
|
|
1846
1849
|
distinct: totalResult.distinct,
|
|
1847
1850
|
};
|
|
1848
1851
|
}
|
|
1852
|
+
isCreatedWithinLastDays(createdAt, days) {
|
|
1853
|
+
if (!createdAt || days <= 0) {
|
|
1854
|
+
return false;
|
|
1855
|
+
}
|
|
1856
|
+
const createdDate = createdAt instanceof Date ? createdAt : new Date(createdAt);
|
|
1857
|
+
if (Number.isNaN(createdDate.getTime())) {
|
|
1858
|
+
return false;
|
|
1859
|
+
}
|
|
1860
|
+
const diffMs = Date.now() - createdDate.getTime();
|
|
1861
|
+
if (diffMs < 0) {
|
|
1862
|
+
return false;
|
|
1863
|
+
}
|
|
1864
|
+
const diffDays = diffMs / (1000 * 60 * 60 * 24);
|
|
1865
|
+
return diffDays <= days;
|
|
1866
|
+
}
|
|
1849
1867
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: CategorySearchStrategy, deps: [{ token: CatalogRepositoryService }, { token: CatalogHelpersService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1850
1868
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: CategorySearchStrategy }); }
|
|
1851
1869
|
}
|