UNPKG

khatavani-client

Version:

The Backend-Api-Integration package simplifies interaction with the backend API by providing a set of CRUD methods for common endpoints. It abstracts away the complexity of making HTTP requests and handling responses, allowing developers to focus on appli

211 lines (186 loc) 5.72 kB
import { FileStoreElement, ImageMetaDataType } from "./CollectionTypes"; import { CRUDMethods, PUT_METHOD } from "./crud"; import { UploadFile } from "./httpFetchHelper"; const KHATAVANI_ENDPOINT = "khatavani"; const USER_ENDPOINT = "Users"; const RESOURCE_ENDPOINT = "resources"; const ACCOUNT_ENDPOINT = "accounts"; const VOUCHER_ENDPOINT = "vouchers"; const TRANSACTION_ENDPOINT = "transactions"; const RESOURCEGROUPS_ENDPOINT = "resourceGroups"; const USERROLE_ENDPOINT = "userlevels"; const BALANCE_ENDPOINT = "balances"; const FILE_ENDPOINT = "files"; const BATCH_ENDPOINT = "batches"; const SERIES_ENDPOINT = "serializedid"; const MESSAGE_ENDPOINT = "messages"; const WAID_ENDPOINT = "waid"; const PAYMENT_ENDPOINT = "receipts"; const MARKER_ENDPOINT = "markers"; const PACKAGE_ENDPOINT = "packages"; /** *Returns Khatavani Object which has the create ,get,getOne,getAll,put,patch,delete * * @return Object of the class CRUDMethods */ export const Khatavani = (): CRUDMethods => { return new CRUDMethods(KHATAVANI_ENDPOINT); } /** *Returns Users Object which has the create ,get,getOne,getAll,put,patch,delete * * @return Object of the class CRUDMethods */ export const Users = (): CRUDMethods => { return new CRUDMethods(USER_ENDPOINT); } /** *Returns Resources Object which has the create ,get,getOne,getAll,put,patch,delete * * @return Object of the class CRUDMethods */ export const Resources = (): CRUDMethods => { return new CRUDMethods(RESOURCE_ENDPOINT); } /** *Returns Accounts Object which has the create ,get,getOne,getAll,put,patch,delete * * @return Object of the class CRUDMethods */ export const Accounts = (): CRUDMethods => { return new CRUDMethods(ACCOUNT_ENDPOINT); } /** *Returns Vouchers Object which has the create ,get,getOne,getAll,put,patch,delete * * @return Object of the class CRUDMethods */ export const Vouchers = (): CRUDMethods => { return new CRUDMethods(VOUCHER_ENDPOINT); } /** *Returns Transactions Object which has the create ,get,getOne,getAll,put,patch,delete * * @return Object of the class CRUDMethods */ export const Transactions = (): CRUDMethods => { return new CRUDMethods(TRANSACTION_ENDPOINT); } /** *Returns ResourceGroups Object which has the create ,get,getOne,getAll,put,patch,delete * * @return Object of the class CRUDMethods */ export const ResourceGroups = (): CRUDMethods => { return new CRUDMethods(RESOURCEGROUPS_ENDPOINT); } /** *Returns UserRoles Object which has the create ,get,getOne,getAll,put,patch,delete * * @return Object of the class CRUDMethods */ export const UserRoles = (): CRUDMethods => { return new CRUDMethods(USERROLE_ENDPOINT); } /** *Returns Balance Object which has the create ,get,getOne,getAll,put,patch,delete * * @return Object of the class CRUDMethods */ export const Balance = (): CRUDMethods => { return new CRUDMethods(BALANCE_ENDPOINT); } /** *Returns Files Object which has the create ,get,getOne,getAll,put,patch,delete * * @return Object of the class CRUDMethods */ export const Files = (): CRUDMethods => { return new CRUDMethods(FILE_ENDPOINT); } /** *Returns Batch Object which has the create ,get,getOne,getAll,put,patch,delete * * @return Object of the class CRUDMethods */ export const Batch = (): CRUDMethods => { return new CRUDMethods(BATCH_ENDPOINT); } /** *Returns Serialized Number (autoIncrementId) which has the get * * @return Object of the class CRUDMethods */ export const Serialized = (): CRUDMethods => { return new CRUDMethods(SERIES_ENDPOINT); } /** *Returns Messages from users which has the get * * @return Object of the class CRUDMethods */ export const Messages = (): CRUDMethods => { return new CRUDMethods(MESSAGE_ENDPOINT); } /** *Returns WA_ID from service with timestamp * * @return Object of the class CRUDMethods */ export const WAID = (): CRUDMethods => { return new CRUDMethods(WAID_ENDPOINT); } /** *Returns Payment from service with timestamp * * @return Object of the class CRUDMethods */ export const PAYMENT = (): CRUDMethods => { return new CRUDMethods(PAYMENT_ENDPOINT); } /** *Returns Markers from service * * @return Object of the class CRUDMethods */ export const Markers = (): CRUDMethods => { return new CRUDMethods(MARKER_ENDPOINT); } /** *Returns Markers from service * * @return Object of the class CRUDMethods */ export const Packages = (): CRUDMethods => { return new CRUDMethods(PACKAGE_ENDPOINT); } /** * @public * @return {allFiles} it is the promises array . * @remark it Uploads the Particular file or image to the firebase bucket */ export const UploadData = async ( fileStore: FileStoreElement[], authToken: string, khID: string, id: string | number, Public: boolean = false, ): Promise<any[]> => { const allFiles = fileStore.map(async (element) => { const uploadImageObject: ImageMetaDataType = { ...element.ImageMetaData }; if (Public) { uploadImageObject.public = Public; } else { uploadImageObject.accountID = id; } const fileEndpoint = Files(); const data = await fileEndpoint.create(authToken, khID, uploadImageObject); let file = element.ImageData; if (element.ImageData.data) { file = element.ImageData.data; } return UploadFile(PUT_METHOD, file, data.headers, data.url); }); await Promise.all(allFiles); return allFiles; };