Fix build error from merge. Extract resolution emails to function
This commit is contained in:
		
							parent
							
								
									5890b74225
								
							
						
					
					
						commit
						0950a281f2
					
				|  | @ -8,7 +8,7 @@ export const sendMarketResolutionEmail = async ( | ||||||
|   payout: number, |   payout: number, | ||||||
|   creator: User, |   creator: User, | ||||||
|   contract: Contract, |   contract: Contract, | ||||||
|   resolution: 'YES' | 'NO' | 'CANCEL' |   resolution: 'YES' | 'NO' | 'CANCEL' | 'MKT' | ||||||
| ) => { | ) => { | ||||||
|   const user = await getUser(userId) |   const user = await getUser(userId) | ||||||
|   if (!user) return |   if (!user) return | ||||||
|  | @ -32,4 +32,4 @@ https://mantic.markets/${creator.username}/${contract.slug} | ||||||
|   await sendEmail(user.email, subject, body) |   await sendEmail(user.email, subject, body) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const toDisplayResolution = { YES: 'YES', NO: 'NO', CANCEL: 'N/A' } | const toDisplayResolution = { YES: 'YES', NO: 'NO', CANCEL: 'N/A', MKT: 'MKT' } | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ export const resolveMarket = functions | ||||||
|   .https.onCall( |   .https.onCall( | ||||||
|     async ( |     async ( | ||||||
|       data: { |       data: { | ||||||
|         outcome: 'YES' | 'NO' | 'CANCEL' |         outcome: 'YES' | 'NO' | 'CANCEL' | 'MKT' | ||||||
|         contractId: string |         contractId: string | ||||||
|       }, |       }, | ||||||
|       context |       context | ||||||
|  | @ -82,9 +82,27 @@ export const resolveMarket = functions | ||||||
|         .catch((e) => ({ status: 'error', message: e })) |         .catch((e) => ({ status: 'error', message: e })) | ||||||
|         .then(() => ({ status: 'success' })) |         .then(() => ({ status: 'success' })) | ||||||
| 
 | 
 | ||||||
|       const activeBets = bets.filter((bet) => !bet.isSold && !bet.sale) |       await sendResolutionEmails( | ||||||
|  |         openBets, | ||||||
|  |         userPayouts, | ||||||
|  |         creator, | ||||||
|  |         contract, | ||||||
|  |         outcome | ||||||
|  |       ) | ||||||
|  | 
 | ||||||
|  |       return result | ||||||
|  |     } | ||||||
|  |   ) | ||||||
|  | 
 | ||||||
|  | const sendResolutionEmails = async ( | ||||||
|  |   openBets: Bet[], | ||||||
|  |   userPayouts: { [userId: string]: number }, | ||||||
|  |   creator: User, | ||||||
|  |   contract: Contract, | ||||||
|  |   outcome: 'YES' | 'NO' | 'CANCEL' | 'MKT' | ||||||
|  | ) => { | ||||||
|   const nonWinners = _.difference( |   const nonWinners = _.difference( | ||||||
|         _.uniq(activeBets.map(({ userId }) => userId)), |     _.uniq(openBets.map(({ userId }) => userId)), | ||||||
|     Object.keys(userPayouts) |     Object.keys(userPayouts) | ||||||
|   ) |   ) | ||||||
|   const emailPayouts = [ |   const emailPayouts = [ | ||||||
|  | @ -96,10 +114,7 @@ export const resolveMarket = functions | ||||||
|       sendMarketResolutionEmail(userId, payout, creator, contract, outcome) |       sendMarketResolutionEmail(userId, payout, creator, contract, outcome) | ||||||
|     ) |     ) | ||||||
|   ) |   ) | ||||||
| 
 | } | ||||||
|       return result |  | ||||||
|     } |  | ||||||
|   ) |  | ||||||
| 
 | 
 | ||||||
| const firestore = admin.firestore() | const firestore = admin.firestore() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user