Skip to content

Commit

Permalink
feat(firebase): save congregation person list as blob in firestore
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Feb 26, 2023
1 parent add102c commit db113b1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/classes/Congregation.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ Congregation.prototype.loadDetails = async function () {
this.cong_name = congSnap.data().cong_name;
this.cong_number = congSnap.data().cong_number;
this.last_backup = congSnap.data().last_backup;
this.cong_persons = congSnap.data().cong_persons || '';
this.cong_persons = '';
if (congSnap.data().cong_persons) {
const resultStr = congSnap.data().cong_persons.toString();
this.cong_persons = resultStr;
}
this.cong_sourceMaterial = congSnap.data().cong_sourceMaterial || [];
this.cong_schedule = congSnap.data().cong_schedule || [];
this.cong_sourceMaterial_draft = congSnap.data().cong_sourceMaterial_draft || [];
Expand Down Expand Up @@ -217,13 +221,15 @@ Congregation.prototype.saveBackup = async function (
}
}

if (oldPerson.id) delete oldPerson.id;
finalPersons.push(oldPerson);
});

// handle new person record
cong_persons.forEach((newPerson) => {
const oldPerson = decryptedPersons.find((person) => person.person_uid === newPerson.person_uid);
if (!oldPerson) {
if (newPerson.id) delete newPerson.id;
finalPersons.push(newPerson);
}
});
Expand Down Expand Up @@ -345,8 +351,10 @@ Congregation.prototype.saveBackup = async function (

const userInfo = users.findUserByAuthUid(uid);

const buffer = Buffer.from(encryptedPersons, 'utf-8');

const data = {
cong_persons: encryptedPersons,
cong_persons: buffer,
cong_schedule_draft: finalSchedule,
cong_sourceMaterial_draft: this.cong_sourceMaterial_draft,
cong_swsPocket: cong_swsPocket,
Expand Down

0 comments on commit db113b1

Please sign in to comment.