首页 文章

成功执行所有删除操作后返回布尔值(true | false)

提问于
浏览
0

我正在使用Sequelize,GraphQL和Typescript来编写代码 . 我有两个表RecordInformation和OtherDescription . RecordInformation在OtherDescription表上有一个外键“OtherID” .

我的解析器文件中有两个代码 . 我可以在sequelize中使用cascade选项删除记录 .

但是,我想知道如何根据成功执行的每个操作更改此代码以返回true或false值 . 目前, Map 操作的返回类型是Bluebird <number> [] . 我想在删除变异后返回布尔值 .

interface IRecordInformation {
    id: number;
    RecordID: number;
    LabelOptionID: number;
    OtherID: number;
}

interface IListRecordInformation {
    RecordInformationList: IRecordInformation[];
}

deleteRecordInformation(_: null, args: IListRecordInformation) {
  const recordInformationList = args.RecordInformationList;
  return recordInformationList.map((recordInfo) => OtherDescription.destroy({
    where: { id: recordInfo.OtherID }
  }));
},

1 回答

  • 0

    您可以使用 Promise.all() 传递 recordInformationList 然后使用带链接 .then().every() 来检查返回的 Promise

    Promise.all(
      recordInformationList.map(recordInfo => 
        OtherDescription.destroy({
          where: { id: recordInfo.OtherID }
        })
      )
    )
    .then(values => values.every(n => n > 0))
    .then(bool => bool);
    

相关问题