mirror of
https://github.com/Xevion/bus-reminder.git
synced 2025-12-06 01:14:30 -06:00
Refactor db.markIdentifier to receive and not generate key
This commit is contained in:
15
src/db.ts
15
src/db.ts
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 } };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user