UNPKG

@xompass/sdk-cloud-api

Version:

Xompass Client for cloud-api

454 lines (442 loc) 14.4 kB
import { SDKModels } from './SDKModels'; import { XompassBaseUserApi, XompassAuth } from '../core'; import { XompassClient } from '../../XompassClient'; import { LoopBackFilter, SDKToken, AccessToken } from '../../models'; import { SuperAdmin } from '../../models'; import { Log, Country, TimeZone } from '../../models'; /** * Api services for the `SuperAdmin` model. */ export abstract class SuperAdminApi extends XompassBaseUserApi { public static model = SDKModels.get('SuperAdmin'); public static findByIdAccessTokens(id: any, fk: any, retry = false): Promise<any> { const _method = 'GET'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/accessTokens/:fk' ].join(''); const _routeParams = { id, fk }; const _postBody = {}; const _urlParams: any = {}; return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static updateByIdAccessTokens( id: any, fk: any, data: any = {}, retry = false ): Promise<any> { const _method = 'PUT'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/accessTokens/:fk' ].join(''); const _routeParams = { id, fk }; const _postBody = { data }; const _urlParams: any = {}; return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static findByIdActivityLogs(id: any, fk: any, retry = false): Promise<any> { const _method = 'GET'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/activityLogs/:fk' ].join(''); const _routeParams = { id, fk }; const _postBody = {}; const _urlParams: any = {}; return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static findByIdTrackingLogs(id: any, fk: any, retry = false): Promise<any> { const _method = 'GET'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/trackingLogs/:fk' ].join(''); const _routeParams = { id, fk }; const _postBody = {}; const _urlParams: any = {}; return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static getCountry(id: any, refresh: any = {}, retry = false): Promise<any> { const _method = 'GET'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/country' ].join(''); const _routeParams = { id }; const _postBody = {}; const _urlParams: any = {}; if (typeof refresh !== 'undefined' && refresh !== null) { _urlParams['refresh'] = refresh; } return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static getTimeZone(id: any, refresh: any = {}, retry = false): Promise<any> { const _method = 'GET'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/timeZone' ].join(''); const _routeParams = { id }; const _postBody = {}; const _urlParams: any = {}; if (typeof refresh !== 'undefined' && refresh !== null) { _urlParams['refresh'] = refresh; } return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static getActivityLogs(id: any, filter: LoopBackFilter = {}, retry = false): Promise<any> { const _method = 'GET'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/activityLogs' ].join(''); const _routeParams = { id }; const _postBody = {}; const _urlParams: any = {}; if (typeof filter !== 'undefined' && filter !== null) { _urlParams['filter'] = filter; } return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static countActivityLogs(id: any, where: any = {}, retry = false): Promise<any> { const _method = 'GET'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/activityLogs/count' ].join(''); const _routeParams = { id }; const _postBody = {}; const _urlParams: any = {}; if (typeof where !== 'undefined' && where !== null) { _urlParams['where'] = where; } return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static getTrackingLogs(id: any, filter: LoopBackFilter = {}, retry = false): Promise<any> { const _method = 'GET'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/trackingLogs' ].join(''); const _routeParams = { id }; const _postBody = {}; const _urlParams: any = {}; if (typeof filter !== 'undefined' && filter !== null) { _urlParams['filter'] = filter; } return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static countTrackingLogs(id: any, where: any = {}, retry = false): Promise<any> { const _method = 'GET'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/trackingLogs/count' ].join(''); const _routeParams = { id }; const _postBody = {}; const _urlParams: any = {}; if (typeof where !== 'undefined' && where !== null) { _urlParams['where'] = where; } return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static login( credentials: any, include: any = 'user', rememberMe = true, retry = false ): Promise<any> { const _method = 'POST'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/login' ].join(''); const _routeParams = {}; const _postBody = { credentials }; const _urlParams: any = {}; if (typeof include !== 'undefined' && include !== null) { _urlParams['include'] = include; } return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry) .then((response: any) => { response.ttl = parseInt(response.ttl, 10); response.rememberMe = rememberMe; XompassAuth.setToken(response); return response; }); } public static logout(retry = false): Promise<any> { const _method = 'POST'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/logout' ].join(''); const _routeParams = {}; const _postBody = {}; const _urlParams: any = {}; _urlParams['access_token'] = XompassAuth.getAccessTokenId(); XompassAuth.clear(); return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static verify(id: any, retry = false): Promise<any> { const _method = 'POST'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/verify' ].join(''); const _routeParams = { id }; const _postBody = {}; const _urlParams: any = {}; return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static confirm( uid: any, token: any, redirect: any = {}, retry = false ): Promise<any> { const _method = 'GET'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/confirm' ].join(''); const _routeParams = {}; const _postBody = {}; const _urlParams: any = {}; if (typeof uid !== 'undefined' && uid !== null) { _urlParams['uid'] = uid; } if (typeof token !== 'undefined' && token !== null) { _urlParams['token'] = token; } if (typeof redirect !== 'undefined' && redirect !== null) { _urlParams['redirect'] = redirect; } return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static resetPassword(options: any, retry = false): Promise<any> { const _method = 'POST'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/reset' ].join(''); const _routeParams = {}; const _postBody = { options }; const _urlParams: any = {}; return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static changePassword(oldPassword: any, newPassword: any, retry = false): Promise<any> { const _method = 'POST'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/change-password' ].join(''); const _routeParams = {}; const _postBody = { data: { oldPassword, newPassword } }; const _urlParams: any = {}; return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static setPassword(newPassword: any, retry = false): Promise<any> { const _method = 'POST'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/reset-password' ].join(''); const _routeParams = {}; const _postBody = { data: { newPassword } }; const _urlParams: any = {}; return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static otpLogin(credentials: any, include: any = {}, retry = false): Promise<any> { const _method = 'POST'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/otp/login' ].join(''); const _routeParams = {}; const _postBody = { credentials }; const _urlParams: any = {}; if (typeof include !== 'undefined' && include !== null) { _urlParams['include'] = include; } return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static otpDisable(id: any, retry = false): Promise<any> { const _method = 'PATCH'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/otp/disable' ].join(''); const _routeParams = { id }; const _postBody = {}; const _urlParams: any = {}; return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static getMiniAppUserSessionsActive(id: any, retry = false): Promise<any> { const _method = 'GET'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/miniapp/activeSessions' ].join(''); const _routeParams = { id }; const _postBody = {}; const _urlParams: any = {}; return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static otpCheck(id: any, retry = false): Promise<any> { const _method = 'GET'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/otp/check' ].join(''); const _routeParams = { id }; const _postBody = {}; const _urlParams: any = {}; return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static otpGenerate(id: any, retry = false): Promise<any> { const _method = 'GET'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/otp/generate' ].join(''); const _routeParams = { id }; const _postBody = {}; const _urlParams: any = {}; return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static otpVerify(id: any, obj: any = {}, retry = false): Promise<any> { const _method = 'POST'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/:id/otp/verify' ].join(''); const _routeParams = { id }; const _postBody = { obj }; const _urlParams: any = {}; return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static verifyAccount(options: any, retry = false): Promise<any> { const _method = 'POST'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '/SuperAdmins/verify' ].join(''); const _routeParams = {}; const _postBody = { options }; const _urlParams: any = {}; return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static getCurrent(filter: LoopBackFilter = {}, retry = false): Promise<any> { const _method = 'GET'; const _url = [ XompassClient.getPath() + '/' + XompassClient.getApiVersion(), '' + '/:id' ].join(''); let id: any = XompassAuth.getCurrentUserId(); if (id == null) { id = '__anonymous__'; } const _routeParams = { id }; const _urlParams: any = {}; const _postBody = {}; if (filter) { _urlParams.filter = filter; } return super.request(_method, _url, _routeParams, _urlParams, _postBody, retry); } public static getCachedCurrent(): SuperAdmin { return XompassAuth.getCurrentUserData(); } public static getCurrentToken(): AccessToken { return XompassAuth.getToken(); } /** * * @returns True if the current user is authenticated (logged in). */ public static isAuthenticated(): boolean { const userId = this.getCurrentId(); const token = this.getCurrentToken(); if(userId === '' || userId == null || userId === 'null' || !token) { return false; } const now = new Date() const created = new Date(token.created || 0); const ttl = token.ttl || 0; return new Date(created.getTime() + ttl * 1000) > now; } /** * * @returns object Id of the currently logged-in user or null. */ public static getCurrentId(): string | number { return XompassAuth.getCurrentUserId(); } /** * The name of the model represented by this $resource, * i.e. `SuperAdmin`. */ public static getModelName(): string { return 'SuperAdmin'; } }