UNPKG

glide-nodejs-sdk

Version:

Glide NodeJS SDK

72 lines (59 loc) 1.72 kB
const validateSchema = require("../utils/validator.schema"); const handleApiErrors = require("../errors/handleApiErrors"); const { updateMerchantSchema, getMerchantTransactionSchema } = require("../validators/merchant.schema"); class Merchant { constructor(request) { this.request = request; } profile = async () => { try { const { data } = await this.request.get("/merchant/profile"); if (data && data.status) { return data.data; } else { throw new Error("Unable to get profile information"); } } catch (error) { handleApiErrors(error); } }; updateProfile = async (payload) => { try { const updatePayload = await validateSchema({ schema: updateMerchantSchema, payload }); const { data } = await this.request.patch("/merchant/profile", updatePayload); if (data && data.status) { return data.status; } else { throw new Error("Unable to update profile information"); } } catch (error) { handleApiErrors(error); } }; getWallet = async () => { try { const { data } = await this.request.get("/merchant/wallet"); if (data && data.status) { return data.wallet; } else { throw new Error("Unable to get wallet information"); } } catch (error) { handleApiErrors(error); } }; getTransactions = async () => { try { const transactionQuery = await validateSchema({ schema: getMerchantTransactionSchema, payload }); const { data } = await this.request.get("/merchant/transactions", { params: transactionQuery }); if (data && data.status) { return data.data; } else { throw new Error("Unable to get transactions"); } } catch (error) { handleApiErrors(error); } }; } module.exports = Merchant;