Refactor db.markIdentifier to receive and not generate key

This commit is contained in:
2023-09-05 12:28:56 -05:00
parent 9a9c676a74
commit 81b781aea1
2 changed files with 8 additions and 11 deletions

View File

@@ -33,15 +33,12 @@ export async function checkIdentifier(key: string): Promise<boolean> {
} }
export async function markIdentifier( export async function markIdentifier(
identifier: string, key: string,
value: boolean = true, value: boolean = true,
expiry?: number, expiry?: number
now: Date = new Date() ): Promise<void> {
): Promise<{ key: string }> { const internalValue = value ? '1' : '0';
const key = getKey(identifier, now);
if (expiry == undefined) await redis.set(key, value ? '1' : '0'); if (expiry == undefined) await redis.set(key, internalValue);
else await redis.set(key, value ? '1' : '0', 'EX', expiry); else await redis.set(key, internalValue, 'EX', expiry);
return { key };
} }

View File

@@ -72,9 +72,9 @@ export default async function handler(
} }
}; };
// Send notification, mark // Send notification, mark (expire in 1 month)
await sendNotification(`${matching.message} (${matching.name})`); await sendNotification(`${matching.message} (${matching.name})`);
await markIdentifier(matching.name, true, 60 * 60 * 24 * 31, now); await markIdentifier(key, true, 60 * 60 * 24 * 31);
return { status: 'notified', identifier: { name: matching.name, key } }; return { status: 'notified', identifier: { name: matching.name, key } };
} }