mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 09:09:36 +02:00
Merge pull request #27711 from overleaf/em-resolve-comment-script
Add script for resolving comments GitOrigin-RevId: 9445b23f401083d12b13f6f093bbdc866722aa8c
This commit is contained in:
46
services/chat/scripts/resolve-comment.mjs
Normal file
46
services/chat/scripts/resolve-comment.mjs
Normal file
@@ -0,0 +1,46 @@
|
||||
import { ObjectId } from 'mongodb'
|
||||
import { db } from '../app/js/mongodb.js'
|
||||
|
||||
const OPTS = parseArgs()
|
||||
|
||||
function parseArgs() {
|
||||
const args = process.argv.slice(2)
|
||||
if (args.length !== 3) {
|
||||
usage()
|
||||
process.exit(1)
|
||||
}
|
||||
const [roomId, userId, timestamp] = args
|
||||
return { roomId, userId, timestamp: new Date(timestamp) }
|
||||
}
|
||||
|
||||
function usage() {
|
||||
console.error('Usage: resolve-comment.mjs ROOM_ID USER_ID TIMESTAMP')
|
||||
}
|
||||
|
||||
async function resolveComment(roomId, userId, timestamp) {
|
||||
const result = await db.rooms.updateOne(
|
||||
{ _id: new ObjectId(roomId) },
|
||||
{
|
||||
$set: {
|
||||
resolved: {
|
||||
user_id: userId, // this is a string in Mongo
|
||||
ts: timestamp,
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
if (result.matchedCount === 0) {
|
||||
console.log(`Room not found: ${roomId}`)
|
||||
} else {
|
||||
console.log(`Comment resolved: room ${roomId}`)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await resolveComment(OPTS.roomId, OPTS.userId, OPTS.timestamp)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
}
|
||||
process.exit(0)
|
||||
Reference in New Issue
Block a user