我已经在updateBrand函数中更新了品牌详细信息。更新详细信息时,我已经检查了姓名的重复情况,但未检查相同的ID。
(即)从“品牌”中选择*,其中brand_name = $ brand_name AND id <> $ bid;
在我写的nodejs中
let duplicateData = await Brand.findOne({ where:searchQuery});
请告诉我们如何在nodejs sequelize查询中使用“ <>”(不等于)。
brandcontroller.js
updateBrand: async (request, h) => {
try {
let bid = request.query.id;
let searchQuery = {};
searchQuery.id = bid;
let {
brand_name,
brand_image,
description,
colorshead,
colorsbg,
brand_id,
status,
activedate,
expirydate,
} = request.payload;
///check name already exists
searchQuery.brand_name = brand_name;
let duplicateData = await Brand.findOne({ where: searchQuery });
if (!duplicateData) {
let updateBrand = await Brand.update(
{
brand_name: brand_name,
brand_image: brand_image,
colorshead: colorshead,
colorsbg: colorsbg,
brand_id: brand_id,
},
{
where: {
id: bid,
},
},
);
let response = {
statusCode: 200,
message: message.DATAFOUND,
};
return h.response(response).code(200);
} else {
return Boom.badRequest(message.NAMEEXISTS);
}
} catch (err) {
return Boom.badRequest(err.message);
}
},