Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const CONFIG = {
MAX_PRODUCTS_PER_CATEGORY: Number(process.env.MAX_PRODUCTS_PER_CATEGORY),
LAST_MONTHS_PRODUCTS_IN_ORDER: Number(process.env.LAST_MONTHS_PRODUCTS_IN_ORDER),
MAX_BESTSELLS_PRODUCTS: Number(process.env.MAX_BESTSELLS_PRODUCTS),
HITS_OF_WEEK_DAYS_PERIOD: Number(process.env.HITS_OF_WEEK_DAYS_PERIOD),
SCORES_MAX_SIZE: Number(process.env.SCORES_MAX_SIZE),
BASE_PRODUCT_COMMENTS_COUNT: Number(process.env.BASE_PRODUCT_COMMENTS_COUNT),
MAX_SEARCH_RESULT: Number(process.env.MAX_SEARCH_RESULT)
Expand Down
8 changes: 8 additions & 0 deletions src/products/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ export const getAllBestsellerProducts = async () => {
return getMostSoldProductsByDate(bestsellerMonthsPriorToToday);
};

export const getHitsOfWeekProducts = async () => {
const hitsOfWeekData = new Date();
hitsOfWeekData.setDate(
hitsOfWeekData.getDate() - CONFIG.HITS_OF_WEEK_DAYS_PERIOD
);
return getMostSoldProductsByDate(hitsOfWeekData);
};

export const getProductKeyValueVotes = (
productId: number,
productScoresDb: ProductScore[]
Expand Down
5 changes: 5 additions & 0 deletions src/products/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import express, { Request, Response } from "express";
import {
getAllBestsellerProducts,
getAllProducts,
getHitsOfWeekProducts,
getProductById,
getProductsByName,
} from "./product";
Expand All @@ -17,6 +18,10 @@ function createProductRouter() {
const bestsellerProducts = await getAllBestsellerProducts();
resp.status(200).json(bestsellerProducts);
})
.get("/hitsofweek", async (_, resp: Response) => {
const hitsOfWeekProducts = await getHitsOfWeekProducts();
resp.status(200).json(hitsOfWeekProducts);
})
.get("/search/:productName", async (req: Request, resp: Response) => {
const allProducts = await getProductsByName(req.params.productName);
resp.status(200).json(allProducts);
Expand Down