Skip to content

Instantly share code, notes, and snippets.

@alberpad
Created October 6, 2018 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alberpad/d84922e9817bfab777dce007f536a868 to your computer and use it in GitHub Desktop.
Save alberpad/d84922e9817bfab777dce007f536a868 to your computer and use it in GitHub Desktop.
functions/index.js
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