Skip to content

Commit

Permalink
Return session and user info for Admin
Browse files Browse the repository at this point in the history
  • Loading branch information
mangledbottles committed Oct 25, 2021
1 parent afb2fa8 commit 4dfaa51
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/controller/Admin.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
'use strict';

import { Repository } from 'typeorm';
/* Import database configuration */
import { connect } from '../config/config';
import { COASTERS_NOT_FOUND, COASTERS_NOT_LINKED, COASTER_ACC_REVOKED } from '../config/messages';

/* Import entities */
import { Coasters } from '../entity/Coasters';
import { Session } from '../entity/Session';
import { Users } from '../entity/Users';

exports.updateCoaster = (coasterId, { encoded, group }) => {
return new Promise(async (resolve, reject) => {
Expand Down Expand Up @@ -50,10 +53,16 @@ exports.getCoaster = (coasterId: string) => {
return new Promise(async (resolve, reject) => {
try {
const connection = await connect();
const repo = connection.getRepository(Coasters);

let [coaster] = await repo.find({ where: { coasterId } });
resolve(coaster);
const coasterRepo = connection.getRepository(Coasters);
const sessionRepo = connection.getRepository(Session);
const usersRepo = connection.getRepository(Users);

let [coaster] = await coasterRepo.find({ where: { coasterId } });
let [session] = await sessionRepo.find({ where: { userId: coaster.userId, active: true } });
let [user] = await usersRepo.find({ where: { userId: coaster.userId }});
let { userId, email, displayName, createdAt } = user;

resolve({ coaster, session, user: { userId, email, displayName, createdAt } });
} catch (error) {
reject(error);
}
Expand Down

0 comments on commit 4dfaa51

Please sign in to comment.