UNPKG

glide-nodejs-sdk

Version:

Glide NodeJS SDK

61 lines (49 loc) 1.62 kB
const handleApiErrors = require("../errors/handleApiErrors"); const { customerTransactionSchema } = require("../validators/transaction.schema"); const { getCustmersSchema, customerUpdateSchema } = require("../validators/customer.schema"); const validateSchema = require("../utils/validator.schema"); class Customer { constructor(request) { this.request = request; } getAll = async (payload) => { try { const customerQuery = await validateSchema({ schema: getCustmersSchema, payload }); const { data } = await this.request.get("/customer", { params: customerQuery }); if (data && data.status) { return data; } else { throw new Error("Unable to get customer list"); } } catch (error) { handleApiErrors(error); } }; update = async (customerId, payload) => { try { const updatePayload = await validateSchema({ schema: customerUpdateSchema, payload }); const { data } = await this.request.put(`/customer/${customerId}`, updatePayload); if (data && data.status) { return data.customer; } else { throw new Error("Unable to update customer profile"); } } catch (error) { handleApiErrors(error); } }; transactions = async (payload) => { try { const transactionQuery = await validateSchema({ schema: customerTransactionSchema, payload }); const { data } = await this.request.get("/wallet/transactions", { params: transactionQuery }); if (data && data.status) { return data; } else { throw new Error("Unable to get customer transactions"); } } catch (error) { handleApiErrors(error); } }; } module.exports = Customer;