import Base from './base' import { Context } from 'koa' import * as config from 'config' import { App, DbCollection } from '../../types' import { TeambitionCore } from '../../service/teambition-core' import * as TeambitionSDK from 'teambition-server-sdk' export default class TeambitionClient extends Base { private clientTbCore: TeambitionCore constructor (app: App, ctx: Context) { super(app, ctx) this.clientTbCore = new TeambitionCore(this.app['coreToken'], this.ctx.header['cookie']) } importTasksInTaskflow(_taskflowId: string, task: Object[]) { return this.clientTbCore.importTasksToScrum(_taskflowId, task) } importTasksToProject(task: Object[]) { const teambitionSDK = new TeambitionSDK.Client.Task() return teambitionSDK .setUrl(`${config.TEAMBITION.CORE.URL}/tasks`) .setHeader({ cookie: this.ctx.header['cookie'], 'request-server': config.APP.NAME }) .createOne(task) } getTestPlanGroups (_projectId: string, needRoot: boolean) { return this.clientTbCore.getTestPlanGroups(_projectId, needRoot) } getCutomfieldsByProjectId (_projectId: string) { return this.clientTbCore.getCustomfieldsByProjectId(_projectId) } getSfcByProjectId (_projectId: string, objectType: string = 'task') { return this.clientTbCore.getSfcByProjectId(_projectId, objectType) } getTagListByProjectId(_projectId: string) { return this.clientTbCore.findTagsByProjectId(_projectId) } getLookUpChoiceList(_projectId: string, _organizationId: string, _customfieldId: string) { return this.clientTbCore.getCustomfieldLookupChoices(_projectId, _organizationId, _customfieldId) } getSprintListByProjectId(_projectId: string) { return this.clientTbCore.getSprintList(_projectId) } importTestCases(body: DbCollection.Testcase) { return this.clientTbCore.importTestcase(body) } getTestPlansInProject (_projectId: string) { return this.clientTbCore.getTestPlanByProjectId(_projectId) } getOrganizationMemberByName(_organizationId: string, name: string) { return this.clientTbCore.getOrganizationMemberByName(_organizationId, name) } async getProjectCluster(_organizationId: string, selectBy: string, _projecttagId: string, _customfieldIds: string []) { const result = await this.clientTbCore.getProjectCluster(_organizationId, selectBy, _projecttagId, _customfieldIds) if (result.errors) { throw new Error(result.errors[0].message) } return result } async getCustomfields(_organizationId: string, _customfieldIds: string []) { const result = await this.clientTbCore.getCustomfields(_organizationId, _customfieldIds) if (result.errors) { throw new Error(result.errors[0].message) } return result } async getProjecttag(_projecttagId: string) { const result = await this.clientTbCore.getProjecttag(_projecttagId) if (result.errors) { throw new Error(result.errors[0].message) } return result } }