검색 업로드

This commit is contained in:
익희 김 2025-01-23 03:41:56 +09:00
parent fa0562117d
commit f4f29e9a0b

View File

@ -5,6 +5,7 @@ const Brand = require('../models/Brand');
const SubCategory = require('../models/SubCategory');
const Search = async (req, res) => {
try {
const { query, shop, subCategory, category } = req.body;
const currenctShop = shop ? await Shop.findById(shop).select(['_id']) : '';
@ -17,7 +18,11 @@ const Search = async (req, res) => {
const products = await Products.aggregate([
{
$match: {
name: { $regex: query || '', $options: 'i' },
$or: [
{ name: { $regex: query || '', $options: 'i' } },
{ metaTitle: { $regex: query || '', $options: 'i' } },
{ description: { $regex: query || '', $options: 'i' } }
],
...(currenctShop && {
shop: currenctShop._id,
}),
@ -56,6 +61,8 @@ const Search = async (req, res) => {
slug: 1,
_id: 1,
category: 1, // Including the category field with only the title
metaTitle: 1,
description: 1,
},
},
@ -72,6 +79,8 @@ const Search = async (req, res) => {
return res.status(400).json({ success: false, message: error.message });
}
};
const getFilters = async (req, res) => {
try {
await SubCategory.findOne();