Skip to content

Commit

Permalink
fix: always getting server version of document
Browse files Browse the repository at this point in the history
  • Loading branch information
benfurber committed Jul 15, 2024
1 parent 1b08f98 commit 91f7c02
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/stores/Discussions/discussionEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const updateDiscussionMetadata = async (
case 'research':
const researchRef = db.collection(collectionName).doc(primaryContentId)

const research = toJS(await researchRef.get()) as IResearch.Item
const research = toJS(await researchRef.get('server')) as IResearch.Item

if (research) {
// This approach is open to error but is better than making lots of DBs
Expand Down
4 changes: 2 additions & 2 deletions src/stores/Howto/howto.store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export class HowtoStore extends ModuleStore {
}
})

const $doc = await dbRef.get()
const $doc = await dbRef.get('server')
return $doc ? $doc : null
}

Expand Down Expand Up @@ -285,7 +285,7 @@ export class HowtoStore extends ModuleStore {
.doc((values as IHowtoDB)._id)
const id = dbRef.id

const existingDoc = await dbRef.get()
const existingDoc = await dbRef.get('server')
logger.debug('uploadHowto.existingDoc', { existingDoc })

const user = this.activeUser as IUser
Expand Down
2 changes: 1 addition & 1 deletion src/stores/Question/question.store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class QuestionStore extends ModuleStore {

logger.info(`upsertQuestion.set`, { dbRef })

return dbRef.get() || null
return dbRef.get('server') || null
}

public async toggleSubscriberStatusByUserName() {
Expand Down
6 changes: 3 additions & 3 deletions src/stores/Research/research.store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class ResearchStore extends ModuleStore {
.collection<IResearch.Item>(COLLECTION_NAME)
.doc(values._id)
const user = this.activeUser as IUser
const updates = (await dbRef.get())?.updates || [] // save old updates when editing
const updates = (await dbRef.get('server'))?.updates || [] // save old updates when editing
const collaborators = await this._setCollaborators(values.collaborators)

try {
Expand Down Expand Up @@ -365,7 +365,7 @@ export class ResearchStore extends ModuleStore {
await this._updateResearchItem(dbRef, newItem, true)
logger.debug('populate db ok')
this.updateUpdateUploadStatus('Database')
const createdItem = (await dbRef.get()) as IResearch.ItemDB
const createdItem = (await dbRef.get('server')) as IResearch.ItemDB
runInAction(() => {
this.activeResearchItem = createdItem
})
Expand Down Expand Up @@ -710,7 +710,7 @@ export class ResearchStore extends ModuleStore {
)
}

return await dbRef.get()
return await dbRef.get('server')
}

private async _getResearchItemBySlug(
Expand Down
2 changes: 1 addition & 1 deletion src/stores/Research/researchEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const setCollaboratorPermission = async (
userId: string,
) => {
const userRef = db.collection<IUserDB>('users').doc(userId)
const user = toJS(await userRef.get())
const user = toJS(await userRef.get('server'))
const role = 'research_creator' as UserRole.RESEARCH_CREATOR

if (!user) return
Expand Down
2 changes: 1 addition & 1 deletion src/stores/common/toggleDocSubscriberStatusByUserName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ export const toggleDocSubscriberStatusByUserName = async (

await dbRef.update(subscribersUpdated as any)

return await dbRef.get()
return await dbRef.get('server')
}
2 changes: 1 addition & 1 deletion src/stores/databaseV2/DocReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class DocReference<T> {
*/
async delete() {
const { serverDB, serverCacheDB } = this.clients
const doc = (await this.get()) as any
const doc = (await this.get('server')) as any
await serverDB.setDoc(`_archived/${this.endpoint}/summary`, {
_archived: new Date().toISOString(),
_id: this.id,
Expand Down

0 comments on commit 91f7c02

Please sign in to comment.