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


    friendlyName: 'Find',


    description: 'Find note.',


    inputs: {

        codMoy: {
            type: 'string',
            required: true
        },

        codeEcole: {
            type: 'string',
            required: true
        },
        anneeScolaire: {
            type: 'string',
            required: true
        },

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

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

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

        },

    },


    exits: {
        encryptionError: {
            statusCode: 500
        },
        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 note = await ProfNote.find({ codMoy: inputs.codMoy, codeEcole: inputs.codeEcole, anneeScolaire: inputs.anneeScolaire }).then(_.first)
        if (!note) {
            return exits.notFound({ message: "La Note n'existe pas" })
        }
        await ProfNote.update({ codMoy: note.codMoy }, { etatNote: 'OUI' });

        return exits.success({ message: 'Note mise à jour !' })

    }

    // All done. 

};
