Merge pull request #18289 from overleaf/ac-ar-eslint-return-await

Add ESLint rule @typescript-eslint/return-await to backend services

GitOrigin-RevId: 75e3e32597827fcc852e69d479515fc72e8f45e4
This commit is contained in:
Andrew Rumble
2024-05-22 10:37:08 +01:00
committed by Copybot
parent 029cd4abe7
commit 71187a51ba
43 changed files with 1180 additions and 411 deletions

View File

@@ -7,7 +7,7 @@ import { ObjectId } from '../../mongodb.js'
const DEFAULT_MESSAGE_LIMIT = 50
const MAX_MESSAGE_LENGTH = 10 * 1024 // 10kb, about 1,500 words
async function readContext(context, req) {
function readContext(context, req) {
req.body = context.requestBody
req.params = context.params.path
req.query = context.params.query
@@ -23,6 +23,11 @@ async function readContext(context, req) {
}
}
/**
* @param context
* @param {(req: unknown, res: unknown) => Promise<unknown>} ControllerMethod
* @returns {Promise<*>}
*/
export async function callMessageHttpController(context, ControllerMethod) {
const req = {}
readContext(context, req)

View File

@@ -19,11 +19,15 @@ export async function getMessages(roomId, limit, before) {
query.timestamp = { $lt: before }
}
query = _ensureIdsAreObjectIds(query)
return db.messages.find(query).sort({ timestamp: -1 }).limit(limit).toArray()
return await db.messages
.find(query)
.sort({ timestamp: -1 })
.limit(limit)
.toArray()
}
export async function findAllMessagesInRooms(roomIds) {
return db.messages
return await db.messages
.find({
room_id: { $in: roomIds },
})

View File

@@ -37,7 +37,7 @@ export async function findOrCreateThread(projectId, threadId) {
}
export async function findAllThreadRooms(projectId) {
return db.rooms
return await db.rooms
.find(
{
project_id: new ObjectId(projectId.toString()),
@@ -52,7 +52,7 @@ export async function findAllThreadRooms(projectId) {
}
export async function findAllThreadRoomsAndGlobalThread(projectId) {
return db.rooms
return await db.rooms
.find(
{
project_id: new ObjectId(projectId.toString()),

View File

@@ -5,7 +5,7 @@ const request = Request.defaults({
})
async function asyncRequest(options) {
return new Promise((resolve, reject) => {
return await new Promise((resolve, reject) => {
request(options, (err, response, body) => {
if (err) {
reject(err)
@@ -17,7 +17,7 @@ async function asyncRequest(options) {
}
export async function sendGlobalMessage(projectId, userId, content) {
return asyncRequest({
return await asyncRequest({
method: 'post',
url: `/project/${projectId}/messages`,
json: {
@@ -28,7 +28,7 @@ export async function sendGlobalMessage(projectId, userId, content) {
}
export async function getGlobalMessages(projectId) {
return asyncRequest({
return await asyncRequest({
method: 'get',
url: `/project/${projectId}/messages`,
json: true,
@@ -36,7 +36,7 @@ export async function getGlobalMessages(projectId) {
}
export async function sendMessage(projectId, threadId, userId, content) {
return asyncRequest({
return await asyncRequest({
method: 'post',
url: `/project/${projectId}/thread/${threadId}/messages`,
json: {
@@ -47,7 +47,7 @@ export async function sendMessage(projectId, threadId, userId, content) {
}
export async function getThreads(projectId) {
return asyncRequest({
return await asyncRequest({
method: 'get',
url: `/project/${projectId}/threads`,
json: true,
@@ -55,7 +55,7 @@ export async function getThreads(projectId) {
}
export async function resolveThread(projectId, threadId, userId) {
return asyncRequest({
return await asyncRequest({
method: 'post',
url: `/project/${projectId}/thread/${threadId}/resolve`,
json: {
@@ -65,7 +65,7 @@ export async function resolveThread(projectId, threadId, userId) {
}
export async function getResolvedThreadIds(projectId) {
return asyncRequest({
return await asyncRequest({
method: 'get',
url: `/project/${projectId}/resolved-thread-ids`,
json: true,
@@ -73,7 +73,7 @@ export async function getResolvedThreadIds(projectId) {
}
export async function editMessage(projectId, threadId, messageId, content) {
return asyncRequest({
return await asyncRequest({
method: 'post',
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}/edit`,
json: {
@@ -89,7 +89,7 @@ export async function editMessageWithUser(
userId,
content
) {
return asyncRequest({
return await asyncRequest({
method: 'post',
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}/edit`,
json: {
@@ -100,7 +100,7 @@ export async function editMessageWithUser(
}
export async function checkStatus() {
return asyncRequest({
return await asyncRequest({
method: 'get',
url: `/status`,
json: true,
@@ -118,28 +118,28 @@ export async function getMetric(matcher) {
}
export async function reopenThread(projectId, threadId) {
return asyncRequest({
return await asyncRequest({
method: 'post',
url: `/project/${projectId}/thread/${threadId}/reopen`,
})
}
export async function deleteThread(projectId, threadId) {
return asyncRequest({
return await asyncRequest({
method: 'delete',
url: `/project/${projectId}/thread/${threadId}`,
})
}
export async function deleteMessage(projectId, threadId, messageId) {
return asyncRequest({
return await asyncRequest({
method: 'delete',
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}`,
})
}
export async function destroyProject(projectId) {
return asyncRequest({
return await asyncRequest({
method: 'delete',
url: `/project/${projectId}`,
})

View File

@@ -2,7 +2,8 @@
"extends": "../../tsconfig.backend.json",
"include": [
"app.js",
"app/src/**/*",
"app/js/**/*",
"config/**/*",
"scripts/**/*",
"test/**/*"
]