
// Display user sign in

const user = require("../../models/user")

exports.displayUserSignIn = (req, res) =>{
    res.render('owners/signin')
}

// Display Owner Dashboard

exports.displayDashboard = (req, res) => {
    if(req.isAuthenticated()){
        User.findOne({_id: req.user._id}).populate({
            path: 'transfertransactions'
        }).exec(function(err, founduser){
            if(err){
                console.log(err)
            }else{
                res.render('owners/home',{
                   owner: founduser 
                })
            }
        })
       
    }else{
        res.render('owners/signin')
    }
    
}

// Display Loans

exports.displayLoans = (req, res) => {
    if(req.isAuthenticated()){
        User.findOne({_id: req.user._id}).populate({
            path: 'loanrequests'
        }).exec(function(err, founduser){
            if(err){
                console.log(err)
            }else{
                res.render('owners/loanrequest',{
                   owner: founduser 
                })
            }
        })
    }else{
        res.render('owners/signin')
    }
    
}

// display transactions

exports.displaytransactions = (req, res) => {
    if(req.isAuthenticated()){
        User.findOne({_id: req.user._id}).populate({
            path: 'transfertransactions'
        }).exec(function(err, founduser){
            if(err){
                console.log(err)
            }else{
                res.render('owners/transactions',{
                   owner: founduser 
                })
            }
        })
    }else{
        res.render('owners/signin')
    }
   
}

// display transfer form

exports.displaytransfer = (req, res) =>{
    if(req.isAuthenticated()){
        User.findOne({_id: req.user._id}).populate({
            path: 'transfertransactions'
        }).exec(function(err, founduser){
            if(err){
                console.log(err)
            }else{
                res.render('owners/transfer',{
                   owner: founduser 
                })
            }
        })
       
    }else{
        res.render('owners/signin')
    }
   
}

// display card management

exports.displaycardmanagement = (req, res) => {
    if(req.isAuthenticated()){
        User.findOne({_id: req.user._id}).populate({
            path: 'cardtransactions'
        }).exec(function(err, founduser){
            if(err){
                console.log(err)
            }else{
                res.render('owners/cardmanagement',{
                   owner: founduser 
                })
            }
        })
       
    }else{
        res.render('owners/signin')
    }
    
}
// display profile

exports.displayprofilemanagement = (req, res) => {
    if(req.isAuthenticated()){
        User.findOne({_id: req.user._id}, function(err, founduser){
            if(err){
                console.log(err)
            }else{
                res.render('owners/profile',{
                   owner: founduser 
                })
            }
        })
       
    }else{
        res.render('owners/signin')
    }
    
}