Skip to content

Instantly share code, notes, and snippets.

@emmsdan
Last active April 14, 2019 15:26
Show Gist options
  • Select an option

  • Save emmsdan/5852f864e0894cb26101aec84fe35a31 to your computer and use it in GitHub Desktop.

Select an option

Save emmsdan/5852f864e0894cb26101aec84fe35a31 to your computer and use it in GitHub Desktop.
//tables
define async createTag(tags, articleid):
# schema tags = [{ tagid, tagname }]
// articles { articleid ....}
// article_tag { tagid, articleid }
try {
// Result is whatever you returned inside the transaction
let result = await sequelize.transaction( async (t) => {
// step 1
tags.forEach(tag => {
Tags.findOrCreate({ tagname: tag });
article_tag({Tags.tagid, articleid});
}
});
console.log(result);
} catch (err) {
console.log(err);
}
return {
status: success || error,
message: ''
};
end define;
# use case
call createdTagStatus = await createTag(['tech', 'agric', 'finance'], 'bgt4ref3y56657-546trg454-45g56tr45');
if (!createdTagStatus.status) {
return createdTagStatus.message;
}
return true;
# end use case;
define updateTag(tags, articleid):
end define;
define deleteTag(tag, articleid):
call deletedTag = article_tags.destroy({ where: { id: articleid, tagname: tag } });
if (deletedTag > 0) {
return true;
}
return false;
end define;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment