#functions

10 messages · Page 1 of 1 (latest)

bronze bridge

TypeError: updateUserHistory is not a function

past estuaryBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
viral pike

the error literally says it all right there

bronze bridge

const history = require("../database/history")
async function updateUserHistory(memberId, action, moderatorId, reason) {
try {
const exuser = await history.findOne({ userId: memberId });

    if (exuser) {
        exuser.history.push({
            action: action,
            moderatorId: moderatorId,
            reason: reason,
            timestamp: new Date()
        });
        await exuser.save();
    } else {
        const newUser = new history({
            userId: memberId,
            history: [{
                action: action,
                moderatorId: moderatorId,
                reason: reason,
                timestamp: new Date()
            }]
        });
        await newUser.save();
    }
} catch (error) {
    console.error('Fout bij het bijwerken van de gebruikersgeschiedenis:', error);
    throw error; // Opnieuw gooien zodat de aanroepende functie dit kan afhandelen
}

}

// Exporteer de updateUserHistory functie
module.exports = updateUserHistory ;

viral pike

you're attempting to call a function which doesn't exist

bronze bridge

THis is the function

viral pike

module.exports needs to be an object afaik

bronze bridge

{}?

viral pike

also show the file in which you're calling it

viral pike