2022-12-13 07:37:49 -05:00
|
|
|
import Request from 'request'
|
|
|
|
|
|
|
|
const request = Request.defaults({
|
2021-07-13 07:04:48 -04:00
|
|
|
baseUrl: 'http://localhost:3010',
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
2016-12-14 12:38:14 -05:00
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
async function asyncRequest(options) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
request(options, (err, response, body) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err)
|
|
|
|
} else {
|
|
|
|
resolve({ response, body })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function sendGlobalMessage(projectId, userId, content) {
|
2022-01-10 04:29:32 -05:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/messages`,
|
|
|
|
json: {
|
|
|
|
user_id: userId,
|
|
|
|
content,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2016-12-16 11:52:50 -05:00
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function getGlobalMessages(projectId) {
|
2022-01-10 04:29:32 -05:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'get',
|
|
|
|
url: `/project/${projectId}/messages`,
|
|
|
|
json: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function sendMessage(projectId, threadId, userId, content) {
|
2022-01-10 04:29:32 -05:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages`,
|
|
|
|
json: {
|
|
|
|
user_id: userId,
|
|
|
|
content,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2017-01-04 08:51:08 -05:00
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function getThreads(projectId) {
|
2022-01-10 04:29:32 -05:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'get',
|
|
|
|
url: `/project/${projectId}/threads`,
|
|
|
|
json: true,
|
|
|
|
})
|
|
|
|
}
|
2017-01-24 09:44:32 -05:00
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function resolveThread(projectId, threadId, userId) {
|
2022-01-10 04:29:32 -05:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/resolve`,
|
|
|
|
json: {
|
|
|
|
user_id: userId,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2017-01-24 09:44:32 -05:00
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function editMessage(projectId, threadId, messageId, content) {
|
2022-01-10 04:29:32 -05:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}/edit`,
|
|
|
|
json: {
|
|
|
|
content,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2018-12-20 14:14:11 -05:00
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function editMessageWithUser(
|
2022-03-31 03:54:33 -04:00
|
|
|
projectId,
|
|
|
|
threadId,
|
|
|
|
messageId,
|
|
|
|
userId,
|
|
|
|
content
|
|
|
|
) {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}/edit`,
|
|
|
|
json: {
|
|
|
|
content,
|
|
|
|
userId,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-04 10:07:58 -05:00
|
|
|
export async function checkStatus() {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'get',
|
|
|
|
url: `/status`,
|
|
|
|
json: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-05 06:42:34 -05:00
|
|
|
export async function getMetric(matcher) {
|
|
|
|
const { body } = await asyncRequest({
|
|
|
|
method: 'get',
|
|
|
|
url: `/metrics`,
|
|
|
|
})
|
|
|
|
const found = body.split('\n').find(matcher)
|
|
|
|
if (!found) return 0
|
|
|
|
return parseInt(found.split(' ')[1], 0)
|
|
|
|
}
|
|
|
|
|
2023-01-04 10:07:58 -05:00
|
|
|
export async function reopenThread(projectId, threadId) {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/reopen`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function deleteThread(projectId, threadId) {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'delete',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function deleteMessage(projectId, threadId, messageId) {
|
2022-01-10 04:29:32 -05:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'delete',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}`,
|
|
|
|
})
|
|
|
|
}
|
2018-12-20 14:14:11 -05:00
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function destroyProject(projectId) {
|
2022-03-16 08:20:52 -04:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'delete',
|
|
|
|
url: `/project/${projectId}`,
|
|
|
|
})
|
|
|
|
}
|