require('dotenv').config();
module.exports = {


    friendlyName: 'Modify',


    description: 'Modify user.',


    inputs: {
        /*id:{
          type:'number',
          required: true
        },*/

        anneeScolaire: {
            type: 'string',
            require: true
        },

        logiUsername: {
            type: 'string',
            require: true

        },
        key: {
            type: 'string',
            require: true

        },
        logiPassword: {
            type: 'string',
            require: true

        },


    },


    exits: {
        notFound: {
            statusCode: 404
        },

    },


    fn: async function (inputs, exits) {

        // TOKEN VERIFY
        let user = await Utilisateurs.find({ login: inputs.logiUsername, codeUser: inputs.logiPassword }).then(_.first)
        if (!user) {
            return exits.notFound('Utilisateur non trouvé')
        }
        console.log("INPUTS 2", inputs)

        let keyVerify = process.env.KEYVERIFY
        //
        if (keyVerify !== inputs.key) {
            return exits.notFound({ message: "Token non valide" })
        }


        ///////////////////

        let annee = await AnneeScolaire.find({ anneeScolaire: inputs.anneeScolaire }).then(_.first)
        if (!annee) {
            return exits.notFound({ message: "Annee Scolaire non retrouvée!" })
        }

        let anneeUpdate = await AnneeScolaire.update({ id: annee.id }, inputs).fetch()

        // All done.
        return exits.success({
            ...anneeUpdate,
        });

    }

};
