web: EntryProposal form implementation.
This commit is contained in:
52
web/src/api-client/index.ts
Normal file
52
web/src/api-client/index.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { default as Axios, AxiosInstance } from 'axios';
|
||||
import { logService } from '@jdbernard/logging';
|
||||
|
||||
import {
|
||||
EventProposalConfig,
|
||||
eventProposalConfigFromDTO,
|
||||
EventProposalModel,
|
||||
eventProposalModelToDTO,
|
||||
} from './event-proposal.models';
|
||||
|
||||
export * from './event-proposal.models';
|
||||
|
||||
const logger = logService.getLogger('client-api');
|
||||
|
||||
export class HffEntryFormsApiClient {
|
||||
private http: AxiosInstance;
|
||||
|
||||
private cachedEventProposalConfig: EventProposalConfig | null = null;
|
||||
|
||||
constructor(apiBase: string) {
|
||||
this.http = Axios.create({ baseURL: apiBase });
|
||||
logger.trace('Initialized HffEntryFormsApiClient');
|
||||
}
|
||||
|
||||
public async version(): Promise<string> {
|
||||
const resp = await this.http.get('version');
|
||||
return resp.data as string;
|
||||
}
|
||||
|
||||
public async getEventProposalConfig(): Promise<EventProposalConfig> {
|
||||
if (!this.cachedEventProposalConfig) {
|
||||
logger.trace('GET /event-proposals/config');
|
||||
const resp = await this.http.get('/event-proposals/config');
|
||||
this.cachedEventProposalConfig = eventProposalConfigFromDTO(
|
||||
(resp.data as any).data
|
||||
);
|
||||
}
|
||||
|
||||
return this.cachedEventProposalConfig;
|
||||
}
|
||||
|
||||
public async proposeEvent(ep: EventProposalModel): Promise<boolean> {
|
||||
logger.trace('POST /event-proposals');
|
||||
const resp = await this.http.post(
|
||||
'/event-proposals',
|
||||
eventProposalModelToDTO(ep)
|
||||
);
|
||||
return resp.status < 300;
|
||||
}
|
||||
}
|
||||
|
||||
export default new HffEntryFormsApiClient(process.env.VUE_APP_API_BASE_URL);
|
Reference in New Issue
Block a user