mirror of
https://github.com/Xevion/bus-reminder.git
synced 2025-12-09 08:06:50 -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(
|
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 };
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 } };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user