type changes

This commit is contained in:
DirkSchlossmacher 2023-11-14 10:52:02 +01:00
parent 35c6263560
commit e3a6787f06

View File

@ -74,15 +74,11 @@ export const getAvailableDateKeys = async (): Promise<string[]> => {
export const getSignInCountForPeriod = async (dateKey: string): Promise<number> => {
try {
const counts = await redis.hgetall(`signin_count:${dateKey}`);
// Explicitly cast the result of redis.hgetall to an object with string values.
const counts = await redis.hgetall(`signin_count:${dateKey}`) as Record<string, string>;
return Object.values(counts).reduce((total, count) => {
// Ensure that 'count' is a string before parsing it to an integer.
if (typeof count === 'string') {
return total + parseInt(count, 10);
} else {
console.error(`Count value is not a string: ${count}`);
return total;
}
// Now TypeScript knows that 'count' is a string.
return total + parseInt(count, 10);
}, 0);
} catch (error) {
console.error(`Failed to get sign-in count for period ${dateKey}`, error);
@ -91,6 +87,7 @@ export const getSignInCountForPeriod = async (dateKey: string): Promise<number>
};
export const getDetailsByUser = async (dateKey: string): Promise<Record<string, number>> => {
try {
const rawCounts = await redis.hgetall(`signin_count:${dateKey}`);