| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import {
- Product
- } from "../../../models/Product";
- import {
- AddProductResult
- } from "./types";
- const addProduct = async (body: any, context: { userID: string }): Promise<AddProductResult> => {
- try {
- const {
- coverPhotoPath,
- description,
- isAvailable,
- categoryID,
- isActive,
- price,
- title
- } = body;
- const {
- userID
- } = context;
- const newProduct = await Product.create({
- coverPhotoPath,
- userID: userID,
- description,
- isAvailable,
- categoryID,
- isActive,
- title,
- price
- });
- return {
- message: "product-created-successfully",
- code: 201,
- payload: {
- product: newProduct
- }
- };
- } catch (error) {
- console.error("AddProduct action error:", error);
- return {
- message: "internal-server-error",
- code: 500
- };
- }
- };
- export default addProduct;
|