Created
April 20, 2017 12:10
-
-
Save oonsamyi/282a1a375c2ca2387bd03d390dd3c070 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* flow */ | |
import type { | |
ClientMisResponse, | |
VisitsMisResponse, | |
ServicesMisResponse, | |
} from '../types/MISResponse'; | |
export type MISResponse = ClientMisResponse | VisitsMisResponse | ServicesMisResponse; | |
export type ClientBodyRequest = { barcode: number }; | |
export type ClientInfoBodyRequest = { id: string }; | |
export type BodyRequest = ClientBodyRequest | ClientInfoBodyRequest; | |
export type MethodName = 'get_client_by_barcode' | 'get_visits_by_userid' | 'get_services_by_userid'; | |
export type SendRequest = (url: string, body: BodyRequest) => Promise<MISResponse>; | |
export default class MisApi { | |
constructor(sendRequest: SendRequest) { | |
Object.defineProperty(this, 'sendRequest', { | |
value: sendRequest, | |
enumerable: true, | |
}); | |
} | |
async callMethod(methodName: MethodName, body: BodyRequest): MISResponse { | |
return this.sendRequest( | |
`https://example.com/${methodName}`, body, | |
); | |
} | |
getClientByBarcode(body: ClientBodyRequest): ClientMisResponse { | |
return this.callMethod('get_client_by_barcode', body); | |
} | |
getVisitsByUserId(body: ClientInfoBodyRequest): VisitsMisResponse { | |
return this.callMethod('get_visits_by_userid', body); | |
} | |
getServicesByUserId(body: ClientInfoBodyRequest): ServicesMisResponse { | |
return this.callMethod('get_services_by_userid', body); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment