Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TyHil committed Jan 27, 2024
1 parent d1ca1a5 commit 4127c57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/data/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { RMPRatingInterface } from '~data/interfaces';
export const HEADERS = {
Authorization: 'Basic dGVzdDp0ZXN0',
'User-Agent':
Expand Down
32 changes: 16 additions & 16 deletions src/data/fetchFromRmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ function getProfessorIds(texts: string[], professorNames: string[]): string[] {
let pendingMatch = null;
const regex =
/"legacyId":(\d+).*?"numRatings":(\d+).*?"firstName":"(.*?)","lastName":"(.*?)"/g;
let allMatches: string[] = text.match(regex);
let highestNumRatings = 0;
const allMatches: string[] = text.match(regex);
const highestNumRatings = 0;

if (allMatches) {
for (const fullMatch of allMatches) {
Expand All @@ -41,7 +41,7 @@ function getProfessorIds(texts: string[], professorNames: string[]): string[] {
match[4].toLowerCase() +
' ',
);
let numRatings = parseInt(match[2]);
const numRatings = parseInt(match[2]);
if (
lowerCaseProfessorNames.includes(
match[3].split(' ')[0].toLowerCase() +
Expand Down Expand Up @@ -86,7 +86,7 @@ function wait(delay) {

function fetchRetry(url: string, delay: number, tries: number, fetchOptions) {
function onError(err) {
let triesLeft: number = tries - 1;
const triesLeft: number = tries - 1;
if (!triesLeft) {
throw err;
}
Expand All @@ -98,11 +98,11 @@ function fetchRetry(url: string, delay: number, tries: number, fetchOptions) {
}

// If using orderedFetchOpts, make sure that it is an array and that the index of the fetch options corresponds to the index of the response in the responses array.
async function validateResponses(responses: any[], orderedFetchOpts: any[]) {
async function validateResponses(responses, orderedFetchOpts) {
for (const [key, value] of Object.entries(responses)) {
let notOk = value?.status !== 200;
const notOk = value?.status !== 200;
if (notOk && value && value.url) {
let details = {
const details = {
status: value.status,
statusText: value.statusText,
redirected: value.redirected,
Expand All @@ -113,28 +113,28 @@ async function validateResponses(responses: any[], orderedFetchOpts: any[]) {
'Status not OK for fetch request. Details are: ' +
JSON.stringify(details),
);
let fetchOptions = orderedFetchOpts[key] || {}; // If we don't have fetch options, we just use an empty object.
const fetchOptions = orderedFetchOpts[key] || {}; // If we don't have fetch options, we just use an empty object.
responses[key] = await fetchRetry(value?.url, 200, 3, fetchOptions);
}
}
return responses;
}

export async function fetchWithGraphQl(graphQlUrlProps: any[]) {
export async function fetchWithGraphQl(graphQlUrlProps) {
try {
let responses = await validateResponses(
const responses = await validateResponses(
await Promise.all(graphQlUrlProps.map((u) => fetch(RMP_GRAPHQL_URL, u))),
graphQlUrlProps,
);
// We now have all the responses. So, we consider all the responses, and collect the ratings.
let ratings: RMPRatingInterface[] = await Promise.all(
const ratings: RMPRatingInterface[] = await Promise.all(
responses.map((res) => res.json()),
);
for (let i = 0; i < ratings.length; i++) {
if (
ratings[i] != null &&
ratings[i].hasOwnProperty('data') &&
ratings[i]['data'].hasOwnProperty('node')
Object.prototype.hasOwnProperty.call(ratings[i], 'data') &&
Object.prototype.hasOwnProperty.call(ratings[i]['data'], 'node')
) {
ratings[i] = ratings[i]['data']['node'];
}
Expand Down Expand Up @@ -162,19 +162,19 @@ export async function requestProfessorsFromRmp(

// fetch professor ids from each url
try {
let responses = await validateResponses(
const responses = await validateResponses(
await Promise.all(professorUrls.map((u) => fetch(u))),
[],
);

let texts = await Promise.all(responses.map((res) => res.text()));
const texts = await Promise.all(responses.map((res) => res.text()));
const professorIds = getProfessorIds(texts, request.professorNames);

// create fetch objects for each professor id
const graphQlUrlProps = getGraphQlUrlProps(professorIds);

// fetch professor info by id with graphQL
let professors = await fetchWithGraphQl(graphQlUrlProps);
const professors = await fetchWithGraphQl(graphQlUrlProps);
return professors;
} catch (error) {
reportError('requestProfessorsFromRmp', error);
Expand Down

0 comments on commit 4127c57

Please sign in to comment.