2022-12-13 12:37:49 +00:00
|
|
|
import Request from 'request'
|
|
|
|
|
|
|
|
const request = Request.defaults({
|
2021-07-13 11:04:48 +00:00
|
|
|
baseUrl: 'http://localhost:3010',
|
2018-12-20 19:14:11 +00:00
|
|
|
})
|
2016-12-14 17:38:14 +00:00
|
|
|
|
2022-01-10 09:29:32 +00: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 12:37:49 +00:00
|
|
|
export async function sendGlobalMessage(projectId, userId, content) {
|
2022-01-10 09:29:32 +00:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/messages`,
|
|
|
|
json: {
|
|
|
|
user_id: userId,
|
|
|
|
content,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2016-12-16 16:52:50 +00:00
|
|
|
|
2022-12-13 12:37:49 +00:00
|
|
|
export async function getGlobalMessages(projectId) {
|
2022-01-10 09:29:32 +00:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'get',
|
|
|
|
url: `/project/${projectId}/messages`,
|
|
|
|
json: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-12-13 12:37:49 +00:00
|
|
|
export async function sendMessage(projectId, threadId, userId, content) {
|
2022-01-10 09:29:32 +00:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages`,
|
|
|
|
json: {
|
|
|
|
user_id: userId,
|
|
|
|
content,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2017-01-04 13:51:08 +00:00
|
|
|
|
2022-12-13 12:37:49 +00:00
|
|
|
export async function getThreads(projectId) {
|
2022-01-10 09:29:32 +00:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'get',
|
|
|
|
url: `/project/${projectId}/threads`,
|
|
|
|
json: true,
|
|
|
|
})
|
|
|
|
}
|
2017-01-24 14:44:32 +00:00
|
|
|
|
2022-12-13 12:37:49 +00:00
|
|
|
export async function resolveThread(projectId, threadId, userId) {
|
2022-01-10 09:29:32 +00:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/resolve`,
|
|
|
|
json: {
|
|
|
|
user_id: userId,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2017-01-24 14:44:32 +00:00
|
|
|
|
2022-12-13 12:37:49 +00:00
|
|
|
export async function editMessage(projectId, threadId, messageId, content) {
|
2022-01-10 09:29:32 +00:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}/edit`,
|
|
|
|
json: {
|
|
|
|
content,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2018-12-20 19:14:11 +00:00
|
|
|
|
2022-12-13 12:37:49 +00:00
|
|
|
export async function editMessageWithUser(
|
2022-03-31 07:54:33 +00:00
|
|
|
projectId,
|
|
|
|
threadId,
|
|
|
|
messageId,
|
|
|
|
userId,
|
|
|
|
content
|
|
|
|
) {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}/edit`,
|
|
|
|
json: {
|
|
|
|
content,
|
|
|
|
userId,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-04 15:07:58 +00:00
|
|
|
export async function checkStatus() {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'get',
|
|
|
|
url: `/status`,
|
|
|
|
json: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-05 11:42:34 +00: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 15:07:58 +00: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 12:37:49 +00:00
|
|
|
export async function deleteMessage(projectId, threadId, messageId) {
|
2022-01-10 09:29:32 +00:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'delete',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}`,
|
|
|
|
})
|
|
|
|
}
|
2018-12-20 19:14:11 +00:00
|
|
|
|
2022-12-13 12:37:49 +00:00
|
|
|
export async function destroyProject(projectId) {
|
2022-03-16 12:20:52 +00:00
|
|
|
return asyncRequest({
|
|
|
|
method: 'delete',
|
|
|
|
url: `/project/${projectId}`,
|
|
|
|
})
|
|
|
|
}
|