I've been working on a project that involves sequelize(MySQL DB).
So I have a table "InterestRate" that takes id's from two other tables(foreign keys).
bankId is stored in "Banks" table and interId is stored in another table called "Interest".
Now I want to populate this table with Postman by sending this data:
{
"bank": "BankName",
"inter": "Interest",
"nks": "4.11",
"eks": "6.24",
"time": "36"
}
BUT I want to populate table with the primary keys of these values(if existed in their own table). E.g When I send to postman I want to check table "Banks" and search "BankName" grab its id in that table, and put it in new table. Same thing for this inter thing.
Code that I have rn is trash, I know why it doesn't work but I'm really stuck.
(req, res) => {
const bank = req.body.bank;
const type = req.body.type;
const nks = req.body.nks;
const eks = req.body.eks;
const time = req.body.time;
InterestRate.create({
bankId: bank,
interId: type,
NKS: nks,
EKS: eks,
time: time,
})
.then(() => {
res.status(200).json({ message: 'Added successfully' });
})
.catch((err) => {
res.status(500).send('Error -> ' + err);
});
};
Note that all models etc. are set up correctly, it works if I enter things manually!
Thank you!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…