Skip to content

Instantly share code, notes, and snippets.

@HyunGyu-Lee
Created December 2, 2019 06:46
Show Gist options
  • Save HyunGyu-Lee/a9940f734c4b79d286f7544f6c18c9af to your computer and use it in GitHub Desktop.
Save HyunGyu-Lee/a9940f734c4b79d286f7544f6c18c9af to your computer and use it in GitHub Desktop.
Firebase 모듈 초기화
import Vue from 'vue'
import { firestorePlugin } from 'vuefire'
import firebase from 'firebase/app'
import 'firebase/firestore'
Vue.use(firestorePlugin)
var firebaseConfig = {
apiKey: "AIzaSyDzqN-wqvAsZ41HVCTzHYqqpQ_cX1sWzYs",
authDomain: "daily-todo-backend.firebaseapp.com",
databaseURL: "https://daily-todo-backend.firebaseio.com",
projectId: "daily-todo-backend",
storageBucket: "daily-todo-backend.appspot.com",
messagingSenderId: "463694718444",
appId: "1:463694718444:web:ad39110d9f515feb218cc9",
measurementId: "G-JXJD1PDEB6"
};
// Initialize Firebase
const firebaseApp = firebase.initializeApp(firebaseConfig);
export default firebaseApp
import Vue from 'vue'
import firebaseApp from '@/modules/firebase'
import _ from 'lodash'
const firestore = firebaseApp.firestore();
const EventBus = new Vue()
const TODO_COLLECTION = 'todos'
export default {
EventBus,
getCollection() {
return firestore.collection(TODO_COLLECTION)
},
addTodo(todo) {
return this.getCollection().add(todo);
},
getTodos() {
return this.getCollection().orderBy('toFinishAt').get();
},
updateTodo(todoId, payload) {
return this.getCollection().doc(todoId).update(payload);
},
deleteTodo(todoId) {
return this.getCollection().doc(todoId).delete();
},
getSummary() {
return this.getCollection().get().then((snapshot) => {
let list = _.map(snapshot.docs, (doc) => doc.data());
return {
statusCounts: _.countBy(list, 'status')
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment