@@ -7,37 +7,30 @@ module.exports = class UserService {
77 * Fetch all the users.
88 * @returns {Promise<Array<User>> } A promise with the array of users.
99 */
10- static fetchAll ( ) {
11- return request . get ( `${ ENDPOINT } all` ) . then (
12- response => response . body . users . map (
13- user => new User ( user )
14- )
15- ) ;
10+ static async fetchAll ( ) {
11+ const { body} = await request . get ( `${ ENDPOINT } all` ) ;
12+ return body . users . map ( user => new User ( user ) ) ;
1613 }
1714
1815 /**
1916 * Fetch one user by id.
2017 * @param id
2118 * @returns {Promise<User> } A promise with the found user.an
2219 */
23- static fetchOne ( id ) {
24- return request . get ( `${ ENDPOINT } ${ id } ` ) . then (
25- response => new User ( response . body . user )
26- ) ;
20+ static async fetchOne ( id ) {
21+ const { body} = await request . get ( `${ ENDPOINT } ${ id } ` ) ;
22+ return new User ( body . user ) ;
2723 }
2824
2925 /**
3026 * Fetch the users based on the given IDs.
3127 * @param {Array<String> } ids
3228 * @returns {Promise<Array<User>> }
3329 */
34- static fetch ( ids ) {
30+ static async fetch ( ids ) {
3531 const idsString = ids && ids . length ? ids . join ( ',' ) : undefined ;
36- return request . get ( ENDPOINT , { ids : idsString } ) . then (
37- response => response . body . users . map (
38- user => new User ( user )
39- )
40- ) ;
32+ const { body} = await request . get ( ENDPOINT , { ids : idsString } ) ;
33+ return body . users . map ( user => new User ( user ) ) ;
4134 }
4235
4336 // static fetch(rol = undefined, ids = undefined, term = undefined) {
@@ -49,12 +42,9 @@ module.exports = class UserService {
4942 * @param {String } opts.term Terms to filter.
5043 * @returns {Promise<Array<User>> }
5144 */
52- static search ( { rol, state, term} ) {
53- return request . get ( ENDPOINT , { rol, state, term} ) . then (
54- response => response . body . users . map (
55- user => new User ( user )
56- )
57- ) ;
45+ static async search ( { rol, state, term} ) {
46+ const { body} = await request . get ( ENDPOINT , { rol, state, term} ) ;
47+ return body . users . map ( user => new User ( user ) ) ;
5848 }
5949
6050 /**
@@ -63,10 +53,9 @@ module.exports = class UserService {
6353 * @param {Array<String> } roles
6454 * @returns {Promise<User> }
6555 */
66- static add ( id , roles ) {
67- return request . put ( `${ ENDPOINT } ${ id } ` , { roles} ) . then (
68- response => new User ( response . body . user )
69- ) ;
56+ static async add ( id , roles ) {
57+ const { body} = await request . put ( `${ ENDPOINT } ${ id } ` , { roles} ) ;
58+ return new User ( body . user ) ;
7059 }
7160
7261 /**
0 commit comments