|
|
@@ -12,7 +12,7 @@ const getProducts = async (query: GetProductsInput, context: { userID: string })
|
|
|
const {
|
|
|
userID
|
|
|
} = context;
|
|
|
-
|
|
|
+
|
|
|
const {
|
|
|
categoryID
|
|
|
} = query;
|
|
|
@@ -23,7 +23,7 @@ const getProducts = async (query: GetProductsInput, context: { userID: string })
|
|
|
|
|
|
if (categoryID) {
|
|
|
matchStage.categoryID = {
|
|
|
- $in: [new mongoose.Types.ObjectId(categoryID)]
|
|
|
+ $in: [new mongoose.Types.ObjectId(categoryID)]
|
|
|
};
|
|
|
}
|
|
|
|
|
|
@@ -36,7 +36,7 @@ const getProducts = async (query: GetProductsInput, context: { userID: string })
|
|
|
from: "categories",
|
|
|
localField: "categoryID",
|
|
|
foreignField: "_id",
|
|
|
- as: "categoryID"
|
|
|
+ as: "categoryIDs"
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
@@ -46,12 +46,19 @@ const getProducts = async (query: GetProductsInput, context: { userID: string })
|
|
|
}
|
|
|
]);
|
|
|
|
|
|
+ const payload = products.map((product) => {
|
|
|
+ return {
|
|
|
+ ...product,
|
|
|
+ categoryIDs: product.categoryID.map((cat: any) => {
|
|
|
+ return cat._id.toString();
|
|
|
+ })
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
return {
|
|
|
message: "products-retrieved-successfully",
|
|
|
- code: 200,
|
|
|
- payload: {
|
|
|
- products
|
|
|
- }
|
|
|
+ payload: payload,
|
|
|
+ code: 200
|
|
|
};
|
|
|
} catch (error) {
|
|
|
console.error("GetProducts action error:", error);
|