I can't change the enum status in electro.js

18 views Asked by At

I made a CRUD project with electron for desktop. I edit the data with findByIdAndUpdate. But now I need something else. When someone gets save, automatically everyone gets 11 digit code with a function.Also everyone has an enum as "onboard" and "ashore". Now I want to have an input, and when I put the 11 digit code, I want to change the status as reverse, if they are onboard, the button should made it ashore. If ashore, button should made it onboard. I get error of "Task not found" so which means couldn't find it in mongoose database.Here is the app.js code:

function updateStatusByCode(code) {
    ipcRenderer.send('update-status-by-code', code);
}




ipcRenderer.on('update-status-success', (event, updatedTask) => {
    console.log('Status updated:', updatedTask);
});

And main.js code:

ipcMain.on('update-status-by-code', async (event, code) => {
    try {
        const task = await Task.findOne({ code: code }).exec();
        if (!task) {
            console.error('Task not found');
            return;
        }

        
        task.status = task.status === 'onboard' ? 'ashore' : 'onboard';

     
        const updatedTask = await task.save();
        console.log('Status updated:', updatedTask);

        
        event.sender.send('update-status-success', updatedTask);
    } catch (err) {
        console.error(err);
    }
});

the database model:

const newTaskSchema = new Schema({
    name:{
        type:String,
        required:true
    },
    description:{
        type:String,
        required:true
    },
    code: {
      type: Number, // Varsayılan olarak bir tamsayı olarak saklayacağız.
      required: true
    },
    status: {
        type: String,
        enum: ["onboard", "ashore"], // Geçerli değerler sadece "onboard" veya "ashore" olabilir
        default: "onboard" // Varsayılan değer "onboard" olarak ayarlandı
    }
})

And HTML code:

  <form id="codeForm">
        <input type="text" id="taskCode" placeholder="11-Digit Code">
        <button type="button" onclick="updateStatusByCode()">Update Status</button>
    </form>

I get error of "Task not found" Why it can't find the code in database?

0

There are 0 answers