forked from OpenWF/SpaceNinjaServer
		
	chore: optimise getAccountIdForRequest (#814)
This commit is contained in:
		
							parent
							
								
									16c2b8f83c
								
							
						
					
					
						commit
						73df848f11
					
				@ -71,7 +71,21 @@ export const getAccountForRequest = async (req: Request): Promise<TAccountDocume
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const getAccountIdForRequest = async (req: Request): Promise<string> => {
 | 
					export const getAccountIdForRequest = async (req: Request): Promise<string> => {
 | 
				
			||||||
    return (await getAccountForRequest(req))._id.toString();
 | 
					    if (!req.query.accountId) {
 | 
				
			||||||
 | 
					        throw new Error("Request is missing accountId parameter");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (!req.query.nonce || parseInt(req.query.nonce as string) === 0) {
 | 
				
			||||||
 | 
					        throw new Error("Request is missing nonce parameter");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (
 | 
				
			||||||
 | 
					        !(await Account.exists({
 | 
				
			||||||
 | 
					            _id: req.query.accountId,
 | 
				
			||||||
 | 
					            Nonce: req.query.nonce
 | 
				
			||||||
 | 
					        }))
 | 
				
			||||||
 | 
					    ) {
 | 
				
			||||||
 | 
					        throw new Error("Invalid accountId-nonce pair");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return req.query.accountId as string;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const isAdministrator = (account: TAccountDocument): boolean => {
 | 
					export const isAdministrator = (account: TAccountDocument): boolean => {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user