Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const createNotifications = ({
users,
activityType,
sender,
content,
ids = {},
}) => {
const db = database();
let updates = {};
users.forEach(user => {
try {
const { key } = db.ref().child(`notifications/${user}`).push();
updates[`notifications/${user}/${key}`] = {
activityType,
id: key,
ids,
sender,
content,
timestamp: database.ServerValue.TIMESTAMP,
read: false,
};
} catch (err) {
// Ignore if sending a notification to a single user fails
console.log(err);
const getFrequencyBySlug = slug => {
const db = database();
return db
.ref(`frequencies`)
.orderByChild('slug')
.equalTo(slug)
.once('value')
.then(snapshot => {
const frequencies = snapshot.val();
// We assume there is only one frequency with a given slug
return frequencies[Object.keys(frequencies)[0]];
});
};
export const saveProviderUid = (user: Object) => {
const db = database();
const updates = {};
updates[`users/${user.uid}/providerUID`] = user.providerData[0].uid;
return db.ref().update(updates).then(() => {});
};
export const createDraft = ({
user: { displayName, photoURL, uid },
frequencyId,
}: createDraftProps) => {
const db = database();
const ref = db.ref().child('stories').push();
return ref
.set({
id: ref.key,
published: false,
timestamp: database.ServerValue.TIMESTAMP,
frequencyId,
creator: {
displayName,
photoURL,
uid,
},
messages: {},
})
export const getMessage = (
type: MessageTypes,
key: string
): GetMessageReturn => {
const db = database();
return db
.ref(`${type}/${key}`)
.once('value')
.then(snapshot => snapshot.val());
};
import Rebase from 're-base';
import firebase from 'firebase/app';
import database from 'firebase/database';
const app = firebase.initializeApp({
apiKey: 'AIzaSyCz1sOB93i4OFudhJdfVflL_bVy_fhZiLs',
authDomain: 'time-table-generator-separate.firebaseapp.com',
databaseURL: 'https://time-table-generator-separate.firebaseio.com',
});
export default Rebase.createClass(database(app));
componentWillReceiveProps(nextProps) {
if (nextProps.otherUserId && nextProps.chatURL) {
this.firebaseRef = database().ref(`chats/${nextProps.chatURL}/messages`);
if (typeof this.firebaseRefs["chats"] === "undefined") {
this.bindAsArray(this.firebaseRef, "chats");
}
}
}
constructor(props) {
super(props);
this.firebaseDB = database();
this.currentChat = null;
this.timeoutRef = null;
this.userInput = null;
this.chatMessageRef = null;
autoBind(this);
}
const getCommunityBySlug = slug => {
const db = database();
return db
.ref(`communities`)
.orderByChild('slug')
.equalTo(slug)
.once('value')
.then(snapshot => {
const results = snapshot.val();
return results[Object.keys(results)[0]];
});
};
export const getMessageGroups = uid => {
const db = database();
return db
.ref(`/users/${uid}/messageGroups`)
.once('value')
.then(snapshot => snapshot.val());
};