handeling save product with pre save method and error handlers
This commit is contained in:
parent
9cb00a1162
commit
b59e652c9b
2 changed files with 2 additions and 1 deletions
|
@ -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';
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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 });
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue