Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion user-registration-app/set-env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writeFile } from 'fs';
import {writeFile} from 'fs';

// Only overwrite environment.ts if nodejs environment variables have been provided (i.e. only if Vercel is building)
if ('PRODUCTION' in process.env) {
Expand All @@ -11,6 +11,7 @@ if ('PRODUCTION' in process.env) {
production: '${process.env.PRODUCTION}',
api_url: '${process.env.API_URL}',
api_v2_url: '${process.env.API_V2_URL}',
api_v3_url: '${process.env.API_V3_URL}',
firebase: {
apiKey: '${process.env.API_KEY}',
authDomain: '${process.env.AUTH_DOMAIN}',
Expand Down
1 change: 1 addition & 0 deletions user-registration-app/src/app/AppConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { environment } from '../environments/environment';
export class AppConstants {
public static API_BASE_URL: string = environment.api_url;
public static API_BASE_URL_V2: string = environment.api_v2_url;
public static API_BASE_URL_V3: string = environment.api_v3_url;
public static LOGIN_ENDPOINT = '/login';
public static REGISTER_ENDPOINT = '/register';
public static LIVE_ENDPOINT = '/live';
Expand Down
2 changes: 2 additions & 0 deletions user-registration-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { TruncatePipe } from './services/pipes/truncate.pipe';
import { MatExpansionModule } from '@angular/material/expansion';
import { MatIconModule } from '@angular/material/icon';
import { QRCodeModule } from 'angularx-qrcode';
import {ActiveEventsPipe} from "./services/pipes/active-events.pipe";
@NgModule({
declarations: [
AppComponent,
Expand All @@ -51,6 +52,7 @@ import { QRCodeModule } from 'angularx-qrcode';
RsvpComponent,
LiveWorkshopComponent,
TruncatePipe,
ActiveEventsPipe,
ScheduleViewComponent,
UserProfileViewComponent,
UserRegistrationViewComponent,
Expand Down
4 changes: 4 additions & 0 deletions user-registration-app/src/app/models/api-error-response-v3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface ApiErrorResponseV3 {
statusCode: number;
message: string;
}
32 changes: 32 additions & 0 deletions user-registration-app/src/app/models/event-v3-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {LocationModel} from './location-model';

export class EventV3Model {
public id: string;
public name: string;
public type: string;
public startTime: number;
public endTime: number;
public description: string;
public icon: string;
public location: LocationModel;
public wsPresenterNames: string;
public wsSkillLevel: string;
public wsRelevantSkills: string;
public wsUrls: string[];

static parseJSON(value: any) {
const event = new EventV3Model();
if ('location' in value) {
const location = new LocationModel();
event.location = Object.assign(location, value['location']);
}
return Object.assign(event, value);
}

static parseFromJSONArray(array: any[]): EventV3Model[] {
return array.map((value) => {
const event = new EventV3Model();
return Object.assign(event, value, { wsUrls: value.wsUrls });
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class ExtraCreditClassV3Model {
public id: number;
public name: string;

static parseJSON(value: any): ExtraCreditClassV3Model {
const model = new ExtraCreditClassV3Model();
return Object.assign(model, value);
}
}
25 changes: 25 additions & 0 deletions user-registration-app/src/app/models/hackathon-static-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {EventV3Model} from './event-v3-model';
import {SponsorV3Model} from './sponsor-v3-model';

export class HackathonStaticModel {
public id: string;
public name: string;
public startTime: number;
public endTime: number;
public active: boolean;
public events: EventV3Model[];
public sponsors: SponsorV3Model[];

static parseJSON(value: any): HackathonStaticModel {
const model = new HackathonStaticModel();
model.id = value['id'];
model.name = value['name'];
model.startTime = value['startTime'];
model.endTime = value['endTime'];
model.active = value['active'];
model.events = EventV3Model.parseFromJSONArray(value['events']);
model.sponsors = SponsorV3Model.parseJSONArray(value['sponsors']);

return model;
}
}
12 changes: 12 additions & 0 deletions user-registration-app/src/app/models/hackathon-v3-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export class HackathonV3Model {
public id: string;
public name: string;
public startTime: number;
public endTime: number;
public active: boolean;

static parseJSON(value: any): HackathonV3Model {
const model = new HackathonV3Model();
return Object.assign(model, value);
}
}
9 changes: 9 additions & 0 deletions user-registration-app/src/app/models/location-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class LocationModel {
public id: number;
public name: string;

static parseJSON(value: any) {
const location = new LocationModel();
return Object.assign(location, value);
}
}
24 changes: 24 additions & 0 deletions user-registration-app/src/app/models/sponsor-v3-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {SponsorModel} from './sponsor';

export class SponsorV3Model {
public id: number;
public name: string;
public darkLogo: string;
public lightLogo: string;
public level: string;
public order: number;
public link?: string;
public hackathonId: string;

static parseJSON(value: any): SponsorV3Model {
const model = new SponsorV3Model();
return Object.assign(model, value);
}

static parseJSONArray(array: any[]): SponsorV3Model[] {
return array.map((s) => {
const model = new SponsorModel();
return Object.assign(model, s);
})
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { catchError, mergeMap, retryWhen, shareReplay, switchMap, map, tap } from 'rxjs/operators';
import { Observable, throwError, timer } from 'rxjs';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { AuthService } from '../AuthService/auth.service';
import { CustomErrorHandlerService } from '../CustomErrorHandler/custom-error-handler.service';
import { NgProgress } from 'ngx-progressbar';
import { AppConstants } from '../../AppConstants';
import {catchError, map, mergeMap, retryWhen, shareReplay, switchMap, tap} from 'rxjs/operators';
import {Observable, throwError, timer} from 'rxjs';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {AuthService} from '../AuthService/auth.service';
import {CustomErrorHandlerService} from '../CustomErrorHandler/custom-error-handler.service';
import {NgProgress} from 'ngx-progressbar';
import {AppConstants} from '../../AppConstants';

export class BaseHttpService {
private readonly CACHE_SIZE = 3;
protected memCache: Map<string, Observable<any>>;

private genericRetryStrategy = ({
maxRetryAttempts = 3,
scalingDuration = 1000,
excludedStatusCodes = [],
}: {
maxRetryAttempts = 3,
scalingDuration = 1000,
excludedStatusCodes = [],
}: {
maxRetryAttempts?: number;
scalingDuration?: number;
excludedStatusCodes?: number[];
Expand Down Expand Up @@ -51,6 +51,7 @@ export class BaseHttpService {
ignoreCache?: boolean,
useAuth = true,
v2: boolean = false,
v3: boolean = false,
uid: string = '',
): Observable<T> {
if (ignoreCache) {
Expand All @@ -60,9 +61,14 @@ export class BaseHttpService {
// Set the value in the memory cache
let headers = new HttpHeaders();
let params = new HttpParams();
const fullUrl = v2
? AppConstants.API_BASE_URL_V2.concat(API_ENDPOINT)
: AppConstants.API_BASE_URL.concat(API_ENDPOINT);
let fullUrl = AppConstants.API_BASE_URL.concat(API_ENDPOINT);

if (v2) {
fullUrl = AppConstants.API_BASE_URL_V2.concat(API_ENDPOINT);
} else if (v3) {
fullUrl = AppConstants.API_BASE_URL_V3.concat(API_ENDPOINT);
}

if (ignoreCache) {
params = params.set('ignoreCache', 'true');
}
Expand All @@ -71,16 +77,17 @@ export class BaseHttpService {
}
let observable = useAuth
? // With authentication
this.authService.idToken.pipe(
switchMap((idToken: string) => {
headers = headers.set('idtoken', idToken);
return this.getInternal(fullUrl, headers, params);
}),
)
this.authService.idToken.pipe(
switchMap((idToken: string) => {
headers = headers.set('idtoken', idToken);
return this.getInternal(fullUrl, headers, params);
}),
)
: // Without authentication
this.getInternal(fullUrl, headers, params);
this.getInternal(fullUrl, headers, params);
observable = observable.pipe(
v2 ? map((apiResponse: any) => apiResponse.body.data) : tap(() => {}),
v2 ? map((apiResponse: any) => apiResponse.body.data) : tap(() => {
}),
catchError((err) => {
return v2
? this.errorHandler.handleV2HttpError(err)
Expand All @@ -98,25 +105,31 @@ export class BaseHttpService {
params?: HttpParams,
): Observable<T> {
return this.http
.get(fullUrl, { headers, params })
.get(fullUrl, {headers, params})
.pipe(shareReplay(this.CACHE_SIZE, 10 * 1000))
.pipe(
retryWhen(this.genericRetryStrategy({ excludedStatusCodes: [400, 401, 404, 409] })),
retryWhen(this.genericRetryStrategy({excludedStatusCodes: [400, 401, 404, 409]})),
) as Observable<T>;
}

protected post(API_ENDPOINT: string, formObject: FormData | any, v2: boolean = false) {
protected post(API_ENDPOINT: string, formObject: FormData | any, v2: boolean = false, v3: boolean = false) {
this.memCache.set(API_ENDPOINT, null);
return this.authService.idToken.pipe(
switchMap((idToken: string) => {
let headers = new HttpHeaders();
let fullUrl = AppConstants.API_BASE_URL.concat(API_ENDPOINT);
headers = headers.set('idtoken', idToken);

if (v2) {
fullUrl = AppConstants.API_BASE_URL_V2.concat(API_ENDPOINT);
} else if (v3) {
fullUrl = AppConstants.API_BASE_URL_V3.concat(API_ENDPOINT);
}

return this.http.post(
v2
? AppConstants.API_BASE_URL_V2.concat(API_ENDPOINT)
: AppConstants.API_BASE_URL.concat(API_ENDPOINT),
fullUrl,
formObject,
{ headers, reportProgress: true },
{headers, reportProgress: true},
);
}),
catchError((err) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Error } from '../../models/interfaces';
import { ToastrService } from 'ngx-toastr';
import { Observable, throwError } from 'rxjs';
import { IApiResponse } from '../../models/api-response.v2';
import {ApiErrorResponseV3} from '../../models/api-error-response-v3';

@Injectable()
export class CustomErrorHandlerService {
Expand Down Expand Up @@ -91,4 +92,9 @@ export class CustomErrorHandlerService {
// this.toastrService.error(error.message);
return throwError(error);
}

handleV3HttpError(err: { error: ApiErrorResponseV3 }) {
console.error(err);
return throwError(err);
}
}
19 changes: 17 additions & 2 deletions user-registration-app/src/app/services/HttpService/HttpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ProjectModel } from '../../models/project-model';
import { ExtraCreditClass } from '../../models/extra-credit-class';
import { UserExtraCreditApiResponse } from '../../models/user-extra-credit';
import { SponsorModel } from '../../models/sponsor';
import {HackathonStaticModel} from '../../models/hackathon-static-model';

@Injectable()
export class HttpService extends BaseHttpService {
Expand Down Expand Up @@ -117,8 +118,22 @@ export class HttpService extends BaseHttpService {
return this.get(API_ENDPOINT).pipe(map(Rsvp.parseJSON));
}

getActiveHackathon() {
return this
.get(
'/hackathons/active/static',
false,
false,
false,
true,
)
.pipe(
map(HackathonStaticModel.parseJSON),
);
}

getEvents() {
const API_ENDPOINT = 'live/events';
const API_ENDPOINT = '/events';
return this.get(API_ENDPOINT, false, false, true).pipe(map(EventModel.parseFromJSONArray));
}

Expand All @@ -137,7 +152,7 @@ export class HttpService extends BaseHttpService {

getExtraCreditClassesForUser(uid: string) {
const API_ENDPOINT = 'users/extra-credit/assignment?type=user';
return this.get(API_ENDPOINT, true, true, true, uid).pipe(
return this.get(API_ENDPOINT, true, true, true, false, uid).pipe(
map((classes: any[]) => classes.map((c) => UserExtraCreditApiResponse.parseJSON(c))),
);
}
Expand Down
11 changes: 11 additions & 0 deletions user-registration-app/src/app/services/pipes/active-events.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Pipe, PipeTransform} from '@angular/core';
import {EventV3Model} from '../../models/event-v3-model';

@Pipe({
name: 'filterActive',
})
export class ActiveEventsPipe implements PipeTransform {
transform(value: EventV3Model[]): EventV3Model[] {
return value.filter((e) => e.endTime >= Date.now());
}
}
Loading