From 290e53b14f45ab6c2761572b8da5cfc134ccf09a Mon Sep 17 00:00:00 2001 From: b1ek Date: Mon, 15 May 2023 16:53:49 +1000 Subject: [PATCH] add user api wrapper --- pairent_frontend_react/src/API/User.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 pairent_frontend_react/src/API/User.js diff --git a/pairent_frontend_react/src/API/User.js b/pairent_frontend_react/src/API/User.js new file mode 100644 index 0000000..0f029f8 --- /dev/null +++ b/pairent_frontend_react/src/API/User.js @@ -0,0 +1,17 @@ +import axios from 'axios'; +import constants from '../constants'; + +const { API_ROOT } = constants; + +class User { + constructor(data) { + this = { ...data, ...this }; + } + + static async getById(id) { + const data = await axios.post(API_ROOT + '/users/get', { id }); + if (data.data['error']) + throw new Error(data.data['error']); + return new User(data.data); + } +} \ No newline at end of file