update['/user-posts/' + uid + '/' + postId + '/lastNotificationTimestamp'] = firebase.database.ServerValue.TIMESTAMP; firebase.database().ref().update(update);
function update(id, data) { return Model.child(id).once('value').then((snapshot) =>{ if(snapshot.val()){ Model.child(id).update(data); return utils.makeResponse(200,null) } else { return utils.makeResponse(404,null,"Not Found") } }).catch(function(error) { return utils.makeResponse(500, null, error.message) }); }
app.put('/:id', (req: any, res: any, next: any) => { admin.database().ref('/contacts/' + req.params.id).update({ firstname: req.body.firstname, lastname: req.body.lastname, phone: req.body.phone, email: req.body.email }) res.send(req.body) next() })
// settings app.post('/api/updateSettings', authenticate, needsVerifiedAcc, (req, res) => { // get user reference in database const settingsRef = db.ref(`users/${req.body.uid}/settings`); // update settings settingsRef.update(req.body.updatedSettings); // send response back to user res.status(200).json({ success: true, message: 'Successfully updated settings' }); });
app.patch('/api/v1/address/:key', function(request, response){ if ((request.params || {}).key){ addressRef.child((request.params || {}).key).update(request.body); addressRef.child((request.params || {}).key).once('value').then(function(snapshot) { response.send({data: snapshot.val()}); }, function (errorObject) { console.log("The read failed: " + errorObject.code); response.send(errorObject); }); } });
functions.database.ref('/users/{userId}').onWrite((event) => { console.log('Making Full Name for UserID:', event.params.userId); // Get the first and last names const firstName = event.data._newData.firstName || ''; const lastName = event.data._newData.lastName || ''; const userData = { fullName: `${firstName} ${lastName}`, }; // Add Role if it doesn't already exist if (event && event.data && event.data._data && !event.data._newData.role) { userData.role = 'user'; } return event.data.ref.update(userData); })
admin.auth().getUser(phone) .then(() => { const ref = admin.database().ref('users/' + phone); ref.on('value', snapshot => { ref.off(); const user = snapshot.val(); if (user.code !== code || !user.codeValid) { return res.status(422).send({ error: 'Code not valid' }); } ref.update({ codeValid: false }); admin.auth().createCustomToken(phone) .then(token => res.send({ token: token })); }); }) .catch((err) => res.status(422).send({ error: err }))
firebaseAdmin.database().ref(DATABASE_DATA_KEY).update(questions).catch(function (error) { console.error(error); });
// get data for an collection of rooms app.post('/api/updateRoomInvite', authenticate, async (req, res) => { // get ref to room by id const roomInviteRef = db.ref(`rooms/${req.body.roomID}/invite`); // generate a new invitation link const newInvitation = generateInvitationLink(req.body.roomID); await roomInviteRef.update({ ...newInvitation }); // send back response with updated invitation link res.status(200).json({ success: true, message: 'Successfully updated room invite link', newInvitation }); });
admin.auth().getUser(phone) .then(userRecord => { const code = Math.floor(Math.random() * 8999 + 1000); twilio.messages.create({ body: 'Your code is ' + code, to: phone, from: '13312534741' }, (err) => { if (err) { return res.status(422).send(err); } admin.database().ref('users/' + phone) .update({ code: code, codeValid: true }, () => { res.send({ success: true }); }); }); return true; }) .catch((err) => { res.status(422).send({ error: err }); });
admin.auth().getUser(phone) .then(() => { const ref = admin.database().ref('users/' + phone); ref.on('value', snapshot => { ref.off(); const user = snapshot.val(); if (user.code !== code || !user.codeValid) { return res.status(422).send({ error: 'Code not valid' }); } ref.update({ codeValid: false }); admin.auth().createCustomToken(phone) .then(token => res.send({ token: token })) .catch(() => res.status(422).send({ error: err })) }); return null; }) .catch(() => res.status(422).send({ error: err }))
update['/user-posts/' + uid + '/' + postId + '/lastNotificationTimestamp'] = firebase.database.ServerValue.TIMESTAMP; firebase.database().ref().update(update);
app.put('/:id', (req: any, res: any, next: any) => { admin.database().ref('/contacts/' + req.params.id).update({ firstname: req.body.firstname, lastname: req.body.lastname, phone: req.body.phone, email: req.body.email }) res.send(req.body) next() })
app.put('/:id', function (req, res, next) { admin.database().ref('/contacts/' + req.params.id).update({ firstname: req.body.firstname, lastname: req.body.lastname, phone: req.body.phone, email: req.body.email }); res.send(req.body); next(); });
function update(id, data) { return Model.child(id).once('value').then((snapshot) =>{ if(snapshot.val()){ Model.child(id).update(data); return utils.makeResponse(200,null) } else { return utils.makeResponse(404,null,"Not Found") } }).catch(function(error) { return utils.makeResponse(500, null, error.message) }); }