how to accept req.params that contain multiple id ? I want to search and delete the multiple id
here's my code :
const id = req.params;
const masterFunders = await masterFunder.findOne({
where: {
id: ids
}
})
if (!masterFunders) {
return res.API.error(RESPONSE_MESSAGE.file_not_found, 400)
}
if (masterFunders.createdAt.getTime() > new Date().getTime() - (1000 * 60 * 60 * 24 * 10 * 3)) {
return res.API.error(RESPONSE_MESSAGE.cannot_delete_file, 400)
}
await masterFunder.destroy({
where: { id: ids }
});
return res.API.success(RESPONSE_MESSAGE.success, 200)
} catch (error) {
console.log(error)
return res.API.error(error.message)
it's error
{
"status": false,
"message": "Invalid value {\n id: '[de7cc75d-4925-4a8d-869c-9072c7310fc9, b9da8552-e3f9-4628-a5a2-9709399b20dc]'\n}",
"meta": {}
}
"ids" seems to be a string that contains an array in JSON format, not a JavaScript array.
So you need to do: ids = JSON.parse(ids); to convert the string to a JavaScript array :)