|
@@ -9,12 +9,12 @@ import {
|
|
|
const updateProduct = async (body: any, context: { userID: string }): Promise<UpdateProductResult> => {
|
|
const updateProduct = async (body: any, context: { userID: string }): Promise<UpdateProductResult> => {
|
|
|
try {
|
|
try {
|
|
|
const {
|
|
const {
|
|
|
- coverPhotoPath,
|
|
|
|
|
description,
|
|
description,
|
|
|
isAvailable,
|
|
isAvailable,
|
|
|
categoryID,
|
|
categoryID,
|
|
|
productID,
|
|
productID,
|
|
|
isActive,
|
|
isActive,
|
|
|
|
|
+ photos,
|
|
|
price,
|
|
price,
|
|
|
title
|
|
title
|
|
|
} = body;
|
|
} = body;
|
|
@@ -26,11 +26,13 @@ const updateProduct = async (body: any, context: { userID: string }): Promise<Up
|
|
|
const updateData: any = {
|
|
const updateData: any = {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- if (categoryID !== undefined) updateData.categoryID = new mongoose.Types.ObjectId(categoryID);
|
|
|
|
|
|
|
+ if (categoryID !== undefined) updateData.categoryID = Array.isArray(categoryID)
|
|
|
|
|
+ ? categoryID
|
|
|
|
|
+ : [categoryID];
|
|
|
if (title !== undefined) updateData.title = title;
|
|
if (title !== undefined) updateData.title = title;
|
|
|
if (description !== undefined) updateData.description = description;
|
|
if (description !== undefined) updateData.description = description;
|
|
|
if (price !== undefined) updateData.price = price;
|
|
if (price !== undefined) updateData.price = price;
|
|
|
- if (coverPhotoPath !== undefined) updateData.coverPhotoPath = coverPhotoPath;
|
|
|
|
|
|
|
+ if (photos !== undefined) updateData.photos = photos;
|
|
|
if (isActive !== undefined) updateData.isActive = isActive;
|
|
if (isActive !== undefined) updateData.isActive = isActive;
|
|
|
if (isAvailable !== undefined) updateData.isAvailable = isAvailable;
|
|
if (isAvailable !== undefined) updateData.isAvailable = isAvailable;
|
|
|
|
|
|
|
@@ -67,21 +69,6 @@ const updateProduct = async (body: any, context: { userID: string }): Promise<Up
|
|
|
foreignField: "_id",
|
|
foreignField: "_id",
|
|
|
as: "categoryID"
|
|
as: "categoryID"
|
|
|
}
|
|
}
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- $unwind: {
|
|
|
|
|
- path: "$categoryID",
|
|
|
|
|
- preserveNullAndEmptyArrays: true
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- $addFields: {
|
|
|
|
|
- categoryID: {
|
|
|
|
|
- _id: "$categoryID._id",
|
|
|
|
|
- title: "$categoryID.title",
|
|
|
|
|
- isActive: "$categoryID.isActive"
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
]);
|
|
]);
|
|
|
|
|
|