Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove drinking water logic #527

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions api-node/src/controllers/indicators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 });
},
Expand Down
87 changes: 39 additions & 48 deletions api-node/src/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
Expand Down
26 changes: 13 additions & 13 deletions api-node/src/cronjobs/aggregators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/*
*
Expand All @@ -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({
Expand Down
1 change: 1 addition & 0 deletions api-node/src/getters/indicators_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const indicatorsObject: Record<IndicatorsSlugEnum, IndicatorItem> = {
long_name: "La qualité de l'eau du robinet",
short_name: 'Eau du robinet',
slug: IndicatorsSlugEnum.drinking_water,
active: false,
},
};

Expand Down
Loading