feat : admin feature
This commit is contained in:
40
src/services/admin.auth.service.js
Normal file
40
src/services/admin.auth.service.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const db = require('../config/db');
|
||||
const { comparePassword, hashPassword } = require('../util/hash');
|
||||
const axios = require('axios');
|
||||
|
||||
async function findAdminByUserName(customerNo) {
|
||||
const result = await db.query('SELECT * FROM admin WHERE username = $1', [
|
||||
customerNo,
|
||||
]);
|
||||
return result.rows[0];
|
||||
}
|
||||
|
||||
async function validateAdmin(customerNo, password) {
|
||||
const user = await findAdminByUserName(customerNo);
|
||||
if (!user) return null;
|
||||
const isMatch = await comparePassword(password, user.password);
|
||||
return isMatch ? user : null;
|
||||
}
|
||||
|
||||
async function getCustomerDetails(customerNo) {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
'http://localhost:8686/kccb/cbs/custInfo/details',
|
||||
{ params: { stcustno: customerNo } }
|
||||
);
|
||||
const details = response.data;
|
||||
const processedDetails = details.map((acc) => ({
|
||||
...acc,
|
||||
activeAccounts: details.length,
|
||||
cifNumber: customerNo,
|
||||
}));
|
||||
return processedDetails;
|
||||
} catch (error) {
|
||||
logger.error('while fetching customer details', error);
|
||||
throw new Error(
|
||||
'API call failed: ' + (error.response?.data?.message || error.message)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { validateAdmin, findAdminByUserName,getCustomerDetails };
|
||||
Reference in New Issue
Block a user