Skip to content

Commit

Permalink
tslint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Davo00 committed Oct 9, 2023
1 parent ee35dd8 commit 6e388b5
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 71 deletions.
2 changes: 1 addition & 1 deletion workbench/backend/src/app/booking/booking.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class BookingController {
.json({ activityId: e.message });
}

let axiosError: AxiosError = e?.error;
const axiosError: AxiosError = e?.error;
return res
.status(axiosError?.response?.status || 500)
.json(axiosError?.response?.data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ReOptimizeController {
const { data } = await this.dao.reOptimize('sync', ctx, body).toPromise();
return res.json(data);
} catch (e) {
let axiosError: AxiosError = e?.error;
const axiosError: AxiosError = e?.error;
return res
.status(axiosError?.response?.status || 500)
.json(axiosError?.response?.data);
Expand All @@ -30,7 +30,7 @@ export class ReOptimizeController {
const { data } = await this.dao.reOptimize('async', ctx, body).toPromise();
return res.json(data);
} catch (e) {
let axiosError: AxiosError = e?.error;
const axiosError: AxiosError = e?.error;
return res
.status(axiosError?.response?.status || 500)
.json(axiosError?.response?.data);
Expand Down
22 changes: 11 additions & 11 deletions workbench/frontend/src/app/common/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const DEFAULT_CTX = {
selectedLocale: 'en-us',
user: '<user>',
userId: 0
}
};

@Injectable({
providedIn: 'root'
Expand All @@ -42,14 +42,14 @@ export class AuthService {

public globalContext$ = new BehaviorSubject<GlobalContext>(DEFAULT_CTX);
public globalContextWithAuth$ = this.globalContext$.pipe(filter((it) => it !== DEFAULT_CTX));
public isLoggedIn$ = this.globalContext$.pipe(map(it => it !== DEFAULT_CTX))
public isLoggedIn$ = this.globalContext$.pipe(map(it => it !== DEFAULT_CTX));

public logout() {
public logout(): void {
this.clearContext();
this.onContextReady(DEFAULT_CTX);
}

public openLoginDialog() {
public openLoginDialog(): void {
const dialogRef = this.dialog.open(LoginDialogComponent,
LoginDialogComponent.CONFIG
);
Expand All @@ -66,14 +66,14 @@ export class AuthService {
});
}

public tryRestoreSession() {
public tryRestoreSession(): void {
const ctx = this.restoreContext();
if (ctx) {
this.infoMessage(
'[✅ INFO ✅] session loaded from sessionStorage',
'logout', () => this.logout()
);
setTimeout(() => this.onContextReady(ctx), 1)
setTimeout(() => this.onContextReady(ctx), 1);
} else {
this.infoMessage(
'[❌ WARN ❌ ] no session found',
Expand All @@ -83,18 +83,18 @@ export class AuthService {
}
}

private onContextReady(ctx: GlobalContext) {
private onContextReady(ctx: GlobalContext): void {
this.globalContext$.next(ctx);
}

private clearContext() {
private clearContext(): void {
this.infoMessage('[✅ INFO ✅] session cleared from sessionStorage', 'login', () => this.openLoginDialog());
sessionStorage.removeItem(this.AUTH_KEY);
}

private storeContext(ctx: GlobalContext) {
private storeContext(ctx: GlobalContext): void {
this.infoMessage('[✅ INFO ✅] session stored in sessionStorage');
sessionStorage.setItem(this.AUTH_KEY, JSON.stringify(ctx))
sessionStorage.setItem(this.AUTH_KEY, JSON.stringify(ctx));
}

private restoreContext(): GlobalContext | null {
Expand All @@ -104,7 +104,7 @@ export class AuthService {
: null;
}

private infoMessage(msg: string, btnText = 'ok', action: () => void | null = null) {
private infoMessage(msg: string, btnText = 'ok', action: () => void | null = null): void {
const snackBarRef = this.snackBar.open(msg, btnText, { duration: 5000 });
if (action) {
snackBarRef.onAction().subscribe(() => {
Expand Down
8 changes: 4 additions & 4 deletions workbench/frontend/src/app/common/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { Injectable } from '@angular/core';
export class ConfigService {
constructor() { }

private getHost() {
private getHost(): 'http://localhost:8000' | '' {
return location.origin === 'http://localhost:4200'
? 'http://localhost:8000'
: '';
}

public getApiUri() {
return `${this.getHost()}/api`
public getApiUri(): string {
return `${this.getHost()}/api`;
}

}
}
16 changes: 8 additions & 8 deletions workbench/frontend/src/app/common/services/plugin.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { of, throwError } from 'rxjs';
import { Observable, ObservedValueOf, of, throwError } from 'rxjs';
import { catchError, map, mergeMap } from 'rxjs/operators';
import { ConfigService } from './config.service';
import { CLIENT_IDENTIFIER } from '../contants';
Expand Down Expand Up @@ -39,10 +39,10 @@ export type PolicyObjectiveDto = {
})
export class PluginService {

private getHeaders(ctx: GlobalContext) {
private getHeaders(ctx: GlobalContext): HttpHeaders {
return new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': `${ctx.authToken}`,
Authorization: `${ctx.authToken}`,
'x-cloud-host': `${ctx.cloudHost}`,
'x-account-name': `${ctx.account}`,
'x-account-id': `${ctx.accountId}`,
Expand Down Expand Up @@ -70,14 +70,13 @@ export class PluginService {
}


// tslint:disable-next-line:typedef
fetchAll() {
fetchAll(): Observable<PluginDto[]> {
return this.auth.globalContextWithAuth$.pipe(
mergeMap(ctx => this.http.get<PluginDto[]>(`${this.config.getApiUri()}/plugin`, { headers: this.getHeaders(ctx) })),
);
}

fetchById(id: string) {
fetchById(id: string): Observable<ObservedValueOf<Observable<PluginDto>>> {
return this.auth.globalContextWithAuth$.pipe(
mergeMap(ctx => this.http.get<PluginDto>(`${this.config.getApiUri()}/plugin/by-id/${id}`, { headers: this.getHeaders(ctx) }))
);
Expand All @@ -91,6 +90,7 @@ export class PluginService {
);
}

// tslint:disable-next-line:typedef
create(plugin: Partial<PluginDto>) {
return this.auth.globalContextWithAuth$.pipe(
mergeMap(ctx => this.http.post<PluginDto>(`${this.config.getApiUri()}/plugin`, plugin, { headers: this.getHeaders(ctx) })),
Expand All @@ -106,13 +106,13 @@ export class PluginService {
);
}

update(plugin: Partial<PluginDto>) {
update(plugin: Partial<PluginDto>): Observable<ObservedValueOf<Observable<PluginDto>>> {
return this.auth.globalContextWithAuth$.pipe(
mergeMap(ctx => this.http.put<PluginDto>(`${this.config.getApiUri()}/plugin/${plugin.id}`, plugin, { headers: this.getHeaders(ctx) }))
);
}

delete(pluginId: string) {
delete(pluginId: string): Observable<ObservedValueOf<Observable<PluginDto>>> {
return this.auth.globalContextWithAuth$.pipe(
mergeMap(ctx => this.http.delete<PluginDto>(`${this.config.getApiUri()}/plugin/${pluginId}`, { headers: this.getHeaders(ctx) }))
);
Expand Down
39 changes: 21 additions & 18 deletions workbench/frontend/src/app/slot-booking/services/booking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export class BookingService {
private query: QueryService
) { }

private getHeaders(ctx: GlobalContext) {
private getHeaders(ctx: GlobalContext): HttpHeaders {
return new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': `${ctx.authToken}`,
Authorization: `${ctx.authToken}`,
'x-cloud-host': `${ctx.cloudHost}`,
'x-account-name': `${ctx.account}`,
'x-account-id': `${ctx.accountId}`,
Expand All @@ -44,17 +44,19 @@ export class BookingService {
'x-client-id': CLIENT_IDENTIFIER,
'x-client-version': '0.0.0',
'x-request-id': `${Date.now()}`,
})
});
}

// tslint:disable-next-line:typedef
private book(bookable: SearchResponseItem, job: Job, activityId: string = 'create-activity') {
return this.auth.globalContextWithAuth$.pipe(
mergeMap(ctx => this.http.post<{}>(`${this.config.getApiUri()}/booking/actions/book/${activityId}`, { job, bookable }, { headers: this.getHeaders(ctx) }))
mergeMap(ctx => this.http.post<{}>(`${this.config.getApiUri()}/booking/actions/book/${activityId}`,
{ job, bookable }, { headers: this.getHeaders(ctx) }))
);
}


public tryBookAll(list: SearchResponseItem[], job: Job) {
public tryBookAll(list: SearchResponseItem[], job: Job): Observable<Progress> {

return new Observable<Progress>((op) => {

Expand All @@ -68,7 +70,7 @@ export class BookingService {
current: (idx + 1),
result: null,
activityId,
}
};


const person = this.query.getResourceFromCache(bookable.resource);
Expand All @@ -83,25 +85,26 @@ export class BookingService {
success: true,
message: `🎉🎉 we booked a slot with ${person.firstName} ${person.lastName} from ${moment(bookable.start).format('HH:mm')} to ${moment(bookable.end).format('HH:mm')} `,
result
})
});
})
.catch(errorRep => {
// tslint:disable-next-line:no-shadowed-variable
let activityId: string;
// if the backend returns a 422 - creation of temp data was okay but booking failed.
// use [activityId] for next try to not recreate data
// use [activityId] for next try to not recreate data
if (errorRep instanceof HttpErrorResponse && errorRep.status === 422 && errorRep.error) {
activityId = errorRep.error.activityId || ''
activityId = errorRep.error.activityId || '';
}

throw { ...progress, activityId: activityId ? activityId : '' };
});
}
};

// setup chain
// setup chain
const work = list.reduce(
(promise, it, idx) => promise.catch((progress: Progress) => tryBook(idx, it, progress.blockedList, progress.activityId)),
Promise.reject({ message: `init`, blockedList: [], success: false, total: list.length, current: -1 })
)
);

// run chain
work
Expand All @@ -110,15 +113,15 @@ export class BookingService {
op.complete();
})
.catch((error: Progress) => {
op.next({ ...error, message: '❌ slot booking failed, all technicains are booked already ...' });
op.next({ ...error, message: '❌ slot booking failed, all technicians are booked already ...' });
op.error(error);
});

return () => {
// clean ups
}
})
// clean-ups
};
});

};
}

}
}
26 changes: 15 additions & 11 deletions workbench/frontend/src/app/slot-booking/services/job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { mergeMap } from 'rxjs/operators';
import { ConfigService } from '../../common/services/config.service';
import { CLIENT_IDENTIFIER } from '../../common/contants';
import { GlobalContext, AuthService } from '../../common/services/auth.service';
import { Observable } from 'rxjs';

export type Job = {
durationMinutes: number,
Expand All @@ -13,7 +14,7 @@ export type Job = {
} | null,
mandatorySkills: string[],
optionalSkills: string[]
}
};

export type TagDTO = {
branches: null
Expand All @@ -33,7 +34,7 @@ export type TagDTO = {
syncStatus: 'IN_CLOUD'
udfMetaGroups: null
udfValues: null
}
};

export type AddressDTO = {
block: null
Expand Down Expand Up @@ -69,16 +70,16 @@ export type AddressDTO = {
udfMetaGroups: null
udfValues: null
zipCode: string
}
};
@Injectable({
providedIn: 'root'
})
export class JobService {

private getHeaders(ctx: GlobalContext) {
private getHeaders(ctx: GlobalContext): HttpHeaders {
return new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': `${ctx.authToken}`,
Authorization: `${ctx.authToken}`,
'x-cloud-host': `${ctx.cloudHost}`,
'x-account-name': `${ctx.account}`,
'x-account-id': `${ctx.accountId}`,
Expand All @@ -98,21 +99,24 @@ export class JobService {
private http: HttpClient,
) { }

fetchAllTags() {
fetchAllTags(): Observable<Array<TagDTO & { persons: string[] }>> {
return this.auth.globalContextWithAuth$.pipe(
mergeMap(ctx => this.http.get<Array<TagDTO & { persons: string[] }>>(`${this.config.getApiUri()}/query/tags`, { headers: this.getHeaders(ctx) }))
mergeMap(ctx => this.http.get<Array<TagDTO & { persons: string[] }>>(`${this.config.getApiUri()}/query/tags`,
{ headers: this.getHeaders(ctx) }))
);
}

fetchAllAddress() {
fetchAllAddress(): Observable<AddressDTO[]> {
return this.auth.globalContextWithAuth$.pipe(
mergeMap(ctx => this.http.get<AddressDTO[]>(`${this.config.getApiUri()}/query/address`, { headers: this.getHeaders(ctx) })),
mergeMap(ctx => this.http.get<AddressDTO[]>(`${this.config.getApiUri()}/query/address`,
{ headers: this.getHeaders(ctx) })),
);
}

personByTag(tagId: string) {
personByTag(tagId: string): Observable<{ person: string; tag: string }[]> {
return this.auth.globalContextWithAuth$.pipe(
mergeMap(ctx => this.http.get<{ person: string, tag: string }[]>(`${this.config.getApiUri()}/query/person/by-tag/${tagId}`, { headers: this.getHeaders(ctx) })),
mergeMap(ctx => this.http.get<{ person: string, tag: string }[]>(`${this.config.getApiUri()}/query/person/by-tag/${tagId}`,
{ headers: this.getHeaders(ctx) })),
);
}
}
Loading

0 comments on commit 6e388b5

Please sign in to comment.