import * as jsonapi from 'utils/json-api-client' import { boundMethod } from 'autobind-decorator' import * as models from 'core/store/models' /** * Create adds validates, saves a new OcrKey. * * @example "POST /keys/ocr" */ export const ENDPOINT = '/proxy/v2/keys/ocr' /** * Index lists OcrKeys. * * @example "GET /keys/ocr" */ export const INDEX_ENDPOINT = ENDPOINT /** * Destroy deletes a OcrKey. * * @example "DELETE /keys/ocr/:keyId" */ interface DestroyPathParams { keyId: string } export const DESTROY_ENDPOINT = `${ENDPOINT}/:keyId` export class OcrKeys { constructor(private api: jsonapi.Api) {} /** * Index lists OcrKeys */ @boundMethod public getOcrKeys(): Promise> { return this.index() } @boundMethod public createOcrKey(): Promise> { return this.create() } @boundMethod public destroyOcrKey(id: string): Promise> { return this.destroy(undefined, { keyId: id }) } private create = this.api.createResource(ENDPOINT) private index = this.api.fetchResource<{}, models.OcrKey[]>(INDEX_ENDPOINT) private destroy = this.api.deleteResource( DESTROY_ENDPOINT, ) }