Function getUser accepts userId and returns a Promise.
The functionality is missing and you need to fix that.

  • The promise should be rejected if the userId is missing.
  • The promise should be resolved with the appropriate user object if the userId is provided.

This task is part of the Full-Stack JavaScript Course
If you have any issues with it, you can ask for community help below the post
Feel free to help others if you’ve already solved the task

db.js

import { loadData } from './storage.js';

export const getUser = (userId) => new Promise((resolve, reject) => {
  //check userId and reject if it's missing

  setTimeout(() => {
    //use loadData and resolve with the user object if the id is present
    return {};
  }, 200);
});

solution.js

import { getUser } from './db.js';

getUser(1).then(console.log).catch(e => console.log(e.message));

getUser().then(console.log).catch(e => console.log(e.message));

storage.js

export const loadData = () => ({
  users: [
    {
      id: 1,
      name: 'Jack',
      friends: [ 23, 125 ],
    }, {
      id: 23,
      name: 'Jane',
      friends: [ 125 ],
    }, {
      id: 125,
      name: 'Jill',
      friends: [ 1 ],
    }
  ]
})