239 lines
6.1 KiB
TypeScript
239 lines
6.1 KiB
TypeScript
import {Injectable} from "@angular/core";
|
|
import ApiService, {AvailableVersion} from "@api/api.service";
|
|
import {catchError, of} from "rxjs";
|
|
import {DatabaseResponse} from "@api/v1/configuration/databaseResponse";
|
|
import {DatabaseRequest} from "@api/v1/configuration/databaseRequest";
|
|
import {CacheRequest} from "@api/v1/configuration/cacheRequest";
|
|
import {CreateUserRequest} from "@api/v1/createUserRequest";
|
|
import {LoggingRequest} from "@api/v1/configuration/loggingRequest";
|
|
import {ScheduleConfigurationRequest} from "@api/v1/configuration/scheduleConfigurationRequest";
|
|
import {EmailRequest} from "@api/v1/configuration/emailRequest";
|
|
import {DateOnly} from "@model/dateOnly";
|
|
import {CacheResponse} from "@api/v1/configuration/cacheResponse";
|
|
import {PasswordPolicy} from "@model/passwordPolicy";
|
|
import {UserResponse} from "@api/v1/userResponse";
|
|
|
|
@Injectable()
|
|
export default class SetupService extends ApiService {
|
|
public readonly basePath = 'Setup/';
|
|
public readonly version = AvailableVersion.v1;
|
|
|
|
public checkToken(token: string) {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('CheckToken')
|
|
.setQueryParams({token: token})
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.get<boolean>(request);
|
|
}
|
|
|
|
public isConfiguredToken() {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('IsConfiguredToken')
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.get<boolean>(request).pipe(catchError(_ => {
|
|
return of(false);
|
|
}));
|
|
}
|
|
|
|
public setPsql(data: DatabaseRequest) {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('SetPsql')
|
|
.setData(data)
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.post<boolean>(request);
|
|
}
|
|
|
|
public setMysql(data: DatabaseRequest) {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('SetMysql')
|
|
.setData(data)
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.post<boolean>(request);
|
|
}
|
|
|
|
public setSqlite(path: string | null = null) {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('SetSqlite')
|
|
.setQueryParams({path: path})
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.post<boolean>(request);
|
|
}
|
|
|
|
public databaseConfiguration() {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('DatabaseConfiguration')
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.get<DatabaseResponse>(request);
|
|
}
|
|
|
|
public setRedis(data: CacheRequest) {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('SetRedis')
|
|
.setData(data)
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.post<boolean>(request);
|
|
}
|
|
|
|
public setMemcached() {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('SetMemcached')
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.post<boolean>(request);
|
|
}
|
|
|
|
public cacheConfiguration() {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('CacheConfiguration')
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.get<CacheResponse>(request);
|
|
}
|
|
|
|
public setPasswordPolicy(data: PasswordPolicy | null) {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('SetPasswordPolicy')
|
|
.setData(data)
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.post<boolean>(request);
|
|
}
|
|
|
|
public passwordPolicyConfiguration() {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('PasswordPolicyConfiguration')
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.get<PasswordPolicy>(request);
|
|
}
|
|
|
|
public createAdmin(data: CreateUserRequest) {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('CreateAdmin')
|
|
.setData(data)
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.post<boolean>(request);
|
|
}
|
|
|
|
public adminConfiguration() {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('AdminConfiguration')
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.get<UserResponse>(request);
|
|
}
|
|
|
|
public registerOAuth(token: string) {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('HandleToken')
|
|
.setQueryParams({token: token})
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.get<null>(request);
|
|
}
|
|
|
|
public setLogging(data: LoggingRequest | null = null) {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('SetLogging')
|
|
.setData(data)
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.post<boolean>(request);
|
|
}
|
|
|
|
public loggingConfiguration() {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('LoggingConfiguration')
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.get<LoggingRequest>(request);
|
|
}
|
|
|
|
public setEmail(data: EmailRequest | null = null) {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('SetEmail')
|
|
.setData(data)
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.post<boolean>(request);
|
|
}
|
|
|
|
public setSchedule(data: ScheduleConfigurationRequest) {
|
|
data.startTerm = new DateOnly(data.startTerm).toString();
|
|
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('SetSchedule')
|
|
.setData(data)
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.post<boolean>(request);
|
|
}
|
|
|
|
public generateTotpKey() {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('GenerateTotpKey')
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.get<string>(request);
|
|
}
|
|
|
|
public verifyTotp(code: string) {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('VerifyTotp')
|
|
.setWithCredentials()
|
|
.setQueryParams({code: code})
|
|
.build;
|
|
|
|
return this.get<boolean>(request);
|
|
}
|
|
|
|
public scheduleConfiguration() {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('ScheduleConfiguration')
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.get<ScheduleConfigurationRequest>(request);
|
|
}
|
|
|
|
public submit() {
|
|
let request = this.createRequestBuilder()
|
|
.setEndpoint('Submit')
|
|
.setWithCredentials()
|
|
.build;
|
|
|
|
return this.post<boolean>(request);
|
|
}
|
|
|
|
public isConfigured() {
|
|
return this.get<boolean>('IsConfigured');
|
|
}
|
|
}
|