Sunday 29 September 2019

Controller that creates bank transaction with some rules

Hello, guys! I need to create a simulation of a bank transaction with a few specific rules.For example, if the type of the payment is done with a debit card, it must be charged a fee of 3.2%.For now I could not set up the rules in the controller yet. Could someone help me out? Here is how my current controller looks like:javascript async store(req, res) { const { type_transaction } = req.body; if (type_transaction === 'debit') { let { value } = req.body; return value += 32; // random value just to test if it'll be saved in the db } const transaction = await Transaction.create(req.body); return res.json(transaction); }With the method above, I'm able to change the value, but I'm not able to save the changed value to the DB. Like the image below:https://user-images.githubusercontent.com/16469917/65846188-54e9c100-e313-11e9-8fb5-6f0173dd514d.pngThis is how the Transaction Model looks like now:```javascript class Transaction extends Model { static init(sequelize) { super.init( { value: Sequelize.INTEGER, description: Sequelize.STRING, type_transaction: Sequelize.STRING, installments: Sequelize.INTEGER, }, { sequelize, }, );return this; // ... CONTINUES ``` Could anyone help me to solve this problem?

Submitted September 30, 2019 at 03:47AM by brainiac__

No comments:

Post a Comment