Skip to content

Commit

Permalink
mpi service updates
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-krenz committed Nov 19, 2024
1 parent 5ab8ef2 commit 9f47358
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 12 deletions.
15 changes: 15 additions & 0 deletions src/mpi/mpi.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,19 @@ export class MPIController {
): Promise<number | undefined> {
return this.mpiService.createELabsExperiment(bearerToken, studyID, name, status, templateID, autoCollaborate);
}

@Get('aclid/screens')
async getAclidScreenings(): Promise<JSON> {

Check warning on line 63 in src/mpi/mpi.controller.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
return this.mpiService.getAclidScreenings();

Check warning on line 64 in src/mpi/mpi.controller.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 65 in src/mpi/mpi.controller.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

@Get('aclid/screen/:id')
async getAclidScreening(id: string): Promise<JSON> {

Check warning on line 68 in src/mpi/mpi.controller.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
return this.mpiService.getAclidScreening(id);

Check warning on line 69 in src/mpi/mpi.controller.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 70 in src/mpi/mpi.controller.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

@Post('aclid/run-screening')
async createAclidScreening(@Body('submissionName') submissionName: string, @Body('sequences') sequences: JSON): Promise<JSON> {

Check warning on line 73 in src/mpi/mpi.controller.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
return this.mpiService.runAclidScreening(submissionName, sequences);

Check warning on line 74 in src/mpi/mpi.controller.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 75 in src/mpi/mpi.controller.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 76 in src/mpi/mpi.controller.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 76 in src/mpi/mpi.controller.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
66 changes: 54 additions & 12 deletions src/mpi/mpi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,21 @@ type eLabsStatus = 'PENDING' | 'PROGRESS' | 'COMPLETED';
export class MPIService {
private tokenStore = new Map<string, { accessToken: string; refreshToken: string; accessTokenExpiration: Date }>();

// TODO: put this in an env file.
private client_id = 'tZSXM9f8WUiPIpNGt1kXlGqzZVYvWNEF'; // Auth0 Damp Canvas app client ID
private client_secret = 'uHw3eZ4XrYcBW1zJJqWt1dbLC6YuwCT-v0AeXa1npLuhiEkw-Ayq1wwDcw3FSgnh'; // Auth0 Damp Canvas app client secret

// TODO: this should be the actual user id, got from DAMP LAB auth?
private currentUserId = 'mpitest';

// To log in use:
// NOTE THAT THIS SERVER IS RUNNING ON PORT 5100
// https://mpi-dev.us.auth0.com/authorize?response_type=code&scope=offline_access&client_id=tZSXM9f8WUiPIpNGt1kXlGqzZVYvWNEF&redirect_uri=http://127.0.0.1:5100/mpi/auth0_redirect&audience=https://mpi.com
// https://mpi-demo.us.auth0.com/authorize?response_type=code&scope=offline_access&client_id=tZSXM9f8WUiPIpNGt1kXlGqzZVYvWNEF&redirect_uri=http://127.0.0.1:5100/mpi/auth0_redirect&audience=https://mpi-demo.com
// To log out use:
// https://mpi-dev.us.auth0.com/oidc/logout?post_logout_redirect_uri=http://127.0.0.1:5100/mpi/auth0_logout&client_id=tZSXM9f8WUiPIpNGt1kXlGqzZVYvWNEF
// https://mpi-demo.us.auth0.com/oidc/logout?post_logout_redirect_uri=http://127.0.0.1:5100/mpi/auth0_logout&client_id=tZSXM9f8WUiPIpNGt1kXlGqzZVYvWNEF

async exchangeCodeForToken(code: string): Promise<string> {
const tokenUrl = `https://mpi-dev.us.auth0.com/oauth/token`;
const tokenUrl = `https://mpi-demo.us.auth0.com/oauth/token`;

Check warning on line 45 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const payload = {
grant_type: 'authorization_code',
client_id: this.client_id,
client_secret: this.client_secret,
client_id: process.env.MPI_CLIENT_ID,
client_secret: process.env.MPI_CLIENT_SECRET,
code,
redirect_uri: 'http://127.0.0.1:5100/mpi/auth0_redirect' // URL in this server that was used to redirect to after Auth0 login
};

Check warning on line 52 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
Expand Down Expand Up @@ -78,11 +74,11 @@ export class MPIService {
async exchangeRefreshTokenForToken(): Promise<void> {
const refreshToken = this.tokenStore.get(this.currentUserId)!.refreshToken;

const tokenUrl = `https://mpi-dev.us.auth0.com/oauth/token`;
const tokenUrl = `https://mpi-demo.us.auth0.com/oauth/token`;

Check warning on line 77 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const payload = {
grant_type: 'refresh_token',
client_id: this.client_id,
client_secret: this.client_secret,
client_id: process.env.MPI_CLIENT_ID,
client_secret: process.env.MPI_CLIENT_SECRET,
refresh_token: refreshToken
};

Check warning on line 83 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Expand Down Expand Up @@ -258,4 +254,50 @@ export class MPIService {
return undefined;
}
}

// aclid
async getAclidScreenings(): Promise<any> {

Check warning on line 259 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const token = await this.getAccessToken();

Check warning on line 260 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
if (!token) {
return new BadRequestException('No token found, log in to MPI first');

Check warning on line 262 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 263 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 263 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
const aclid = await axios.get('http://localhost:5000/aclid/screens', {
headers: {
Authorization: `Bearer ${token}`
}
});

Check warning on line 268 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
return aclid.data;

Check warning on line 269 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

async getAclidScreening(id: string): Promise<any> {

Check warning on line 272 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const token = await this.getAccessToken();

Check warning on line 273 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
if (!token) {
return new BadRequestException('No token found, log in to MPI first');

Check warning on line 275 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 276 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 276 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
const aclid = await axios.get(`http://localhost:5000/aclid/screens/${id}/details`, {
headers: {
Authorization: `Bearer ${token}`
}
});

Check warning on line 281 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
return aclid.data;

Check warning on line 282 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

async runAclidScreening(submissionName: string, sequences: JSON): Promise<any> {

Check warning on line 285 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
// sequences: [{name: string, sequence: string}]
const token = await this.getAccessToken();

Check warning on line 287 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
if (!token) {
return new BadRequestException('No token found, log in to MPI first');

Check warning on line 289 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 290 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 290 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
const aclid = await axios.post(
'http://localhost:5000/aclid/screen',
{ submissionName, sequences },
{
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json'
}
}

Check warning on line 299 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
);
return aclid.data;

Check warning on line 301 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}
}

Check warning on line 303 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 303 in src/mpi/mpi.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

0 comments on commit 9f47358

Please sign in to comment.