mike-works/web-security-fundamentals

Missing Account.findById

wtlin1228 opened this issue ยท 3 comments

There is no Account.findById in the /server/models/account.js.
So I can't transfer money between accounts.

Transfer works after I added the following code.

Account.findById = function (accountId) {
  return Account.findOne({
    where: { id: accountId },
    attributes: ['id', 'userId', 'name', 'number', 'balance']
  }).then(account => {
    if (!account) throw new Error("No account found");
    return account;
  })
}

Maybe it's caused by upgrading sequelize to 5.21.7 from 5.21.6 in this commit.

d608cbb

Thanks for that @wtlin1228 !
I just ran into the same issue and this fixed it ๐Ÿ‘

If anyone is still having issues with this, you can replace findById with findByPk. I also recommend using Node version 8.17.0 with this course.