refactor habit compete
This commit is contained in:
parent
19b7f5d93d
commit
f0177d31c0
|
|
@ -8,6 +8,16 @@ interface CompletionResponse {
|
||||||
updatedCoins: number;
|
updatedCoins: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Date object for the start of a given day in UTC.
|
||||||
|
* This is duplicated here as per the instruction not to create new shared utilities.
|
||||||
|
*/
|
||||||
|
function getStartOfDay(date: Date): Date {
|
||||||
|
const startOfDay = new Date(date);
|
||||||
|
startOfDay.setUTCHours(0, 0, 0, 0);
|
||||||
|
return startOfDay;
|
||||||
|
}
|
||||||
|
|
||||||
export default defineEventHandler(async (event): Promise<CompletionResponse> => {
|
export default defineEventHandler(async (event): Promise<CompletionResponse> => {
|
||||||
const userId = await getUserIdFromSession(event);
|
const userId = await getUserIdFromSession(event);
|
||||||
const habitId = parseInt(event.context.params?.id || '', 10);
|
const habitId = parseInt(event.context.params?.id || '', 10);
|
||||||
|
|
@ -31,8 +41,7 @@ export default defineEventHandler(async (event): Promise<CompletionResponse> =>
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalize date to the beginning of the day for consistent checks
|
// Normalize date to the beginning of the day for consistent checks
|
||||||
const startOfToday = new Date();
|
const startOfToday = getStartOfDay(new Date()); // Correctly get a Date object
|
||||||
startOfToday.setUTCHours(0, 0, 0, 0);
|
|
||||||
|
|
||||||
const existingCompletion = await prisma.habitCompletion.findFirst({
|
const existingCompletion = await prisma.habitCompletion.findFirst({
|
||||||
where: {
|
where: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user