0

I'm trying to use mocky.io to get mock values but here i am unable to assign the response data value to _user_id or any other variable, it's showing as undefined on console.log, when i do console.log for response object i get the json object but it's not working when i do the same to fetch the values inside the json object like userData.permissions,it shows undefined .

import axios from 'axios';
import { injectable } from 'inversify';
import "reflect-metadata";
interface RoutePermissions {
    admin?: boolean;
    view: boolean;
    user?:boolean;
   
  }
  interface UserPermissions {
    admin: boolean;
    view: boolean;
   
  }
  interface User {
    user_id: string;
    permissions: UserPermissions;
    test:boolean
  }
  
interface RoutePermissionsObject {
    [pageName: string]: RoutePermissions;
  }
  @injectable()
class configService {
    private _user_id:string="";
    private _userPermissions: { [key: string]:any} = {};
    private _test:boolean=true


  async loadConfigData(): Promise<void> {
    
    const response = await axios.get<User>('https://run.mocky.io/v3/4f5026de-ce29-49a8-b7d6-5c1dd93e3e54');
    const userData = response.data;
    console.log(userData);
    this._user_id=userData.user_id;
    this._userPermissions=userData.permissions;
    this._test=userData.test
    console.log(userData.permissions);
  
  }
  get UserPermissions(): UserPermissions {
    
    return {
      admin: this._userPermissions.admin,
      view: this._userPermissions.view
    };
  }

  
} ```

0 Answers0