From 042b59bb791ebd8c514e734989cdf339e921a721 Mon Sep 17 00:00:00 2001 From: Michael Foiani Date: Fri, 6 Sep 2019 12:28:56 -0400 Subject: Added options to archive previous year's data --- src/actions/firebaseFirestore.js | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/actions') diff --git a/src/actions/firebaseFirestore.js b/src/actions/firebaseFirestore.js index 10e285a..c43a77f 100644 --- a/src/actions/firebaseFirestore.js +++ b/src/actions/firebaseFirestore.js @@ -228,3 +228,46 @@ export const createComment = (postId, content) => (dispatch, getState) => { } } +//TODO: Make it per year, not hard coded... + +export const archiveClass2019 = () => (dispatch, getState) => { + if(getState().app.offline) { + alert('Failed to archive class. Please establish internet connection.'); + } else { + var docRef = firestore.collection('users'); + docRef.get().then((oldUsers) => { + oldUsers.forEach((user) => { + var newPath = firestore.collection('archived').doc('2019').collection('users'); + newPath.doc(user.id).set(user.data()); + + if(user.data().username && user.data().username.includes('2019')) { + console.log(user.data().username, user.id); + docRef.doc(user.id).delete(); + } + + docRef.doc(user.id).update({hours: 0}); + + }); + }); + } +} + +export const archiveCompetitions2019 = () => (dispatch, getState) => { + if(getState().app.offline) { + alert('Failed to archive competitions. Please establish internet connection.'); + } else { + var docRef = firestore.collection('competitions'); + docRef.get().then((oldCompetitions) => { + oldCompetitions.forEach((comp) => { + console.log(comp.id, comp.data()); + var newPath = firestore.collection('archived').doc('2019').collection('competitions'); + newPath.doc(comp.id).set(comp.data()); + + //This will delete the document in its old place... + docRef.doc(comp.id).delete(); + + }); + }); + + } +} -- cgit v1.2.3-70-g09d2