From cb7f45a0c44e7bcf4a98857f7edd4777b7cd525e Mon Sep 17 00:00:00 2001 From: charlesdoiron Date: Mon, 15 Apr 2024 10:55:12 +0200 Subject: [PATCH] fix: remove drinking water logic --- api-node/src/controllers/indicators.ts | 26 ++++---- api-node/src/controllers/user.ts | 87 +++++++++++-------------- api-node/src/cronjobs/aggregators.ts | 26 ++++---- api-node/src/getters/indicators_list.ts | 1 + 4 files changed, 66 insertions(+), 74 deletions(-) diff --git a/api-node/src/controllers/indicators.ts b/api-node/src/controllers/indicators.ts index 92c3e64c..858378e5 100644 --- a/api-node/src/controllers/indicators.ts +++ b/api-node/src/controllers/indicators.ts @@ -12,7 +12,7 @@ import { indicatorsList } from '~/getters/indicators_list'; import { withUser } from '~/middlewares/auth'; import utc from 'dayjs/plugin/utc'; import { getBathingWaterFromMunicipalityAndDate } from '~/getters/bathing_water'; -import { getDrinkingWaterFromUdi } from '~/getters/drinking_water'; +// import { getDrinkingWaterFromUdi } from '~/getters/drinking_water'; import { IndicatorsSlugEnum } from '@prisma/client'; dayjs.extend(utc); @@ -109,18 +109,18 @@ router.get( if (bathingWater) indicators.push(bathingWater); - if (Number(req.user.appbuild) > 62) { - const drinkingWater = await getDrinkingWaterFromUdi({ - udi: req.user.udi, - municipality_insee_code, - date_UTC_ISO: dayjs().utc().toISOString(), - }); - if (drinkingWater instanceof Error) { - next(drinkingWater); - return; - } - if (drinkingWater) indicators.push(drinkingWater); - } + // if (Number(req.user.appbuild) > 62) { + // const drinkingWater = await getDrinkingWaterFromUdi({ + // udi: req.user.udi, + // municipality_insee_code, + // date_UTC_ISO: dayjs().utc().toISOString(), + // }); + // if (drinkingWater instanceof Error) { + // next(drinkingWater); + // return; + // } + // if (drinkingWater) indicators.push(drinkingWater); + // } res.status(200).send({ ok: true, data: indicators }); }, diff --git a/api-node/src/controllers/user.ts b/api-node/src/controllers/user.ts index 1ff89e94..bc3e31d8 100644 --- a/api-node/src/controllers/user.ts +++ b/api-node/src/controllers/user.ts @@ -3,14 +3,9 @@ import { z } from 'zod'; import { catchErrors } from '../middlewares/errors'; import prisma from '../prisma.js'; import { type CustomError } from '~/types/error'; -import { - type User, - type udis as UdiType, - GranularityEnum, -} from '@prisma/client'; +import { type User } from '@prisma/client'; import { withUser } from '~/middlewares/auth.js'; import type { RequestWithUser } from '~/types/request'; -import { UdiService } from '~/service/udi.js'; const router = express.Router(); router.post( @@ -108,48 +103,44 @@ router.put( if (bodyHasProperty('granularity')) { updatedUser.granularity = req.body.granularity; } - if (bodyHasProperty('coordinates')) { - let userUdis: UdiType[] = []; - - if (req.body.coordinates.lat && req.body.coordinates.lon) { - const longitude = parseFloat(req.body.coordinates.lon); - const latitude = parseFloat(req.body.coordinates.lat); - - if (req.body.granularity === GranularityEnum.street) { - userUdis = await UdiService.findUdiByCoordinates( - latitude, - longitude, - ); - - if (userUdis?.length) { - updatedUser.udi = userUdis[0].code_udi; - } - } - if (req.body.granularity === GranularityEnum.city) { - // Some cities have multiple UDI, we need to check if we have multiple UDI for the city - const udisCount = await UdiService.countUdisByMunicipalityInseeCode( - req.body.municipality_insee_code, - ); - - if (udisCount === 0) { - updatedUser.udi = null; - } - if (udisCount === 1) { - userUdis = await UdiService.findUdiByCoordinates( - latitude, - longitude, - ); - // If we have a single UDI for the city, we can set it directly and send data to the user - if (userUdis?.length) { - updatedUser.udi = userUdis[0].code_udi; - } - } - if (udisCount > 1) { - updatedUser.udi = 'multiple'; - } - } - } - } + // if (bodyHasProperty('coordinates')) { + // let userUdis: UdiType[] = []; + // if (req.body.coordinates.lat && req.body.coordinates.lon) { + // const longitude = parseFloat(req.body.coordinates.lon); + // const latitude = parseFloat(req.body.coordinates.lat); + // if (req.body.granularity === GranularityEnum.street) { + // userUdis = await UdiService.findUdiByCoordinates( + // latitude, + // longitude, + // ); + // if (userUdis?.length) { + // updatedUser.udi = userUdis[0].code_udi; + // } + // } + // if (req.body.granularity === GranularityEnum.city) { + // // Some cities have multiple UDI, we need to check if we have multiple UDI for the city + // const udisCount = await UdiService.countUdisByMunicipalityInseeCode( + // req.body.municipality_insee_code, + // ); + // if (udisCount === 0) { + // updatedUser.udi = null; + // } + // if (udisCount === 1) { + // userUdis = await UdiService.findUdiByCoordinates( + // latitude, + // longitude, + // ); + // // If we have a single UDI for the city, we can set it directly and send data to the user + // if (userUdis?.length) { + // updatedUser.udi = userUdis[0].code_udi; + // } + // } + // if (udisCount > 1) { + // updatedUser.udi = 'multiple'; + // } + // } + // } + // } if (bodyHasProperty('push_notif_token')) { updatedUser.push_notif_token = req.body.push_notif_token; } diff --git a/api-node/src/cronjobs/aggregators.ts b/api-node/src/cronjobs/aggregators.ts index c0151f79..c61f214e 100644 --- a/api-node/src/cronjobs/aggregators.ts +++ b/api-node/src/cronjobs/aggregators.ts @@ -5,7 +5,7 @@ import { setupCronJob } from './utils'; import { capture } from '~/third-parties/sentry'; import { getWeatherAlert } from '~/aggregators/weather_alert'; import { getBathingWaterIndicator } from '~/aggregators/bathing_water'; -import { getDrinkingWaterIndicator } from '~/aggregators/drinking_water'; +// import { getDrinkingWaterIndicator } from '~/aggregators/drinking_water'; /* * @@ -22,18 +22,18 @@ Test it: run `npm run dev-cronjobs` and check the logs export async function initAggregators() { await Promise.resolve() - .then(() => { - console.log('Inside aggregators cronjobs'); - }) - .then( - async () => - await setupCronJob({ - name: 'Drinking Water', - cronTime: '10 10,22 * * *', // every day at 10:10am and 10:10pm - job: getDrinkingWaterIndicator, - runOnInit: true, - }), - ) + // .then(() => { + // console.log('Inside aggregators cronjobs'); + // }) + // .then( + // async () => + // await setupCronJob({ + // name: 'Drinking Water', + // cronTime: '10 10,22 * * *', // every day at 10:10am and 10:10pm + // job: getDrinkingWaterIndicator, + // runOnInit: true, + // }), + // ) .then( async () => await setupCronJob({ diff --git a/api-node/src/getters/indicators_list.ts b/api-node/src/getters/indicators_list.ts index 8f63cb7e..abce5615 100644 --- a/api-node/src/getters/indicators_list.ts +++ b/api-node/src/getters/indicators_list.ts @@ -41,6 +41,7 @@ const indicatorsObject: Record = { long_name: "La qualité de l'eau du robinet", short_name: 'Eau du robinet', slug: IndicatorsSlugEnum.drinking_water, + active: false, }, };