Created
September 25, 2017 20:15
-
-
Save Necromant1k/85dd6ec8bde35ada445abbe04b5f6d8c to your computer and use it in GitHub Desktop.
sda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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