Skip to content

Commit

Permalink
Merge pull request #60 from betagouv/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
theolemague authored Feb 26, 2025
2 parents 36c7d6c + 9ec29d7 commit 4b1f9d7
Show file tree
Hide file tree
Showing 32 changed files with 581 additions and 523 deletions.
33 changes: 0 additions & 33 deletions .github/workflows/deploy-api-staging.yml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/deploy-app-staging.yml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/deploy-widget-benevolat-staging.yml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/deploy-widget-volontariat-staging.yml

This file was deleted.

3 changes: 2 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"dev": "nodemon",
"start-dev": "ts-node src/index.ts",
"stop": "pm2 stop api",
"start": "pm2 start dist/index.js --name api",
"start": "npm run build && node dist/index.js",
"start-pm2": "pm2 start dist/index.js --name api",
"prettier": "prettier --write . --plugin=prettier-plugin-organize-imports",
"reload": "pm2 reload api"
},
Expand Down
1 change: 0 additions & 1 deletion api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const ADMIN_SNU_URL = "https://admin.snu.gouv.fr";
export const ES_ENDPOINT = process.env.ES_ENDPOINT;
export const DB_ENDPOINT = process.env.DB_ENDPOINT;
export const MISSION_INDEX = "mission";
export const RNA_INDEX = "rna";
export const ASSOS_INDEX = "association";
export const STATS_INDEX = "stats";

Expand Down
42 changes: 30 additions & 12 deletions api/src/controllers/iframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,46 +229,63 @@ router.get("/widget/:widgetId/msearch", async (req: Request, res: Response, next
// If location is set in widget, show only missions in this location
if (widget.location && widget.location.lat && widget.location.lon) {
const distance = getDistanceKm(widget.distance && widget.distance !== "Aucun" ? widget.distance : "50km");
where.geoPoint = { $nearSphere: { $geometry: { type: "Point", coordinates: [widget.location.lon, widget.location.lat] }, $maxDistance: distance * 1000 } };
whereAggs.geoPoint = { $geoWithin: { $centerSphere: [[widget.location.lon, widget.location.lat], distance / EARTH_RADIUS] } };
// If location is set in query, check if remote is set or no
where["addresses.geoPoint"] = {
$nearSphere: {
$geometry: { type: "Point", coordinates: [widget.location.lon, widget.location.lat] },
$maxDistance: distance * 1000,
},
};
whereAggs["addresses.geoPoint"] = {
$geoWithin: {
$centerSphere: [[widget.location!.lon, widget.location!.lat], distance / EARTH_RADIUS],
},
};
} else if (query.data.lat && query.data.lon) {
const distance = getDistanceKm("50km");
// For the aggs, we don't need to check if the remote is set or no, we want all the remote facets
whereAggs.$and.push({
$or: [{ geoPoint: { $geoWithin: { $centerSphere: [[query.data.lon, query.data.lat], distance / EARTH_RADIUS] } } }, { remote: "full" }],
$or: [{ "addresses.geoPoint": { $geoWithin: { $centerSphere: [[query.data.lon, query.data.lat], distance / EARTH_RADIUS] } } }, { remote: "full" }],
});
// If remote is set to no, show only missions in this location
if (query.data.remote && query.data.remote.includes("no") && !query.data.remote.includes("yes")) {
where.geoPoint = { $nearSphere: { $geometry: { type: "Point", coordinates: [query.data.lon, query.data.lat] }, $maxDistance: distance * 1000 } };
// If remote is set to yes, show only remote missions
where.remote = "no";
where["addresses.geoPoint"] = {
$nearSphere: {
$geometry: { type: "Point", coordinates: [query.data.lon, query.data.lat] },
$maxDistance: distance * 1000,
},
};
} else if (query.data.remote && query.data.remote.includes("yes") && !query.data.remote.includes("no")) {
where.remote = "full";
// Else show missions in this location and remote once
} else {
// $near not accepted in $and or $or
where.$and.push({
$or: [{ geoPoint: { $geoWithin: { $centerSphere: [[query.data.lon, query.data.lat], distance / EARTH_RADIUS] } } }, { remote: "full" }],
$or: [{ "addresses.geoPoint": { $geoWithin: { $centerSphere: [[query.data.lon, query.data.lat], distance / EARTH_RADIUS] } } }, { remote: "full" }],
});
}
// No location set, check if remote is set or no
} else {
if (query.data.remote && query.data.remote.includes("yes") && !query.data.remote.includes("no")) {
where.remote = "full";
where.$and.push({ $or: [{ remote: "full" }, { remote: "possible" }] });
}
if (query.data.remote && query.data.remote.includes("no") && !query.data.remote.includes("yes")) {
where.$and.push({ $or: [{ remote: "no" }, { remote: "possible" }] });
where.remote = "no";
}
}

// When converting geoPoint for count
if (where["addresses.geoPoint"]) {
const geoWithin = whereAggs.$or ? whereAggs.$or : [{ "addresses.geoPoint": whereAggs["addresses.geoPoint"] }];
delete where["addresses.geoPoint"];
where.$or = geoWithin;
}

if (!where.$and.length) delete where.$and;
if (!where.$or.length) delete where.$or;
if (!whereAggs.$and.length) delete whereAggs.$and;
if (!whereAggs.$or.length) delete whereAggs.$or;

const missions = await MissionModel.find(where).sort({ remote: -1 }).limit(query.data.size).skip(query.data.from).lean();

if (where.geoPoint) where.geoPoint = whereAggs.geoPoint; // $nearSphere is not supported in countDocuments
const total = await MissionModel.countDocuments(where);
const facets = await MissionModel.aggregate([{ $match: whereAggs }, { $facet }]);

Expand All @@ -285,6 +302,7 @@ router.get("/widget/:widgetId/msearch", async (req: Request, res: Response, next
postalCode: e.postalCode,
places: e.places,
tags: e.tags,
addresses: e.addresses,
})),
aggs: {},
} as { [key: string]: any };
Expand Down
18 changes: 17 additions & 1 deletion api/src/models/mission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ const geoPointSchema = new Schema({
},
});

const addressesSchema = new Schema({
street: { type: String },
postalCode: { type: String },
departmentName: { type: String },
departmentCode: { type: String },
city: { type: String },
region: { type: String },
country: { type: String },
location: {
lat: { type: Number },
lon: { type: Number },
},
geoPoint: { type: geoPointSchema, default: null },
});

const schema = new Schema<Mission>(
{
// Identifiers
Expand Down Expand Up @@ -63,7 +78,7 @@ const schema = new Schema<Mission>(
lat: { type: Number },
lon: { type: Number },
},
geoPoint: { type: geoPointSchema, default: null },
addresses: { type: [addressesSchema], default: [] },

// Organisation
organizationId: { type: String },
Expand Down Expand Up @@ -175,6 +190,7 @@ schema.index({ departmentName: 1 });
schema.index({ organizationName: 1 });
schema.index({ organizationRNA: 1 });
schema.index({ geoPoint: "2dsphere" });
schema.index({ "addresses.geoPoint": "2dsphere" });

const MissionModel = model<Mission>(MODELNAME, schema);
export default MissionModel;
19 changes: 19 additions & 0 deletions api/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,25 @@ export interface Mission {
coordinates: [number, number];
}
| undefined;

addresses: {
street: string | undefined;
postalCode: string | undefined;
departmentName: string | undefined;
departmentCode: string | undefined;
city: string | undefined;
region: string | undefined;
country: string | undefined;
location: {
lat: number | undefined;
lon: number | undefined;
};
geoPoint: {
type: "Point";
coordinates: [number, number] | undefined;
};
}[];

snu: boolean | undefined;
snuPlaces: number | undefined;
remote: "no" | "possible" | "full";
Expand Down
8 changes: 4 additions & 4 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
"type": "module",
"scripts": {
"dev": "vite",
"start-dev": "node server/index.js",
"start": "pm2 start server/index.js --name app",
"stop": "pm2 stop app",
"build": "vite build",
"start": "node server/index.js",
"start-pm2": "pm2 start server/index.js --name app",
"stop": "pm2 stop app",
"prettier": "prettier --write .",
"reload": "pm2 reload app"
},
"devDependencies": {
"@vitejs/plugin-react": "^4.3.1",
"autoprefixer": "^10.4.20",
"dotenv": "^16.4.5",
"dotenv": "^16.4.7",
"express": "^4.21.0",
"hsts": "^2.2.0",
"postcss": "^8.4.45",
Expand Down
1 change: 1 addition & 0 deletions app/server/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "dotenv/config";
import express from "express";
import path from "path";
import { fileURLToPath } from "url";
Expand Down
1 change: 0 additions & 1 deletion process/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const ES_ENDPOINT = process.env.ES_ENDPOINT;
export const DB_ENDPOINT = process.env.DB_ENDPOINT;
export const STATS_INDEX = "stats";
export const MISSION_INDEX = "mission";
export const RNA_INDEX = "rna";

export const SENTRY_DSN = process.env.SENTRY_DSN;

Expand Down
6 changes: 2 additions & 4 deletions process/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,11 @@ const leboncoinJob = new CronJob(

// Every first Tuesday of the month at 10:00 AM
const reportJob = new CronJob(
// "0 10 * * 2",
"0 10 * * 4",
"0 10 * * 2",
async () => {
// if not the first Tuesday of the month, return
const date = new Date();
// if (date.getDay() !== 2 || date.getDate() > 7) return;
if (date.getDay() !== 4 || date.getDate() > 7) return; // Temporary to Thursday
if (date.getDay() !== 2 || date.getDate() > 7) return;

runnings.report = true;
const checkInId = Sentry.captureCheckIn({
Expand Down
Loading

0 comments on commit 4b1f9d7

Please # to comment.