fix setCountdown API
This commit is contained in:
		@@ -389,10 +389,17 @@ export const setCountdown = async (userId: number, countdown: Countdown) => {
 | 
				
			|||||||
    const relationship = await getRelationship(userId);
 | 
					    const relationship = await getRelationship(userId);
 | 
				
			||||||
    if (!relationship) throw new Error("Relationship not found");
 | 
					    if (!relationship) throw new Error("Relationship not found");
 | 
				
			||||||
    const existingCountdown: Countdown | null = await getCountdown(userId);
 | 
					    const existingCountdown: Countdown | null = await getCountdown(userId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Ensure the date is a valid Date object
 | 
				
			||||||
 | 
					    const countdownDate = new Date(countdown.date);
 | 
				
			||||||
 | 
					    if (isNaN(countdownDate.getTime())) {
 | 
				
			||||||
 | 
					      throw new Error("Invalid date provided");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let result;
 | 
					    let result;
 | 
				
			||||||
    if (existingCountdown !== null) {
 | 
					    if (existingCountdown !== null) {
 | 
				
			||||||
      result = await db.update(schema.countdowns)
 | 
					      result = await db.update(schema.countdowns)
 | 
				
			||||||
        .set({ title: countdown.title, date: countdown.date })
 | 
					        .set({ title: countdown.title, date: countdownDate })
 | 
				
			||||||
        .where(eq(schema.countdowns.id, existingCountdown.id))
 | 
					        .where(eq(schema.countdowns.id, existingCountdown.id))
 | 
				
			||||||
        .returning();
 | 
					        .returning();
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
@@ -400,7 +407,7 @@ export const setCountdown = async (userId: number, countdown: Countdown) => {
 | 
				
			|||||||
        .values({
 | 
					        .values({
 | 
				
			||||||
          relationshipId: relationship.id,
 | 
					          relationshipId: relationship.id,
 | 
				
			||||||
          title: countdown.title,
 | 
					          title: countdown.title,
 | 
				
			||||||
          date: countdown.date,
 | 
					          date: countdownDate,
 | 
				
			||||||
        }).returning();
 | 
					        }).returning();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return result[0] as Countdown;
 | 
					    return result[0] as Countdown;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user