Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ぜひ使って欲しいCloud Functions for Firebase

DaikiOKA
August 21, 2019

ぜひ使って欲しいCloud Functions for Firebase

DaikiOKA

August 21, 2019
Tweet

More Decks by DaikiOKA

Other Decks in Programming

Transcript

  1. ϓογϡ௨஌ onCreate export const pushRideshareRequest = functions.firestore .document(commonUtil.makePath('ridesharerequest/{requestId}')) .onCreate((snap, context)

    => { const newValue = new firestoreModels.RideShareRequest(snap.data()); const to = newValue.to; console.log(`push start ridesharerequest : ${context.params.requestId}`); return pushMessageByUserId(to, '૬৐Γґཔ͕ಧ͖·ͨ͠ɻ಺༰Λ֬ೝͯ͠ڐՄ͠·͠ΐ͏ɻ'); });
  2. ϓογϡ௨஌ onUpdate export const pushLikeComment = functions.firestore .document(commonUtil.makePath('mapcomment/{mapcommentId}')) .onUpdate((change, context)

    => { const afterData = new firestoreModels.MapComment(change.after.data()); const afterLike = afterData.likeMembers.length; const beforeData = new firestoreModels.MapComment(change.before.data()); const beforeLike = beforeData.likeMembers.length; const toUserId = afterData.user; if (!toUserId) return null; if (beforeLike < afterLike) { return pushMessageByUserId(toUserId, '͍͍Ͷ͕ԡ͞Ε·ͨ͠ʂ'); } return null; });
  3. ςετίʔυ QVTI%FTUJOBUJPO6QEBUF  \ CFGPSF\ TDSFFO/BNFVTF  MPDBUJPO\ MBUJUVEF 

    MPOHJUVEF ^  EFTUJOBUJPO\ OBNF5  HFP-PDBUJPO\ MBUJUVEF  MPOHJUVEF ^ ^ ^  BGUFS\ TDSFFO/BNFVTFS  MPDBUJPO\ MBUJUVEF  MPOHJUVEF ^  EFTUJOBUJPO\ OBNF5PLZP5PXFS  HFP-PDBUJPO\ MBUJUVEF  MPOHJUVEF ^ ^ ^ ^  \ QBSBNT\ VTFS*EVTFS ^ ^  • beforeͱafterʹͦΕͧ ΕσʔλΛهड़ • params͸ඞཁͳ࣌ͷ Έ
  4. Cloud Functionͷ৽ػೳ Scheduler export const cronRemindShare = functions.pubsub //.schedule("0 18

    * * *")//ຖ೔18࣌ʹ࣮ߦ .schedule("every 5 minutes")//̑෼͓͖ .timeZone("Asia/Tokyo") .onRun(async context => { console.log("͜͜Ͱఆظ࣮ߦ") });