Skip to content

Instantly share code, notes, and snippets.

View nwaughachukwuma's full-sized avatar
🧶
Making stuff

Chukwuma Nwaugha nwaughachukwuma

🧶
Making stuff
View GitHub Profile
import firebase from 'react-native-firebase';
export const dynamicEventLink = async (id) => {
const link =
new firebase.links.DynamicLink(
encodeURI(`https://eventsmag.page.link/${id}`),
'eventsmag.page.link'
).android.setPackageName('app_android_package_name')
.ios.setBundleId('app_ios_bundle_id');
@nwaughachukwuma
nwaughachukwuma / rideCost.js
Last active September 1, 2019 11:43
Method showing ride fee algorithm
export async function calculateTripCost(from: Coords, to: Coords, numPassengers: number) {
try {
const res = await getDistanceAndDuration(from, to) // this is a google maps api for returning distance and duration
const { distance } = res
let { duration } = res
if (res.duration_in_traffic) {
duration = res.duration_in_traffic
}
@nwaughachukwuma
nwaughachukwuma / signIn.ts
Last active October 8, 2019 15:32
cloud function http request for user signin
/**
* User signIn Http Request
*/
import * as functions from 'firebase-functions';
import * as APIRequest from 'request'
import { admin } from '../admin' // project is initialized before importing
const signInwithTokenURL = 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=[API_KEY]'
const lookUpUserURL = 'https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=[API_Key]'
@nwaughachukwuma
nwaughachukwuma / userUpdated.ts
Last active October 8, 2019 10:35
user updated trigger
/**
* User updated trigger
*/
import * as functions from 'firebase-functions'
import { createStripeCustomer } from './stripe';
// listen for changes when user record is updated
export const userUpdatedTrigger = functions.firestore
.document('users/{userId}')
.onUpdate(async (change, context) => {
@nwaughachukwuma
nwaughachukwuma / stripe.ts
Last active September 29, 2021 18:21
Create stripe customer and store on user document
/**
* Create your stripe customer
*/
import * as functions from 'firebase-functions';
import { DocumentSnapshot } from "firebase-functions/lib/providers/firestore";
import * as Stripe from "stripe"
const secretKey = functions.config().stripe.key // ensure you have set the configuration
const stripe = new Stripe(secretKey)
**
* Prompt to write or update the Spreadsheet
* -----------------------------------------
* Detect an entry in a defined collection on the
* Firestore database. Listen for onCreate, onUpdate
* and onDelete
*/
export const writeToSheetTrigger = functions.firestore
.document('collectionName/{docId}')
.onWrite(async (change, context) => {
/**
* Logic for appending an Entry on the Spreadsheet
*/
interface Metadata {
theRange: string
theData: (number|string)[][]
}
export function appendEntry(sheetsAPI: any, spreadsheetId: string, auth: any, metadata: Metadata) {
return new Promise((resolve, reject) => {