/** * @author songxiwen * @date 2020/12/07 17:29 */ import { TowifyClient } from './towify.client'; import { GettingUsableApiKeyErrorType, GettingUsableApiKeySuccessType, ThirdPartyApiKeyListFilterRequestType, ThirdPartyApiKeyRequestType, ThirdPartyApiKeyResponseType, ThirdPartyPlatformListFilterRequestType, ThirdPartyPlatformRequestType, ThirdPartyPlatformResponseType } from './type'; export enum ApiKeyMicroserviceFunction { CreateThirdPartyApiKey = 'ThirdPartyApiKeyService:createThirdPartyApiKey', GetThirdPartyPlatformById = 'ThirdPartyApiKeyService:getThirdPartyPlatformById', GetUsableTinyApiKey = 'ThirdPartyApiKeyService:getUsableTinyApiKey', GetThirdPartyApiKeyList = 'ThirdPartyApiKeyService:getThirdPartyApiKeyList', GetThirdPartyApiKeyPageList = 'ThirdPartyApiKeyService:getThirdPartyApiKeyPageList', GetThirdPartyApiKeyCount = 'ThirdPartyApiKeyService:getThirdPartyApiKeyCount', CreateThirdPartyPlatform = 'ThirdPartyApiKeyService:createThirdPartyPlatform', ChangeThirdPartyPlatformStatus = 'ThirdPartyApiKeyService:changeThirdPartyPlatformStatus', GetThirdPartyPlatformList = 'ThirdPartyApiKeyService:getThirdPartyPlatformList', GetThirdPartyPlatformPageList = 'ThirdPartyApiKeyService:getThirdPartyPlatformPageList', GetThirdPartyPlatformCount = 'ThirdPartyApiKeyService:getThirdPartyPlatformCount', UpdateTinyApiKeyRemainingCount = 'ThirdPartyApiKeyService:updateTinyApiKeyRemainingCount' } export class ApiKeyMicroserviceHandler { public static async createThirdPartyApiKey( requestBody: ThirdPartyApiKeyRequestType ): Promise { await TowifyClient.getInstance().sendMessage< void, ThirdPartyApiKeyRequestType >(ApiKeyMicroserviceFunction.CreateThirdPartyApiKey, requestBody); } public static async getUsableTinyApiKey(): Promise< | GettingUsableApiKeySuccessType<{ key: string; }> | GettingUsableApiKeyErrorType > { const result = await TowifyClient.getInstance().sendMessage< | GettingUsableApiKeySuccessType<{ key: string; }> | GettingUsableApiKeyErrorType, '' >(ApiKeyMicroserviceFunction.GetUsableTinyApiKey, ''); return result; } public static async updateTinyApiKeyRemainingCount(requestBody: { thirdPartyApiKeyId: string; thirdPartyPlatformName: string; callerId: string; callerRole: string; }): Promise { await TowifyClient.getInstance().sendMessage< void, { thirdPartyApiKeyId: string; thirdPartyPlatformName: string; callerId: string; callerRole: string; } >(ApiKeyMicroserviceFunction.UpdateTinyApiKeyRemainingCount, requestBody); } public static async getThirdPartyPlatformById(requestBody: { id: string; }): Promise { const result = await TowifyClient.getInstance().sendMessage< ThirdPartyPlatformResponseType, { id: string } >(ApiKeyMicroserviceFunction.GetThirdPartyPlatformById, requestBody); return result; } public static async getThirdPartyApiKeyList(): Promise< ThirdPartyApiKeyResponseType[] > { const result = await TowifyClient.getInstance().sendMessage< ThirdPartyApiKeyResponseType[], string >(ApiKeyMicroserviceFunction.GetThirdPartyApiKeyList, ''); return result; } public static async getThirdPartyApiKeyPageList( requestBody: ThirdPartyApiKeyListFilterRequestType ): Promise { const result = await TowifyClient.getInstance().sendMessage< ThirdPartyApiKeyResponseType[], ThirdPartyApiKeyListFilterRequestType >(ApiKeyMicroserviceFunction.GetThirdPartyApiKeyPageList, requestBody); return result; } public static async getThirdPartyApiKeyCount( requestBody: ThirdPartyApiKeyListFilterRequestType ): Promise { const result = await TowifyClient.getInstance().sendMessage< number, ThirdPartyApiKeyListFilterRequestType >(ApiKeyMicroserviceFunction.GetThirdPartyApiKeyCount, requestBody); return result; } public static async createThirdPartyPlatform( requestBody: ThirdPartyPlatformRequestType ): Promise { await TowifyClient.getInstance().sendMessage< void, ThirdPartyPlatformRequestType >(ApiKeyMicroserviceFunction.CreateThirdPartyPlatform, requestBody); } public static async changeThirdPartyPlatformStatus(requestBody: { id: string; isEnabled: boolean; }): Promise { await TowifyClient.getInstance().sendMessage< void, { id: string; isEnabled: boolean; } >(ApiKeyMicroserviceFunction.ChangeThirdPartyPlatformStatus, requestBody); } public static async getThirdPartyPlatformList(): Promise< ThirdPartyPlatformResponseType[] > { const result = await TowifyClient.getInstance().sendMessage< ThirdPartyPlatformResponseType[], string >(ApiKeyMicroserviceFunction.GetThirdPartyPlatformList, ''); return result; } public static async getThirdPartyPlatformPageList( requestBody: ThirdPartyPlatformListFilterRequestType ): Promise { const result = await TowifyClient.getInstance().sendMessage< ThirdPartyPlatformResponseType[], ThirdPartyPlatformListFilterRequestType >(ApiKeyMicroserviceFunction.GetThirdPartyPlatformPageList, requestBody); return result; } public static async getThirdPartyPlatformCount( requestBody: ThirdPartyPlatformListFilterRequestType ): Promise { const result = await TowifyClient.getInstance().sendMessage< number, ThirdPartyPlatformListFilterRequestType >(ApiKeyMicroserviceFunction.GetThirdPartyPlatformCount, requestBody); return result; } }