Skip to content

Commit

Permalink
Merge branch 'main' into nupath-sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
daisykucharski committed Feb 26, 2024
2 parents 9d70835 + cc101af commit fe090b4
Show file tree
Hide file tree
Showing 27 changed files with 931 additions and 234 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@
"dependencies": {
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.17.8",
"@nestjs/axios": "^3.0.2",
"@nestjs/terminus": "^10.2.2",
"@nestjs/throttler": "^5.0.1",
"cross-env": "^7.0.3",
"fuse.js": "^7.0.0",
"nodemailer": "^6.9.1"
},
"devDependencies": {
Expand Down
14 changes: 12 additions & 2 deletions packages/api-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ class SearchAPIClient {
searchCourses = async (
searchQuery: string,
catalogYear?: number,
nupath?: NUPathEnum[],
minIndex = 0,
maxIndex = 9999
): Promise<ScheduleCourse2<null>[]> => {
Expand All @@ -327,7 +328,13 @@ class SearchAPIClient {
/** Search courses from the latest terms to the older year terms. */
const allCourses = await Promise.all(
termsOrderedByYear.map((termId) =>
this.searchCoursesForTerm(searchQuery, termId, minIndex, maxIndex)
this.searchCoursesForTerm(
searchQuery,
termId,
nupath,
minIndex,
maxIndex
)
)
);

Expand All @@ -351,6 +358,7 @@ class SearchAPIClient {
private searchCoursesForTerm = async (
searchQuery: string,
termId: string,
nupath: NUPathEnum[] = [],
minIndex = 0,
maxIndex = 9999
): Promise<ScheduleCourse2<null>[]> => {
Expand All @@ -360,7 +368,9 @@ class SearchAPIClient {
data: JSON.stringify({
query: `
{
search(termId:"${termId}", query: "${searchQuery}", classIdRange: {min: ${minIndex}, max: ${maxIndex}}) {
search(termId:"${termId}", query: "${searchQuery}", classIdRange: {min: ${minIndex}, max: ${maxIndex}}${
nupath.length > 0 ? `, nupath: ${JSON.stringify(nupath)}` : ""
}) {
totalCount
pageInfo { hasNextPage }
nodes { ... on ClassOccurrence { name subject maxCredits minCredits prereqs coreqs nupath classId
Expand Down
24 changes: 23 additions & 1 deletion packages/api/src/meta/meta.controller.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
import { Controller, Get } from "@nestjs/common";
import {
HealthCheckService,
HttpHealthIndicator,
HealthCheck,
TypeOrmHealthIndicator,
HealthCheckResult,
} from "@nestjs/terminus";
import { MetaService } from "./meta.service";
import { type MetaInfo } from "@graduate/common";

@Controller("meta")
export class MetaController {
constructor(private readonly metaService: MetaService) {}
constructor(
private readonly metaService: MetaService,
private health: HealthCheckService,
private http: HttpHealthIndicator,
private db: TypeOrmHealthIndicator
) {}

@Get("/info")
getMetaInfo(): MetaInfo {
return this.metaService.getMetaInfo();
}

@Get("/health")
@HealthCheck()
async getHealthInfo(): Promise<HealthCheckResult> {
return await this.metaService.getHealthInfo(
this.health,
this.http,
this.db
);
}
}
3 changes: 3 additions & 0 deletions packages/api/src/meta/meta.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Module } from "@nestjs/common";
import { TerminusModule } from "@nestjs/terminus";
import { HttpModule } from "@nestjs/axios";
import { MetaService } from "./meta.service";
import { MetaController } from "./meta.controller";

@Module({
controllers: [MetaController],
providers: [MetaService],
imports: [HttpModule, TerminusModule],
exports: [MetaService],
})
export class MetaModule {}
18 changes: 18 additions & 0 deletions packages/api/src/meta/meta.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { type MetaInfo } from "@graduate/common";
import { Injectable } from "@nestjs/common";
import {
HealthCheckService,
HttpHealthIndicator,
TypeOrmHealthIndicator,
HealthCheckResult,
} from "@nestjs/terminus";

@Injectable()
export class MetaService {
Expand All @@ -14,4 +20,16 @@ export class MetaService {
environment: process.env.NODE_ENV ?? false,
};
}

getHealthInfo(
health: HealthCheckService,
http: HttpHealthIndicator,
db: TypeOrmHealthIndicator
): Promise<HealthCheckResult> {
return health.check([
() =>
http.pingCheck("graduate_api", "https://graduatenu.com/api/meta/info"),
() => db.pingCheck("database"),
]);
}
}
16 changes: 16 additions & 0 deletions packages/common/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,19 @@ export const isStrongPassword = (password: string): boolean => {
const containsLettersAndNumbersRegex = /^(?=.*[a-zA-Z])(?=.*[0-9])/;
return password.length >= 8 && containsLettersAndNumbersRegex.test(password);
};

/**
* Comparator function for sorting majors by name Criteria: ignores spacing and
* special characters when sorting
*/
export const majorNameComparator = (a: string, b: string) => {
const trimmedA = a
.replace(/[^A-Z0-9]/gi, "")
.trim()
.toLowerCase();
const trimmedB = b
.replace(/[^A-Z0-9]/gi, "")
.trim()
.toLowerCase();
return trimmedB.localeCompare(trimmedA);
};
Loading

0 comments on commit fe090b4

Please sign in to comment.