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


    friendlyName: 'Find',


    description: 'Find Commande.',


    inputs: {
        /*etatNote: {
            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.count({ codMoy: inputs.codMoy, etatNote: inputs.etatNote, codeEcole: inputs.codeEcole, anneeScolaire: inputs.anneeScolaire })
        console.log(note)
        return exits.success(note);

    }

    // All done. 

};
