Browse Source

bugfix: issue when getting covid positivity of new user

pull/13/head
Nareshkumar Rao 3 years ago
parent
commit
b9fe3b8d55
  1. 1
      src/db/models/User.helper.ts
  2. 2
      src/routes/CovidRoute.ts

1
src/db/models/User.helper.ts

@ -39,6 +39,7 @@ export async function getUserCovidPositivity(
): Promise<boolean> { ): Promise<boolean> {
const user = await getUserByTelegramID(telegramID); const user = await getUserByTelegramID(telegramID);
if (!user) throw new Error("User not found"); if (!user) throw new Error("User not found");
if (!user.infectionDate) return false;
const infectionDuration = new Date().getTime() - user.infectionDate.getTime(); const infectionDuration = new Date().getTime() - user.infectionDate.getTime();
if (infectionDuration > 60 * 60 * 24 * 14 * 1000) { if (infectionDuration > 60 * 60 * 24 * 14 * 1000) {
await setUserCovidPositivity(telegramID, false); await setUserCovidPositivity(telegramID, false);

2
src/routes/CovidRoute.ts

@ -27,7 +27,7 @@ export async function CovidRoute(req: CovidRouteRequest, res: Response) {
} }
} catch (error) { } catch (error) {
res res
.send(500)
.status(500)
.send({ error: error instanceof Error ? error.message : "Error" }); .send({ error: error instanceof Error ? error.message : "Error" });
} }
} }

Loading…
Cancel
Save