This is my first post here so please be gentle. I am using Sequelize w/ PostgresDB in Node and trying to search for a contact by email using findOrCreate. The email entry is in JSON format (see structure below)...
I want to find a contact by email and iterate over each email address in the JSON array for each contact entry.
I am passing in an email address and a name in the POST payload.
If I cannot find the contact by email I want to create a new contact (this part is easy).
router.post('/gmail/fetchcontact', function (req, res, next){
Contacts.findOrCreate({
where: {
email: // this is where I am stuck. How do I access this array and loop over?
},
defaults: {
name: req.body.name //
}
})
.then(response => {
if (response[1] === true) {
console.log('RESPONSE!!!', response[1])
}
})
// THIS IS THE STRUCTURE OF THE JSON I AM LOOKING TO ITERATE OVER
[{
address: '[email protected]',
primary: true,
rel: 'http://schemas.google.com/g/2005#home'
},{
address: '[email protected]',
primary: false,
labels: ['work'],
},{
address: '[email protected]',
primary: false,
labels: ['play'],
}]
Any ideas? Any help would be greatly appreciated. Thanks!