소스 검색

Feature: Refactor product-related actions and controllers for improved structure and clarity

emrecevik106 1 개월 전
부모
커밋
20acc5f193

+ 3 - 3
src/actions/menu/addProduct/index.ts

@@ -13,8 +13,8 @@ const addProduct = async (body: any, context: { userID: string }): Promise<AddPr
             isAvailable,
             categoryID,
             isActive,
-            title,
             price,
+            title
         } = body;
 
         const {
@@ -23,13 +23,13 @@ const addProduct = async (body: any, context: { userID: string }): Promise<AddPr
 
         const newProduct = await Product.create({
             coverPhotoPath,
+            userID: userID,
             description,
             isAvailable,
             categoryID,
             isActive,
             title,
-            price,
-            userID: userID,
+            price
         });
 
         return {

+ 1 - 0
src/actions/menu/getProducts/index.ts

@@ -12,6 +12,7 @@ const getProducts = async (query: GetProductsInput, context: { userID: string })
         const {
             userID
         } = context;
+        
         const {
             categoryID
         } = query;

+ 1 - 2
src/actions/menu/updateProduct/index.ts

@@ -16,7 +16,7 @@ const updateProduct = async (body: any, context: { userID: string }): Promise<Up
             productID,
             isActive,
             price,
-            title,
+            title
         } = body;
 
         const {
@@ -27,7 +27,6 @@ const updateProduct = async (body: any, context: { userID: string }): Promise<Up
         };
 
         if (categoryID !== undefined) updateData.categoryID = new mongoose.Types.ObjectId(categoryID);
-
         if (title !== undefined) updateData.title = title;
         if (description !== undefined) updateData.description = description;
         if (price !== undefined) updateData.price = price;

+ 5 - 1
src/controllers/menuController.ts

@@ -15,6 +15,7 @@ import {
     addProduct as _addProduct
 } from "../actions/menu";
 
+//#region Category Controllers
 export const addCategory = async (req: AuthRequest, res: Response): Promise<void> => {
     const result = await _addCategory(req.context!.userID, req.body);
 
@@ -57,7 +58,9 @@ export const getCategories = async (req: AuthRequest, res: Response): Promise<vo
             }),
         });
 };
+//#endregion
 
+//#region Product Controllers
 export const addProduct = async (req: AuthRequest, res: Response): Promise<void> => {
     const result = await _addProduct(req.body, req.context!);
 
@@ -108,4 +111,5 @@ export const deleteProduct = async (req: AuthRequest, res: Response): Promise<vo
                 payload: result.payload
             })
         });
-};
+};
+// #endregion

+ 4 - 5
src/models/Product.ts

@@ -2,16 +2,15 @@ import mongoose, {
     Document,
     Schema
 } from "mongoose";
-
 export interface IProduct extends Document {
     categoryID: mongoose.Types.ObjectId;
     userID: mongoose.Types.ObjectId;
-    title: string;
-    description: string;
-    price: number;
     coverPhotoPath: string;
-    isActive: boolean;
     isAvailable: boolean;
+    description: string;
+    isActive: boolean;
+    title: string;
+    price: number;
 }
 
 const productSchema = new Schema<IProduct>(