Fix findOneAnd* usages

findOneAnd* now returns either a document or null rather than a result
set (unless the result set is requested explicitly). See
https://www.mongodb.com/blog/post/behavioral-changes-find-one-family-apis-node-js-driver-6-0-0.

GitOrigin-RevId: 93dc64cbcc663217f914cf9e9821e2b9642154db
This commit is contained in:
andrew rumble
2024-09-24 08:06:28 +00:00
committed by Copybot
parent 5b1c0c5008
commit 5f699ac5ef
2 changed files with 6 additions and 11 deletions
@@ -7,7 +7,7 @@ const { callbackify } = require('util')
const ONE_HOUR_IN_S = 60 * 60
async function peekValueFromToken(use, token) {
const result = await db.tokens.findOneAndUpdate(
const tokenDoc = await db.tokens.findOneAndUpdate(
{
use,
token,
@@ -22,8 +22,6 @@ async function peekValueFromToken(use, token) {
returnDocument: 'after',
}
)
const tokenDoc = result.value
if (!tokenDoc) {
throw new Errors.NotFoundError('no token found')
}
@@ -82,11 +80,10 @@ const OneTimeTokenHandler = {
usedAt: now,
},
},
function (error, result) {
function (error, token) {
if (error) {
return callback(error)
}
const token = result.value
if (!token) {
return callback(new Errors.NotFoundError('no token found'))
}