let express = require('express')
let router = express.Router()
const auth = require('../lib/auth')
var Recaptcha = require('express-recaptcha').RecaptchaV3;
const Errors = require('../lib/errors')
let {
    User
} = require('../models')
let {
    StaffApplications
} = require('../models')

router.post('/', auth, async(req, res, next) => {
    try {
        throw Errors.noLongerHiring
        if(!req.userData.username) {
            throw Errors.requestNotAuthorized
        }
        let user = await User.findOne({ where: {
                username: req.userData.username
            }})
        let userParams = {
            username: req.userData.username,
            dob: req.autosan.body.dob,
            email: user.email,
            whyWork: req.autosan.body.whyWork,
            otherForm: req.autosan.body.otherForm,
            experience: req.autosan.body.experience,
            suggestions: req.autosan.body.suggestions,
            selectedOption: req.autosan.body.selectedOption,
        }
        await StaffApplications.create(userParams)
        res.json({ success: true })
    } catch (e) { next(e) }
})

module.exports = router;
