| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | /** * @name User * @description This module exposes functions * related to the `/users` path. * * @module user **/ import { cond, has, T, curry } from 'ramda' import routes from '../routes' import request from '../request' const findOne = curry((opts, body) => request.get(opts, routes.user.details(body.id), {}) ) const findAll = curry((opts, pagination) => request.get(opts, routes.user.base, pagination || {}) ) /** * `GET /users` * Makes a request to /users or to /users/:id * * @param {Object} opts An options params which * is usually already bound * by `connect` functions. * * @param {Object} body The payload for the request. * @param {Number} [body.id] The user's ID. If not sent a * users list will be returned instead. * @param {Number} [body.count] Pagination option to get a list of users. * Number of users in a page * @param {Number} [body.page] Pagination option for a list of users. * The page index. */ const find = (opts, body) => cond([ [has('id'), findOne(opts)], [T, findAll(opts)], ])(body) /** * `PUT /users/reset_password` * * @param {Object} opts An options params which * is usually already bound * by `connect` functions. * @param {String} email The email of the account * of which the password will * be reset. * @returns {Promise} Resolves to the result * of the request or an error. */ const resetPassword = (opts, body) => request.put(opts, routes.user.resetPassword, body) /** * `PUT /users/redefine_password` * Redefines a user's password based on a reset token * * @example * * client.user.redefinePassword() * * @param {Objec} opts An options params which * is usually already bound * by `connect` functions. * @param {Object} body An object containing the * reset token and email of * the account. * @returns {Promise} Resolves to the result * of the request or an error. */ const redefinePassword = (opts, body) => request.put(opts, routes.user.redefinePassword, body) /** * `POST /users/` * Creates a user * * @param {Objec} opts An options params which * is usually already bound * by `connect` functions. * @param {Object} body The payload for the request. */ const create = (opts, body) => request.post(opts, routes.user.base, body) /** * `GET /users` * Makes a request to /users * * @param {Object} opts An options params which * is usually already bound * by `connect` functions. * * @param {Number} [body.count] Pagination option to get a list of users. * Number of users in a page * @param {Number} [body.page] Pagination option for a list of users. * The page index. */ const all = (opts, body) => findAll(opts, body) /** * `DELETE /users/:id` * Deletes an user from the given payload. * * @param {Object} opts An options params which * is usually already bound * by `connect` functions. * * @param {String} [body.id] - The user ID. If not sent an * user list will be returned instead * * @returns {Promise} Resolves to the result of * the request or to an error. */ const destroy = (opts, body) => request.delete(opts, routes.user.details(body.id), {}) /** * `PUT /users/:id` * Updates a user from the given payload. * * @param {Object} opts An options params which * is usually already bound * by `connect` functions. * * @param {Object} body The payload for the request * * @returns {Promise} A promise that resolves to * the newly created user's * data or to an error. **/ const update = (opts, body) => request.put(opts, routes.user.details(body.id), body) /** * `PUT /user/:id/update_password` * Updates a user's password from the given payload. * * @example * client.user.updatePassword({ id:'123', current_password: 'foo', new_password: 'bar' }) * * @param {Object} opts An options params which * is usually already bound * by `connect` functions. * * @param {Object} body The payload for the request * * @returns {Promise} A promise that resolves to * the newly created user's * data or to an error. **/ const updatePassword = (opts, body) => request.put(opts, routes.user.updatePassword(body.id), body) /** * `GET /user` * Returns the currently authenticated user * * @param {Object} opts An options params which * is usually already bound * by `connect` functions. * * @returns {Promise} A promise that resolves to * the newly created user's * data or to an error. */ const current = opts => request.get(opts, routes.user.singular, {}) export default { all, create, current, destroy, find, redefinePassword, resetPassword, update, updatePassword, } |