mirror of
https://github.com/quepasaevents/qpa-client.git
synced 2023-12-14 05:33:02 +01:00
Get user by id
This commit is contained in:
parent
febe02016e
commit
3a17e6623a
|
@ -163,6 +163,25 @@ export default class Repository {
|
|||
})
|
||||
}
|
||||
|
||||
async getUserById(id: string, datastore?: Datastore | DatastoreTransaction): Promise<User> {
|
||||
const ds = (datastore || this.datastore)
|
||||
const key = this.datastore.key(['User', parseInt(id)])
|
||||
console.log('repository getUserById', id, key)
|
||||
|
||||
const result = await ds.get(key)
|
||||
|
||||
if (!result) {
|
||||
return null
|
||||
} else if (result.length > 1) {
|
||||
const message = `Got more than one even for the same queried id ${id}`
|
||||
throw new Error(message)
|
||||
}
|
||||
console.log('repository.getUserById succeeded with result', JSON.stringify(result));
|
||||
const user = result[0] as User
|
||||
user.id = user[Datastore.KEY].id
|
||||
return result[0] as User;
|
||||
}
|
||||
|
||||
async getEvent(id: string, datastore ?: Datastore | DatastoreTransaction): Promise<CalendarEvent> {
|
||||
const ds = (datastore || this.datastore)
|
||||
const key = this.datastore.key(['Event', parseInt(id)])
|
||||
|
|
|
@ -85,9 +85,7 @@ export default class SessionManager {
|
|||
if (sessionInvite.timeValidated) {
|
||||
return Promise.reject('Session request has already been validated')
|
||||
}
|
||||
const matchingUser: User = await this.repository.getUser({
|
||||
email: sessionRequest.email
|
||||
})
|
||||
const matchingUser: User = await this.repository.getUserById(sessionInvite.userId)
|
||||
if (matchingUser.id === sessionInvite.userId) {
|
||||
const session: Session = {
|
||||
userId: matchingUser.id,
|
||||
|
|
|
@ -83,6 +83,7 @@ const handleSignin = async (req: Request, res: Response) => {
|
|||
const ip = req.ip.split('.').map(num => parseInt(num))
|
||||
|
||||
console.log('Got sign in request with params', JSON.stringify(params))
|
||||
|
||||
const session: Session = await sessionManager.initiateSession({
|
||||
hash: params.hash as string,
|
||||
email: params.email as string,
|
||||
|
|
Loading…
Reference in a new issue