Skip to content

Commit

Permalink
refact: Change payloads to match new API requests and responses
Browse files Browse the repository at this point in the history
  • Loading branch information
PMax5 committed Jan 18, 2024
1 parent 120f458 commit 834a7ef
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/app/admin/links/complete-company-info.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class CompleteCompanyInfoPipe implements PipeTransform {

if (event === undefined) { return result; }

const participation = Participation.getFromEvent(complete[index].participations, event);
const participation = Participation.getFromEvent(complete[index].participation, event);

if (participation) {
result.currentParticipation = participation;
Expand Down
2 changes: 1 addition & 1 deletion src/app/admin/links/link/companies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Companies {
newCompany.currentParticipation =
company.currentParticipation
? company.currentParticipation
: Participation.getFromEdition(company.participations, filtered[0].edition);
: Participation.getFromEdition(company.participation, filtered[0].edition);
newCompany.link = link;

if (link.valid) {
Expand Down
10 changes: 5 additions & 5 deletions src/app/admin/links/links.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ export class LinksService {
const eventOverride = this.event !== undefined && this.event.id !== event.id;
this.event = event;
if (eventOverride) { this.updateLinks(event.id as string); }
});

this.deckCompaniesSubscription = this.deckService.getDeckCompaniesSubject()
.subscribe(companies => {
this.companies.updateCompanies(companies, this.event.id);
this.updateLinks();
this.deckCompaniesSubscription = this.deckService.getDeckCompaniesSubject()
.subscribe(companies => {
this.companies.updateCompanies(companies, this.event.id.toString());
this.updateLinks();
});
});
}

Expand Down
1 change: 1 addition & 0 deletions src/app/admin/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class LoginComponent implements OnInit {
auto_select: false,
cancel_on_tap_outside: true,
ux_mode: "popup",
hd: "sinfo.org"
});
this.renderGoogleButton();
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/admin/login/login.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ export class LoginService {
) { }

getToken() {
return this.storage.getItem('corlief_token');
return this.storage.getItem('token')['token'];
}

saveToken(credentials: String) {
this.storage.setItem('corlief_token', credentials);
this.storage.setItem('token', credentials);
}

login(user: String, token: String): Observable<String> {
return this.http.post<String>(`${this.corlief}/auth/google`, { user, token }, httpOptions);
}

logout() {
this.storage.removeItem('corlief_token');
this.storage.removeItem('token');
this.router.navigate(['/login']);
}

isLoggedIn(): boolean {
return this.storage.getItem('corlief_token') !== null;
return this.storage.getItem('token') !== null;
}
}
28 changes: 21 additions & 7 deletions src/app/deck/company.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,63 @@
import { Link } from '../admin/links/link/link';
import { Event } from './event';

export class Item {
name: String;
description: String;
type: String;
cost: Number;
vat: Number;
}

export class Package {
name: String;
items?: [Item];
}

export class Participation {
event: String;
member: String;
status: String;
kind: String;
advertisementLvl: String;
partner: Boolean;

static getFromEvent(participations: [Participation], event: Event): Participation {
return Participation.getFromEdition(participations, event.id);
}

static getFromEdition(participations: [Participation], edition: String): Participation {
for (const p of participations) {
if (p.event === edition) { return p; }
if (p.event.toString() === edition) { return p; }
} return null;
}
}

export class Company {
id: String;
img: String;
description: String;

name?: String;
participations?: [Participation];
participation?: [Participation];

currentParticipation: Participation;
link?: Link;

static filter(company: Company, edition: String) {
if (company.participations === undefined || !company.participations.length) {
if (company.participation === undefined || !company.participation.length) {
return false;
}

if (company.currentParticipation === undefined) {
company.currentParticipation = Participation.getFromEdition(company.participations, edition);
company.currentParticipation = Participation.getFromEdition(company.participation, edition);
}

if (company.currentParticipation === null || company.currentParticipation.kind === 'Partnership') {
if (company.currentParticipation === null || company.currentParticipation.partner) {
return false;
}

return ['in-conversations', 'closed-deal', 'announced']
.includes(company.currentParticipation.status as string);
return true;
}

static findById(id: String, companies: Company[]) {
Expand Down
6 changes: 4 additions & 2 deletions src/app/deck/deck.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export class DeckService {
private getCompanies(edition: String): void {
this.http.get<Company[]>(
`${this.deck}/companies?event=${edition}`
).subscribe(companies => this.deckCompaniesSubject.next(companies));
).subscribe(companies => {
this.deckCompaniesSubject.next(companies)
});
}

getEventSubject(): Observable<Event> {
Expand All @@ -70,7 +72,7 @@ export class DeckService {
this.events = Event.fromArray(events).sort(Event.compare) as [Event];

const filtered = edition
? events.filter(e => e.id === edition)[0]
? events.filter(e => e.id.toString() === edition)[0]
: events[events.length - 1];

const event = new Event(filtered);
Expand Down

0 comments on commit 834a7ef

Please sign in to comment.