我需要使用一些特定规则来模拟银行交易。例如,如果使用借记卡付款,则必须支付3.2%的费用。
现在我还不能在控制器中设置规则。有人可以帮我吗? 这是我当前的控制器的外观:
class TransactionController {
async store(req, res) {
const { type_transaction } = req.body;
if (type_transaction === 'debit') {
const value = value - 32 / 10;
}
const transaction = await Transaction.create(req.body);
return res.json(transaction);
}
}
这是交易模型:
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
}
答案 0 :(得分:0)
在这种情况下,我们需要像下面的代码一样从Besides no version, or a specific one, it is also possible to use logical operators:
'> 0.1' Any version higher than 0.1
'>= 0.1' Version 0.1 and any higher version
'< 0.1' Any version lower than 0.1
'<= 0.1' Version 0.1 and any lower version
In addition to the logic operators CocoaPods has an optimistic operator ~>:
'~> 0.1.2' Version 0.1.2 and the versions up to 0.2, not including 0.2 and higher
'~> 0.1' Version 0.1 and the versions up to 1.0, not including 1.0 and higher
'~> 0' Version 0 and higher, this is basically the same as not having it.
To use the master branch of the repo:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git'
To use a different branch of the repo:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'dev'
To use a tag of the repo:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :tag => '3.1.1'
Or specify a commit:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :commit => '0f506b1c45'
获取值:
req.body