Track lastUpdatedTime
This commit is contained in:
		
							parent
							
								
									3d96b11c6d
								
							
						
					
					
						commit
						c880e164f9
					
				| 
						 | 
				
			
			@ -20,6 +20,7 @@ export type FullContract<
 | 
			
		|||
  visibility: 'public' | 'unlisted'
 | 
			
		||||
 | 
			
		||||
  createdTime: number // Milliseconds since epoch
 | 
			
		||||
  lastUpdatedTime?: number // Updated on new bet or comment
 | 
			
		||||
  lastBetTime?: number
 | 
			
		||||
  lastCommentTime?: number
 | 
			
		||||
  closeTime?: number // When no more trading is allowed
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,9 +19,10 @@ export const onCreateBet = functions.firestore
 | 
			
		|||
      throw new Error('Could not find contract corresponding with bet')
 | 
			
		||||
 | 
			
		||||
    const bet = change.data() as Bet
 | 
			
		||||
    const lastBetTime = bet.createdTime
 | 
			
		||||
 | 
			
		||||
    await firestore
 | 
			
		||||
      .collection('contracts')
 | 
			
		||||
      .doc(contract.id)
 | 
			
		||||
      .update({ lastBetTime: bet.createdTime })
 | 
			
		||||
      .update({ lastBetTime, lastUpdatedTime: Date.now() })
 | 
			
		||||
  })
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,6 +22,7 @@ export const onCreateComment = functions.firestore
 | 
			
		|||
      throw new Error('Could not find contract corresponding with comment')
 | 
			
		||||
 | 
			
		||||
    const comment = change.data() as Comment
 | 
			
		||||
    const lastCommentTime = comment.createdTime
 | 
			
		||||
 | 
			
		||||
    const commentCreator = await getUser(comment.userId)
 | 
			
		||||
    if (!commentCreator) throw new Error('Could not find contract creator')
 | 
			
		||||
| 
						 | 
				
			
			@ -29,7 +30,7 @@ export const onCreateComment = functions.firestore
 | 
			
		|||
    await firestore
 | 
			
		||||
      .collection('contracts')
 | 
			
		||||
      .doc(contract.id)
 | 
			
		||||
      .update({ lastCommentTime: comment.createdTime })
 | 
			
		||||
      .update({ lastCommentTime, lastUpdatedTime: Date.now() })
 | 
			
		||||
 | 
			
		||||
    let bet: Bet | undefined
 | 
			
		||||
    let answer: Answer | undefined
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user