mirror of
https://github.com/valitydev/dashboard.git
synced 2024-11-06 10:35:21 +00:00
Add bootstrap service with getMyParty call (#328)
This commit is contained in:
parent
db7b9dedb5
commit
c96e2b0837
@ -3,7 +3,7 @@ import { NgModule } from '@angular/core';
|
||||
import { CAPIConfigService } from './capi-config.service';
|
||||
import { InvoicesService } from './invoices.service';
|
||||
import { ShopsService } from './shops.service';
|
||||
import { ApiModule, ClaimsService, Configuration, PayoutsService } from './swagger-codegen';
|
||||
import { ApiModule, ClaimsService, Configuration, PartiesService, PayoutsService } from './swagger-codegen';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@ -12,6 +12,6 @@ import { ApiModule, ClaimsService, Configuration, PayoutsService } from './swagg
|
||||
providers: [{ provide: Configuration, useClass: CAPIConfigService }],
|
||||
},
|
||||
],
|
||||
providers: [CAPIConfigService, ClaimsService, ShopsService, InvoicesService, PayoutsService],
|
||||
providers: [CAPIConfigService, ClaimsService, ShopsService, InvoicesService, PayoutsService, PartiesService],
|
||||
})
|
||||
export class CAPIModule {}
|
||||
|
14
src/app/api/capi/capi-parties.service.ts
Normal file
14
src/app/api/capi/capi-parties.service.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { PartiesService, Party } from '../../api-codegen/capi';
|
||||
import { genXRequestID } from '../utils';
|
||||
|
||||
@Injectable()
|
||||
export class CAPIPartiesService {
|
||||
constructor(private partiesService: PartiesService) {}
|
||||
|
||||
getMyParty(): Observable<Party> {
|
||||
return this.partiesService.getMyParty(genXRequestID());
|
||||
}
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { CAPIClaimsService } from './capi-claims.service';
|
||||
import { CAPIPartiesService } from './capi-parties.service';
|
||||
|
||||
@NgModule({
|
||||
providers: [CAPIClaimsService],
|
||||
providers: [CAPIClaimsService, CAPIPartiesService],
|
||||
})
|
||||
export class CAPIModule {}
|
||||
|
@ -1,4 +1,5 @@
|
||||
export * from './capi.module';
|
||||
export * from './capi-claims.service';
|
||||
export * from './capi-parties.service';
|
||||
export * from './utils';
|
||||
export * from './models';
|
||||
|
@ -1,5 +1,5 @@
|
||||
<dsh-container>
|
||||
<dsh-sections></dsh-sections>
|
||||
<dsh-sections *ngIf="bootstrapSuccessful$ | async"></dsh-sections>
|
||||
</dsh-container>
|
||||
|
||||
<dsh-yandex-metrika *ngIf="env.production"></dsh-yandex-metrika>
|
||||
|
@ -1,17 +1,30 @@
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { TranslocoService } from '@ngneat/transloco';
|
||||
import { filter } from 'rxjs/operators';
|
||||
|
||||
import { ENV, Env } from '../environments';
|
||||
import { TestShopService } from './test-shop.service';
|
||||
import { BootstrapService } from './bootstrap.service';
|
||||
|
||||
@Component({
|
||||
selector: 'dsh-root',
|
||||
templateUrl: 'app.component.html',
|
||||
providers: [TestShopService],
|
||||
providers: [BootstrapService],
|
||||
})
|
||||
export class AppComponent implements OnInit {
|
||||
constructor(private testShopService: TestShopService, @Inject(ENV) public env: Env) {}
|
||||
bootstrapSuccessful$ = this.bootstrapService.bootstrapped$.pipe(filter((r) => !!r));
|
||||
|
||||
constructor(
|
||||
private bootstrapService: BootstrapService,
|
||||
@Inject(ENV) public env: Env,
|
||||
private snackBar: MatSnackBar,
|
||||
private transloco: TranslocoService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.testShopService.createTestShopWhenNoShops();
|
||||
this.bootstrapService.bootstrap();
|
||||
this.bootstrapService.bootstrapped$
|
||||
.pipe(filter((r) => !r))
|
||||
.subscribe(() => this.snackBar.open(this.transloco.translate('errors.bootstrapAppFailed'), 'OK'));
|
||||
}
|
||||
}
|
||||
|
44
src/app/bootstrap.service.ts
Normal file
44
src/app/bootstrap.service.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { iif, Observable, of, ReplaySubject } from 'rxjs';
|
||||
import { catchError, first, map, shareReplay, switchMap, switchMapTo, tap } from 'rxjs/operators';
|
||||
|
||||
import { ApiShopsService, CAPIClaimsService, CAPIPartiesService, createTestShopClaimChangeset } from './api';
|
||||
|
||||
@Injectable()
|
||||
export class BootstrapService {
|
||||
bootstrapped$: Observable<boolean>;
|
||||
|
||||
private bootstrap$ = new ReplaySubject(1);
|
||||
|
||||
constructor(
|
||||
private partiesService: CAPIPartiesService,
|
||||
private shopService: ApiShopsService,
|
||||
private capiClaimsService: CAPIClaimsService
|
||||
) {
|
||||
this.bootstrapped$ = this.bootstrap$.pipe(
|
||||
first(),
|
||||
switchMapTo(this.partiesService.getMyParty()),
|
||||
switchMapTo(this.shopService.shops$.pipe(first())),
|
||||
switchMap((shops) =>
|
||||
iif(
|
||||
() => shops.length === 0,
|
||||
this.createTestShop().pipe(tap(() => this.shopService.reloadShops())),
|
||||
of(true)
|
||||
)
|
||||
),
|
||||
catchError((err) => {
|
||||
console.error(err);
|
||||
return of(false);
|
||||
}),
|
||||
shareReplay(1)
|
||||
);
|
||||
}
|
||||
|
||||
bootstrap() {
|
||||
this.bootstrap$.next();
|
||||
}
|
||||
|
||||
private createTestShop(): Observable<boolean> {
|
||||
return this.capiClaimsService.createClaim(createTestShopClaimChangeset()).pipe(map(() => true));
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { TranslocoService } from '@ngneat/transloco';
|
||||
import { Subject } from 'rxjs';
|
||||
import { filter, first, switchMap, switchMapTo } from 'rxjs/operators';
|
||||
|
||||
import { ApiShopsService, CAPIClaimsService, createTestShopClaimChangeset } from './api';
|
||||
|
||||
@Injectable()
|
||||
export class TestShopService {
|
||||
private createTestShopWhenNoShops$ = new Subject();
|
||||
|
||||
constructor(
|
||||
private capiClaimsService: CAPIClaimsService,
|
||||
private shopService: ApiShopsService,
|
||||
private snackBar: MatSnackBar,
|
||||
private transloco: TranslocoService
|
||||
) {
|
||||
this.createTestShopWhenNoShops$
|
||||
.pipe(
|
||||
first(),
|
||||
switchMapTo(this.shopService.shops$),
|
||||
first(),
|
||||
filter((shops) => shops.length === 0),
|
||||
switchMap(() => this.createTestShop())
|
||||
)
|
||||
.subscribe(
|
||||
() => {
|
||||
this.shopService.reloadShops();
|
||||
},
|
||||
() => {
|
||||
this.snackBar.open(this.transloco.translate('commonError'), 'OK');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private createTestShop() {
|
||||
return this.capiClaimsService.createClaim(createTestShopClaimChangeset());
|
||||
}
|
||||
|
||||
createTestShopWhenNoShops(): void {
|
||||
this.createTestShopWhenNoShops$.next();
|
||||
}
|
||||
}
|
@ -138,7 +138,8 @@
|
||||
"saveConversationsFailed": "Не удалось сохранить комментарий",
|
||||
"revokeClaimByIDFailed": "Не удалось отозвать заявку",
|
||||
"requestReviewClaimByIDFailed": "Не удалось отправить заявку на рассмотрение",
|
||||
"updateClaimByIDFailed": " Не удалось обновить заявку"
|
||||
"updateClaimByIDFailed": " Не удалось обновить заявку",
|
||||
"bootstrapAppFailed": "Ошибка инициализации"
|
||||
},
|
||||
"yes": "Да",
|
||||
"no": "Нет",
|
||||
|
Loading…
Reference in New Issue
Block a user