-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b173b7b
commit 83c6906
Showing
8 changed files
with
280 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,27 @@ | ||
import * as authservice from './services/auth-service'; | ||
import * as networkservice from './services/network-service'; | ||
|
||
import AuthClient, { createAuthClient, IAuthClient } from './services/auth-service'; | ||
|
||
import RecordService, { IRecordService } from './services/record-service'; | ||
|
||
import SidedrawerSevice, { ISidedrawerSevice } from './services/sidedrawer-service'; | ||
|
||
import UserSevice, { IUserSevice } from './services/user-service'; | ||
|
||
import NetworkService, { INetworkService } from './services/network-service'; | ||
|
||
export const authClient: IAuthClient = new AuthClient(); | ||
|
||
export const networks: INetworkService = new NetworkService(); | ||
|
||
export const records: IRecordService = new RecordService(); | ||
|
||
export const sidedrawers: ISidedrawerSevice = new SidedrawerSevice(); | ||
|
||
export const users: IUserSevice = new UserSevice(); | ||
|
||
export const createAuthSidedrawerClient = async (client_id: string) => { | ||
return await authservice.createAuthClient(client_id); | ||
return await createAuthClient(client_id); | ||
}; | ||
|
||
export const getSidedrawersOwned = async (token: string) => { | ||
return networkservice.getOwned(token); | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,45 @@ | ||
import config from '../config.json'; | ||
import axios from 'axios'; | ||
//import { Auth0Client } from '@auth0/auth0-spa-js'; | ||
|
||
import { auth } from './auth-service'; | ||
|
||
const instance = axios.create({ | ||
baseURL: config.apiNetwork | ||
}); | ||
|
||
|
||
export const getTimeline = async (sidedrawer_id: string, type: string) => { | ||
return instance.get(`sidedrawer/sidedrawer-id/${sidedrawer_id}/log?locale=en-CA&page=1&entityType=${type}`); | ||
}; | ||
export interface INetworkService { | ||
|
||
export const getShared = async () => { | ||
return instance.get(`sidedrawer/shared`); | ||
}; | ||
getTimeline(sidedrawer_id: string, type: string): Promise<any>; | ||
getShared(): Promise<any>; | ||
getOwned(): Promise<any>; | ||
|
||
} | ||
|
||
export default class NetworkService implements INetworkService { | ||
|
||
getTimeline = async (sidedrawer_id: string, type: string) => { | ||
await setToken(); | ||
return instance.get(`sidedrawer/sidedrawer-id/${sidedrawer_id}/log?locale=en-CA&page=1&entityType=${type}`); | ||
}; | ||
|
||
getShared = async () => { | ||
await setToken(); | ||
return instance.get(`sidedrawer/shared`); | ||
}; | ||
|
||
export const getOwned = async (token: string) => { | ||
console.log(`Bearer nuevo ${token}`); | ||
instance.defaults.headers.common['Authorization'] = `Bearer ${token}`; | ||
return instance.get(`sidedrawer/owned`); | ||
getOwned = async () => { | ||
await setToken(); | ||
return instance.get(`sidedrawer/owned`); | ||
}; | ||
|
||
|
||
} | ||
|
||
|
||
const setToken = async () => { | ||
if (!auth) | ||
throw new Error('The Auth Client have not been initialized'); | ||
|
||
instance.defaults.headers.common['Authorization'] = `Bearer ${await auth.getTokenSilently()}`; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
import config from '../config.json'; | ||
import axios from 'axios'; | ||
import { auth } from './auth-service'; | ||
|
||
const instance = axios.create({ | ||
baseURL: config.apiRecord | ||
}); | ||
export interface IRecordService { | ||
|
||
getBySidedrawer(sidedrawer_id: string): Promise<any>; | ||
getUserSetting(user_id: string): Promise<any>; | ||
|
||
export const getBySidedrawer = async (sidedrawer_id: string) => { | ||
return instance.get(`sidedrawer/sidedrawer-id/${sidedrawer_id}/records`); | ||
}; | ||
} | ||
export default class RecordService implements IRecordService { | ||
|
||
export const getUserSetting = async (user_id: string) => { | ||
return instance.get(`/accounts/account-id/${user_id}/settings`); | ||
}; | ||
getBySidedrawer = async (sidedrawer_id: string) => { | ||
await setToken(); | ||
return instance.get(`sidedrawer/sidedrawer-id/${sidedrawer_id}/records`); | ||
}; | ||
|
||
getUserSetting = async (user_id: string) => { | ||
await setToken(); | ||
return instance.get(`/accounts/account-id/${user_id}/settings`); | ||
}; | ||
|
||
} | ||
|
||
const setToken = async () => { | ||
if (!auth) | ||
throw new Error('The Auth Client have not been initialized'); | ||
|
||
instance.defaults.headers.common['Authorization'] = `Bearer ${await auth.getTokenSilently()}`; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,36 @@ | ||
import config from '../config.json'; | ||
import axios from 'axios'; | ||
import { auth } from './auth-service'; | ||
|
||
const instance = axios.create({ | ||
baseURL: config.apiRecord | ||
}); | ||
|
||
export interface ISidedrawerSevice { | ||
|
||
export const getHome = async (sidedrawer_id: string) => { | ||
return instance.get(`sidedrawer/sidedrawer-id/${sidedrawer_id}/home?locale=en-CA`); | ||
getHome(sidedrawer_id: string): Promise<any>; | ||
getById(user_id: string): Promise<any>; | ||
|
||
} | ||
|
||
export default class SidedrawerSevice implements ISidedrawerSevice { | ||
|
||
getHome = async (sidedrawer_id: string) => { | ||
await setToken(); | ||
return instance.get(`sidedrawer/sidedrawer-id/${sidedrawer_id}/home?locale=en-CA`); | ||
}; | ||
|
||
getById = async (sidedrawer_id: string) => { | ||
await setToken(); | ||
return instance.get(`sidedrawer/sidedrawer-id/${sidedrawer_id}`); | ||
}; | ||
|
||
} | ||
|
||
const setToken = async () => { | ||
if (!auth) | ||
throw new Error('The Auth Client have not been initialized'); | ||
|
||
instance.defaults.headers.common['Authorization'] = `Bearer ${await auth.getTokenSilently()}`; | ||
}; | ||
|
||
export const getById = async (sidedrawer_id: string) => { | ||
return instance.get(`sidedrawer/sidedrawer-id/${sidedrawer_id}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,36 @@ | ||
import config from '../config.json'; | ||
import axios from 'axios'; | ||
import { auth } from './auth-service'; | ||
|
||
const instance = axios.create({ | ||
baseURL: config.apiUser | ||
}); | ||
|
||
export interface IUserSevice { | ||
|
||
export const getUserBy = async (auth: string) => { | ||
return instance.get(`/accounts/open-id/${auth}`); | ||
}; | ||
getUserBy(auth: string): Promise<any>; | ||
getSetting(user_id: string): Promise<any>; | ||
|
||
export const getUserSetting = async (user_id: string) => { | ||
return instance.get(`/accounts/account-id/${user_id}/settings`); | ||
}; | ||
} | ||
|
||
export default class UserSevice implements IUserSevice { | ||
|
||
getUserBy = async (auth: string) => { | ||
await setToken(); | ||
return instance.get(`/accounts/open-id/${auth}`); | ||
}; | ||
|
||
getSetting = async (user_id: string) => { | ||
await setToken(); | ||
return instance.get(`/accounts/account-id/${user_id}/settings`); | ||
}; | ||
|
||
} | ||
|
||
|
||
const setToken = async () => { | ||
if (!auth) | ||
throw new Error('The Auth Client have not been initialized'); | ||
|
||
instance.defaults.headers.common['Authorization'] = `Bearer ${await auth.getTokenSilently()}`; | ||
}; |
Oops, something went wrong.