2018-12-20 14:14:11 -05:00
|
|
|
const request = require('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 })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function sendGlobalMessage(projectId, userId, content) {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/messages`,
|
|
|
|
json: {
|
|
|
|
user_id: userId,
|
|
|
|
content,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2016-12-16 11:52:50 -05:00
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
async function getGlobalMessages(projectId) {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'get',
|
|
|
|
url: `/project/${projectId}/messages`,
|
|
|
|
json: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function sendMessage(projectId, threadId, userId, content) {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages`,
|
|
|
|
json: {
|
|
|
|
user_id: userId,
|
|
|
|
content,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2017-01-04 08:51:08 -05:00
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
async function getThreads(projectId) {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'get',
|
|
|
|
url: `/project/${projectId}/threads`,
|
|
|
|
json: true,
|
|
|
|
})
|
|
|
|
}
|
2017-01-24 09:44:32 -05:00
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
async function resolveThread(projectId, threadId, userId) {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/resolve`,
|
|
|
|
json: {
|
|
|
|
user_id: userId,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2017-01-24 09:44:32 -05:00
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
async function reopenThread(projectId, threadId) {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/reopen`,
|
|
|
|
})
|
|
|
|
}
|
2017-01-24 09:44:32 -05:00
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
async function deleteThread(projectId, threadId) {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'delete',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}`,
|
|
|
|
})
|
|
|
|
}
|
2018-12-20 14:14:11 -05:00
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
async function editMessage(projectId, threadId, messageId, content) {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}/edit`,
|
|
|
|
json: {
|
|
|
|
content,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2018-12-20 14:14:11 -05:00
|
|
|
|
2022-03-31 03:54:33 -04:00
|
|
|
async function editMessageWithUser(
|
|
|
|
projectId,
|
|
|
|
threadId,
|
|
|
|
messageId,
|
|
|
|
userId,
|
|
|
|
content
|
|
|
|
) {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}/edit`,
|
|
|
|
json: {
|
|
|
|
content,
|
|
|
|
userId,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
async function deleteMessage(projectId, threadId, messageId) {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'delete',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}`,
|
|
|
|
})
|
|
|
|
}
|
2018-12-20 14:14:11 -05:00
|
|
|
|
2022-03-16 08:20:52 -04:00
|
|
|
async function destroyProject(projectId) {
|
|
|
|
return asyncRequest({
|
|
|
|
method: 'delete',
|
|
|
|
url: `/project/${projectId}`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
module.exports = {
|
|
|
|
sendGlobalMessage,
|
|
|
|
getGlobalMessages,
|
|
|
|
sendMessage,
|
|
|
|
getThreads,
|
|
|
|
resolveThread,
|
|
|
|
reopenThread,
|
|
|
|
deleteThread,
|
|
|
|
editMessage,
|
2022-03-31 03:54:33 -04:00
|
|
|
editMessageWithUser,
|
2022-01-10 04:29:32 -05:00
|
|
|
deleteMessage,
|
2022-03-16 08:20:52 -04:00
|
|
|
destroyProject,
|
2018-12-20 14:14:11 -05:00
|
|
|
}
|