mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-24 01:29:35 +02:00
Add script for resolving comments GitOrigin-RevId: 9445b23f401083d12b13f6f093bbdc866722aa8c
47 lines
1010 B
JavaScript
47 lines
1010 B
JavaScript
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)
|