2022-09-05 00:55:52 +00:00
|
|
|
import { BaseAPI, route } from './base';
|
2022-09-01 22:32:03 +00:00
|
|
|
|
|
|
|
export type LoginResult = {
|
|
|
|
token: string;
|
|
|
|
expiresAt: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type LoginPayload = {
|
|
|
|
username: string;
|
|
|
|
password: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type RegisterPayload = {
|
|
|
|
user: {
|
|
|
|
email: string;
|
|
|
|
password: string;
|
|
|
|
name: string;
|
|
|
|
};
|
|
|
|
groupName: string;
|
|
|
|
};
|
|
|
|
|
2022-09-04 02:42:03 +00:00
|
|
|
export type StatusResult = {
|
|
|
|
health: boolean;
|
|
|
|
versions: string[];
|
|
|
|
title: string;
|
|
|
|
message: string;
|
|
|
|
};
|
|
|
|
|
2022-09-01 22:32:03 +00:00
|
|
|
export class PublicApi extends BaseAPI {
|
2022-09-04 02:42:03 +00:00
|
|
|
public status() {
|
2022-09-05 00:55:52 +00:00
|
|
|
return this.http.get<StatusResult>(route('/status'));
|
2022-09-04 02:42:03 +00:00
|
|
|
}
|
|
|
|
|
2022-09-01 22:32:03 +00:00
|
|
|
public login(username: string, password: string) {
|
2022-09-05 00:55:52 +00:00
|
|
|
return this.http.post<LoginPayload, LoginResult>(route('/users/login'), {
|
2022-09-02 01:52:40 +00:00
|
|
|
username,
|
|
|
|
password,
|
|
|
|
});
|
2022-09-01 22:32:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public register(payload: RegisterPayload) {
|
2022-09-05 00:55:52 +00:00
|
|
|
return this.http.post<RegisterPayload, LoginResult>(route('/users/register'), payload);
|
2022-09-01 22:32:03 +00:00
|
|
|
}
|
|
|
|
}
|