I've created an API in nodejs + express => update user API where data comes in body
router.patch('/profile', verifyAuth, updateProfile);
In updateProfile using const reqData = req.body
I'm updating the reqData in user modal
data such as:
{
firstName: string,
lastName: string,
gender: string,
dateOfBirth: Date,
email: string,
phone: string,
}
Here phone number is my unique key so, I don't want anyone to update phone and there are many other keys as well.
Therefore I want to capture only fields which I want to update in req.body for update profile API.
Is there a way to specify request modal for APIs in express nodejs? If someone add any other keys in request it will be neglected in req.body
I think it will help you:) To skip the update of th phone number, you just have to skip the key "phone" in the dictionnary.
Have a nice day.
function checkProfile(item){ return { firstName: item.firstName, lastName: item.lastName, gender: item.gender, dateOfBirth: item.dateOfBirth, email: item.email, phone: item.phone, } } const rawProfile = { firstName: "string", lastName: "string", gender: "string", dateOfBirth: new Date(), email: "string", phone: "string", additionalValue1:"xxxxxx", additionalValue2:"xxxxxx", additionalValue3:"xxxxxx", } console.log(checkProfile(rawProfile))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.