Answer the question
In order to leave comments, you need to log in
How to update information in the database?
Is it correct to do such updates of information in the project? Or is it better to somehow do everything through 1 request, without error control?
async updateProduct(id, productData) {
const product = await Product.findById(id);
if (!product) {
throw new Error(PRODUCT_NOT_FOUND);
}
if (await this.checkProductExist(productData, id)) {
throw new Error(PRODUCT_ALREADY_EXIST);
}
const model = await modelService.getModelById(productData.model)
productData.model = model.name;
return Product.findByIdAndUpdate(id, productData, { new: true });
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question