Skip to content

Instantly share code, notes, and snippets.

@jirawatee
Last active May 27, 2019 21:36
Show Gist options
  • Save jirawatee/110c96eb92cf6c6d35dac2001f9b7f6a to your computer and use it in GitHub Desktop.
Save jirawatee/110c96eb92cf6c6d35dac2001f9b7f6a to your computer and use it in GitHub Desktop.
Livescore in UCL by Cloud Firestore
exports.liveScore = functions.region(region).runWith(runtimeOpts)
.firestore.document('ucl/final')
.onWrite(async (change, context) => {
let latest = change.after.data().score; // ดึงค่าล่าสุดหลังจาก score อัพเดท
// ดึงข้อมูลผู้ใช้ที่ subscribe ทั้งหมด
let userIds = await admin.firestore().doc('ucl/final').collection('uid').get()
userIds.forEach(doc => {
push(doc.id, latest, null) // ส่งข้อความแจ้งผลบอล
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment