32 lines
894 B
JavaScript
32 lines
894 B
JavaScript
// applyLoan.js
|
|
|
|
const Scholarship = artifacts.require('Scholarship');
|
|
const { validateGPA, formatGPA } = require('../utils/GPAValidator');
|
|
|
|
module.exports = async function(callback) {
|
|
try {
|
|
const scholarship = await Scholarship.deployed();
|
|
|
|
// Example GPA value
|
|
const gpa = 3.5;
|
|
|
|
// Validate GPA
|
|
if (!validateGPA(gpa)) {
|
|
console.error("Invalid GPA.");
|
|
return;
|
|
}
|
|
|
|
const formattedGPA = formatGPA(gpa);
|
|
console.log(`Applying for a loan with GPA: ${formattedGPA}`);
|
|
|
|
// Call the applyForLoan function in the smart contract
|
|
await scholarship.applyForLoan(formattedGPA, { from: web3.eth.accounts[0] });
|
|
|
|
console.log("Loan application successful!");
|
|
callback();
|
|
} catch (error) {
|
|
console.error("Error applying for loan:", error);
|
|
callback(error);
|
|
}
|
|
};
|