28 lines
842 B
TypeScript
28 lines
842 B
TypeScript
import { Injectable, inject } from '@angular/core';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { Observable, map } from 'rxjs';
|
|
import { Bot, BotWithToken } from '../models/bot.models';
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class BotService {
|
|
private readonly http = inject(HttpClient);
|
|
private readonly base = '/api/account/bots';
|
|
|
|
list(): Observable<Bot[]> {
|
|
return this.http.get<Bot[]>(this.base);
|
|
}
|
|
|
|
create(name: string): Observable<BotWithToken> {
|
|
return this.http.post<BotWithToken>(this.base, { name });
|
|
}
|
|
|
|
rotateToken(botId: string): Observable<string> {
|
|
return this.http.post<{ token: string }>(`${this.base}/${botId}/rotate-token`, null)
|
|
.pipe(map(r => r.token));
|
|
}
|
|
|
|
delete(botId: string): Observable<void> {
|
|
return this.http.delete<void>(`${this.base}/${botId}`);
|
|
}
|
|
}
|