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(
identifier: string,
key: string,
value: boolean = true,
expiry?: number,
now: Date = new Date()
): Promise<{ key: string }> {
const key = getKey(identifier, now);
expiry?: number
): Promise<void> {
const internalValue = value ? '1' : '0';
if (expiry == undefined) await redis.set(key, value ? '1' : '0');
else await redis.set(key, value ? '1' : '0', 'EX', expiry);
return { key };
if (expiry == undefined) await redis.set(key, internalValue);
else await redis.set(key, internalValue, 'EX', expiry);
}

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 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 } };
}