From b59e652c9b6b80e9fc66f423006bfa9fdd61dfe2 Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Thu, 15 Jun 2023 12:16:26 +0300 Subject: [PATCH] handeling save product with pre save method and error handlers --- src/controllers/ProductController.ts | 2 +- src/schemas/productModel.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controllers/ProductController.ts b/src/controllers/ProductController.ts index 42e8e25..f08f515 100644 --- a/src/controllers/ProductController.ts +++ b/src/controllers/ProductController.ts @@ -1,5 +1,5 @@ import { Request, Response } from 'express'; -import { Product, IProduct } from '../schemas/productModel'; +import { Product } from '../schemas/productModel'; import { handleCreateProductError } from '../middlewares/errorHandlers'; diff --git a/src/schemas/productModel.ts b/src/schemas/productModel.ts index 00206b4..57cf79d 100644 --- a/src/schemas/productModel.ts +++ b/src/schemas/productModel.ts @@ -37,6 +37,7 @@ ProductSchema.pre('save', async function (next) { }); const Product = mongoose.model('Product', ProductSchema); + ProductSchema.index({ name: 1, userId: 1 }, { unique: true });