handeling save product with pre save method and error handlers

This commit is contained in:
Kfir Dayan 2023-06-15 12:16:26 +03:00
parent 9cb00a1162
commit b59e652c9b
2 changed files with 2 additions and 1 deletions

View file

@ -1,5 +1,5 @@
import { Request, Response } from 'express'; import { Request, Response } from 'express';
import { Product, IProduct } from '../schemas/productModel'; import { Product } from '../schemas/productModel';
import { handleCreateProductError } from '../middlewares/errorHandlers'; import { handleCreateProductError } from '../middlewares/errorHandlers';

View file

@ -37,6 +37,7 @@ ProductSchema.pre('save', async function (next) {
}); });
const Product = mongoose.model<IProduct>('Product', ProductSchema); const Product = mongoose.model<IProduct>('Product', ProductSchema);
ProductSchema.index({ name: 1, userId: 1 }, { unique: true }); ProductSchema.index({ name: 1, userId: 1 }, { unique: true });