Created
October 6, 2018 19:17
-
-
Save alberpad/d84922e9817bfab777dce007f536a868 to your computer and use it in GitHub Desktop.
functions/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require('firebase-functions'); | |
const admin = require('firebase-admin'); | |
admin.initializeApp(); | |
exports.newOrder = functions.firestore | |
.document('orders/{orderId}') | |
.onCreate((snap, context)=> { | |
const order = snap.data(); | |
return admin.firestore().collection('orders').doc(order.oid).get().then(snap => { | |
return admin.firestore().collection('messages').doc(order.oid).set( | |
{log: `Nuevo pedido realizado con ID ${order.oid}, coste total: ${snap.data().totalCost} €`} | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment