Skip to content

Instantly share code, notes, and snippets.

@Necromant1k
Created September 25, 2017 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Necromant1k/85dd6ec8bde35ada445abbe04b5f6d8c to your computer and use it in GitHub Desktop.
Save Necromant1k/85dd6ec8bde35ada445abbe04b5f6d8c to your computer and use it in GitHub Desktop.
sda
defaultTags.map(async tag => {
const transaction = await Model.sequelize.transaction()
try {
const categoryTags = await CategoryTags.findById(req.params.catId, {transaction})
await categoryTags.destroy({where: req.params.catId})
await transaction.commit()
} catch (err) {
await transaction.rollback()
}
try {
await CategoryTags.findOrCreate({
where: {
categoryId: category.id,
tagId: tag.id
},
defaults: {
categoryId: category.id,
tagId: tag.id
},
transaction
})
await transaction.commit()
} catch (err) {
await transaction.rollback()
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment