Fix ORM API usages in Token subclasses

This commit is contained in:
2026-07-22 22:26:26 -04:00
parent e11e39c23a
commit 1ef868e23c
3 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -95,7 +95,7 @@ class OtpToken extends Token {
} }
static async issue(uid, method) { static async issue(uid, method) {
const existing = await this.find({uid}); const existing = await this.list({where: {uid}});
for (const t of existing) { for (const t of existing) {
if (t.is_valid) await t.update({is_valid: false}); if (t.is_valid) await t.update({is_valid: false});
} }
@@ -104,7 +104,7 @@ class OtpToken extends Token {
} }
static async verify(uid, code) { static async verify(uid, code) {
const tokens = await this.listDetail({uid}); const tokens = await this.list({where: {uid}});
const match = tokens.find(t => t.is_valid && !t.isExpired && t.code === code); const match = tokens.find(t => t.is_valid && !t.isExpired && t.code === code);
if (!match) return null; if (!match) return null;
await match.update({is_valid: false}); await match.update({is_valid: false});
+2 -2
View File
@@ -203,7 +203,7 @@ router.post('/impersonate/:uid', middleware.auth, async function(req, res, next)
const target = await User.get(req.params.uid); const target = await User.get(req.params.uid);
// Clean up any existing impersonation for this target // Clean up any existing impersonation for this target
const existing = await ImpersonationToken.listDetail({ target_uid: target.uid }); const existing = await ImpersonationToken.list({where: { target_uid: target.uid }});
for (const old of existing) { for (const old of existing) {
if (old.is_valid && !old.isExpired) { if (old.is_valid && !old.isExpired) {
try { await target.removeTempPassword(old.temp_hash); } catch(_) {} try { await target.removeTempPassword(old.temp_hash); } catch(_) {}
@@ -237,7 +237,7 @@ router.delete('/impersonate/:uid', middleware.auth, async function(req, res, nex
await permission.byGroup(req.user, ['app_sso_admin']); await permission.byGroup(req.user, ['app_sso_admin']);
const target = await User.get(req.params.uid); const target = await User.get(req.params.uid);
const existing = await ImpersonationToken.listDetail({ target_uid: target.uid }); const existing = await ImpersonationToken.list({where: { target_uid: target.uid }});
let revoked = 0; let revoked = 0;
for (const token of existing) { for (const token of existing) {
+1 -1
View File
@@ -24,7 +24,7 @@ router.get('/', async function(req, res, next){
router.get('/:name', async function(req, res, next){ router.get('/:name', async function(req, res, next){
try{ try{
return res.json({ return res.json({
results: await tokens[req.params.name][req.query.detail ? "listDetail" : "list"]() results: await tokens[req.params.name].list({detail: !!req.query.detail})
}); });
}catch(error){ }catch(error){
next(error); next(error);