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
3,052 changes: 1,833 additions & 1,219 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
"migrate": "medusa migrations run"
},
"dependencies": {
"@medusajs/admin": "7.1.8",
"@medusajs/admin": "7.1.14",
"@medusajs/cache-inmemory": "^1.8.9",
"@medusajs/cache-redis": "^1.8.9",
"@medusajs/event-bus-local": "^1.9.7",
"@medusajs/event-bus-redis": "^1.8.10",
"@medusajs/file-local": "^1.0.2",
"@medusajs/medusa": "1.18.1",
"@medusajs/medusa": "1.20.6",
"@tanstack/react-query": "4.22.0",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
Expand Down
37 changes: 37 additions & 0 deletions src/api/middlewares.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type {
MiddlewaresConfig,
MedusaRequest,
MedusaResponse,
MedusaNextFunction,
} from "@medusajs/medusa";

import { getProductFilters } from "./store/custom/getProductFilters";
import { getProductsList } from "./store/custom/getProducts";

async function logger(
req: MedusaRequest,
res: MedusaResponse,
next: MedusaNextFunction
) {
next();
}

export const config: MiddlewaresConfig = {
routes: [
{
matcher: "/store/custom",
method: "GET",
middlewares: [logger],
},
{
matcher: "/store/getProductFilters",
method: "GET",
middlewares: [getProductFilters],
},
{
matcher: "/store/getProducts",
method: "GET",
middlewares: [getProductsList],
},
],
};
20 changes: 20 additions & 0 deletions src/api/store/custom/getProductFilters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa";

export async function getProductFilters(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
try {
const filterList = {
colors: ["red", "blue", "green", "yellow", "purple"],
styles: ["HEM", "MATTER", "RIMA", "BASAL", "ART"],
rooms: ["Foyer/EntranceHall", "KitchenRoom", "FamilyRoom", "DiningRoom", "LivingRoom", "MasterBedroom", "Bathroom", "Laundry Room", "Guest Room", "Home Office", "Library"]
};
res.status(200).json({ filterList });
} catch (error) {
console.log(error)
res
.status(500)
.json({ error: "An error occurred while fetching products filter." });
}
}
34 changes: 34 additions & 0 deletions src/api/store/custom/getProducts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa";

export async function getProductsList(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const productService = req.scope.resolve("productService");
const { colors, styles, rooms} = req.query;

const colorsArray = typeof colors === 'string' ? colors.split(',').map((color: string) => color.trim().toLowerCase()) : Array.isArray(colors) ? colors : [];
const stylesArray = typeof styles === 'string' ? styles.split(',').map((style: string) => style.trim().toLowerCase()) : Array.isArray(styles) ? styles : [];
const roomsArray = typeof rooms === 'string' ? rooms.split(',').map((room: string) => room.trim().toLowerCase()) : Array.isArray(rooms) ? rooms : [];

try {
let products = await productService.list({}, { relations: ["variants"] });
if (colorsArray.length > 0 || stylesArray.length > 0 || roomsArray.length > 0) {
products = products.filter((product: any) => {
const variantTitles = product.variants.map((variant: any) => variant.title.toLowerCase());
let hasValidColor = colorsArray.length === 0;
let hasValidStyle = stylesArray.length === 0;
let hasValidRoom = roomsArray.length === 0;
if (colorsArray.length > 0) hasValidColor = colorsArray.some((color: any) => variantTitles.includes(color));
if (stylesArray.length > 0) hasValidStyle = stylesArray.some((style: any) => variantTitles.includes(style));
if (roomsArray.length > 0) hasValidRoom = roomsArray.some((room: any) => variantTitles.includes(room));

return hasValidColor && hasValidStyle && hasValidRoom;
});
}
res.status(200).json({ products });
} catch (error) {
console.log(error);
res.status(500).json({ error: "An error occurred while fetching products." });
}
}
4 changes: 2 additions & 2 deletions src/subscribers/invite-created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default async function handleInviteCreated({
const sendGridService = container.resolve("sendgridService")

sendGridService.sendEmail({
templateId: "send-invite",
from: "jose.garcia+threshold@vokal.io",
templateId: "d-3e6dc14ca2004c9f8984804255eddf96",
from: "jose.garcia+thresholddoors@vokal.io",
to: data.user_email,
dynamic_template_data: {
// any data necessary for your template...
Expand Down
Loading