nodejs将条件ID note等于哪里可以检入

时间:2018-10-09 06:18:54

标签: node.js sequelize.js

我已经在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);
  }
},

1 个答案:

答案 0 :(得分:1)

您可以将$ne用于<>

where: {
    id: { $ne : bid },
}

更多 Data from Api