Convert apis/index and queryUrlGenerator to TS
parent
fd18ec2714
commit
3b2c63acb1
|
@ -1,12 +0,0 @@
|
|||
import {proxy} from 'utils/queryUrlGenerator'
|
||||
|
||||
export const getAlerts = (source, timeRange, limit) =>
|
||||
proxy({
|
||||
source,
|
||||
query: `SELECT host, value, level, alertName FROM alerts WHERE time >= '${
|
||||
timeRange.lower
|
||||
}' AND time <= '${timeRange.upper}' ORDER BY time desc ${
|
||||
limit ? `LIMIT ${limit}` : ''
|
||||
}`,
|
||||
db: 'chronograf',
|
||||
})
|
|
@ -0,0 +1,19 @@
|
|||
import {proxy} from 'src/utils/queryUrlGenerator'
|
||||
import {TimeRange} from '../../types'
|
||||
|
||||
export const getAlerts = (
|
||||
source: string,
|
||||
timeRange: TimeRange,
|
||||
limit: number
|
||||
) => {
|
||||
const query = `SELECT host, value, level, alertName FROM alerts WHERE time >= '${
|
||||
timeRange.lower
|
||||
}' AND time <= '${timeRange.upper}' ORDER BY time desc ${
|
||||
limit ? `LIMIT ${limit}` : ''
|
||||
}`
|
||||
return proxy({
|
||||
source,
|
||||
query,
|
||||
db: 'chronograf',
|
||||
})
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
import AJAX from 'utils/ajax'
|
||||
|
||||
export const proxy = async ({source, query, db, rp, tempVars, resolution}) => {
|
||||
try {
|
||||
return await AJAX({
|
||||
method: 'POST',
|
||||
url: source,
|
||||
data: {
|
||||
tempVars,
|
||||
query,
|
||||
resolution,
|
||||
db,
|
||||
rp,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
throw error
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
import AJAX from 'src/utils/ajax'
|
||||
|
||||
interface ProxyQuery {
|
||||
source: string
|
||||
query: string
|
||||
db: string
|
||||
rp?: string
|
||||
tempVars?: string
|
||||
resolution?: string
|
||||
}
|
||||
|
||||
export async function proxy<T = any>({
|
||||
source,
|
||||
query,
|
||||
db,
|
||||
rp,
|
||||
tempVars,
|
||||
resolution,
|
||||
}: ProxyQuery) {
|
||||
try {
|
||||
return await AJAX<T>({
|
||||
method: 'POST',
|
||||
url: source,
|
||||
data: {
|
||||
tempVars,
|
||||
query,
|
||||
resolution,
|
||||
db,
|
||||
rp,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
throw error
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue