You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.1 KiB
71 lines
2.1 KiB
import { Api } from './api'; |
|
import { Connection, TestRequest, ConnectionPoolType, SocketResult } from './crud.typings'; |
|
import { requestGet, requestDelete, requestPost, requestPut } from './crud.service'; |
|
import { editStatusEvent } from '@constants/env'; |
|
|
|
export class DecisionApi implements Api { |
|
isDec = true; |
|
|
|
getConnectionlist(): Promise<{data: Connection[]}> { |
|
return requestGet('list'); |
|
} |
|
|
|
deleteConnection(connectionName: string): Promise<{data: string}> { |
|
return requestDelete('', { |
|
connectionName, |
|
}); |
|
} |
|
|
|
addConnection(data: Connection): Promise<{data: string}> { |
|
const form = { |
|
...data, |
|
connectionId: data.connectionName, |
|
connectionData : JSON.stringify(data.connectionData), |
|
}; |
|
|
|
return requestPost('', form); |
|
} |
|
|
|
updateConnection(data: Connection): Promise<{data: string}> { |
|
const form = { |
|
...data, |
|
connectionData : JSON.stringify(data.connectionData), |
|
}; |
|
|
|
return requestPut('', form); |
|
} |
|
|
|
testConnection(data: Connection): Promise<TestRequest> { |
|
const form = { |
|
...data, |
|
connectionId: data.connectionName, |
|
connectionData : JSON.stringify(data.connectionData), |
|
}; |
|
|
|
return requestPost('test', form); |
|
} |
|
|
|
getConnectionPool(name: string): Promise<{data: ConnectionPoolType}> { |
|
return requestGet(`pool/info?connectionName=${name}`); |
|
} |
|
|
|
getConnectionStatus(name: string): Promise<SocketResult> { |
|
return this.sendEditStatusEvent(name, editStatusEvent.OPEN); |
|
} |
|
|
|
shutdownConnectionStatus(name: string): Promise<SocketResult> { |
|
return this.sendEditStatusEvent(name, editStatusEvent.SHUTDOWN); |
|
} |
|
|
|
private sendEditStatusEvent(name: string, type: string): Promise<SocketResult> { |
|
return new Promise(resolve => { |
|
if (Dec && Dec.socket.connected) { |
|
Dec.socket.emit(type, name, (re: any) => { |
|
resolve(re); |
|
}); |
|
} else { |
|
resolve({ data: 'success' }); |
|
} |
|
}); |
|
} |
|
}
|
|
|