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

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

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

68c380c9ce344f9e11d8a181d329426d?s=128

DaikiOKA

August 21, 2019
Tweet

Transcript

  1. ͥͻ࢖ͬͯཉ͍͠ Cloud functions for Firebase

  2. Cloud functions for firebaseͱ͸ 'JSFCBTFͷϢʔβೝূɺσʔλϕʔεͷ௥ՃͳͲͷΠϕϯτ Λड͚औͬͯॲཧΛߦ͏αʔϏε ରԠݴޠɿ+BWB4DSJQUPS5ZQF4DSJQU 'JSFTUPSFτϦΨʔ w PO$SFBUF

    w PO6QEBUF w PO%FMFUF w PO8SJUF
  3. nori-naͰͷར༻ํ๏ • ϓογϡ௨஌ • σʔλͷूܭ • ֎෦αʔϏεͱͷ࿈ܞ(ܾࡁɺݕࡧ)

  4. ϓογϡ௨஌ 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, '૬৐Γґཔ͕ಧ͖·ͨ͠ɻ಺༰Λ֬ೝͯ͠ڐՄ͠·͠ΐ͏ɻ'); });
  5. ϓογϡ௨஌ 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; });
  6. ϩʔΧϧͰςετՄೳ $npm run shell

  7. ςετίʔυ 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͸ඞཁͳ࣌ͷ Έ
  8. Cloud Functionͷ৽ػೳ Scheduler export const cronRemindShare = functions.pubsub //.schedule("0 18

    * * *")//ຖ೔18࣌ʹ࣮ߦ .schedule("every 5 minutes")//̑෼͓͖ .timeZone("Asia/Tokyo") .onRun(async context => { console.log("͜͜Ͱఆظ࣮ߦ") });
  9. ͋Γ͕ͱ͏͍͟͝·ͨ͠

  10. OPSJOB 5FDI /JHIU