Skip to content

Commit 111f105

Browse files
flacombeGllmR
andauthored
Ajout d'un export du changelog des projets (#464)
* Ajout d'un export du changelog des projets * Removes migration script call --------- Co-authored-by: GllmR <56537238+GllmR@users.noreply.github.com> Co-authored-by: Guillaume <guillaume@livingdata.co>
1 parent 1d0a49c commit 111f105

File tree

5 files changed

+46
-16
lines changed

5 files changed

+46
-16
lines changed

backend/export/csv.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import Wellknown from 'wellknown'
55
import {getProjets} from '../lib/models/projets.js'
66
import {buildGeometryFromTerritoires} from '../lib/territoires.js'
77
import {findClosestEtape} from '../../shared/find-closest-etape.js'
8+
import {getUpdatedProjets} from '../admin/reports.js'
9+
10+
import {getUpdateStatus} from '../../lib/utils/projet.js'
811

912
async function computeWkt(perimetres) {
1013
const perimetresGeojson = await buildGeometryFromTerritoires(perimetres)
@@ -121,6 +124,19 @@ export async function exportSubventionsAsCSV() {
121124
return Papa.unparse(rows)
122125
}
123126

127+
export async function exportProjectsChangeLog(since) {
128+
const changes = await getUpdatedProjets(Number.isNaN(since.valueOf()) ? new Date('2010-01-01') : since)
129+
130+
const rows = changes.map(change => ({
131+
ref_projet: change._id,
132+
nom_projet: change.nom,
133+
action: getUpdateStatus(change),
134+
update_date: change._updated
135+
}))
136+
137+
return Papa.unparse(rows)
138+
}
139+
124140
export async function exportEditorKeys() {
125141
const projets = await getProjets()
126142
const rows = projets.map(projet => ({

backend/routes/data.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import express from 'express'
22
import {ensureAdmin} from '../auth/middleware.js'
33
import w from '../util/w.js'
44

5-
import {exportProjetsAsCSV, exportLivrablesAsCSV, exportToursDeTableAsCSV, exportSubventionsAsCSV, exportEditorKeys} from '../export/csv.js'
5+
import {exportProjetsAsCSV, exportLivrablesAsCSV, exportToursDeTableAsCSV, exportSubventionsAsCSV, exportProjectsChangeLog, exportEditorKeys} from '../export/csv.js'
66
import {computeDallesGeoJSON, computeLivrablesGeoJSON} from '../export/stockage.js'
77

88
const dataRoutes = new express.Router()
@@ -43,6 +43,12 @@ dataRoutes.get('/stockages/dalles.geojson', w(async (req, res) => {
4343
res.attachment('dalles.geojson').send(dallesGeoJSON)
4444
}))
4545

46+
dataRoutes.get('/changes.csv', w(async (req, res) => {
47+
const projectChanges = await exportProjectsChangeLog(new Date(req.query.since))
48+
49+
res.attachment('changes.csv').type('csv').send(projectChanges)
50+
}))
51+
4652
dataRoutes.get('/editor-keys.csv', w(ensureAdmin), w(async (req, res) => {
4753
const editorKeysCSVFile = await exportEditorKeys()
4854

components/gestion-admin/changes.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ import {fr} from 'date-fns/locale'
77
import Loader from '@/components/loader.js'
88
import {getAllChanges} from '@/lib/suivi-pcrs.js'
99
import colors from '@/styles/colors.js'
10+
import {getUpdateStatus} from '@/lib/utils/projet.js'
1011

1112
const Changes = ({token}) => {
1213
const [changes, setChanges] = useState()
1314
const [search, setSearch] = useState()
1415
const [error, setError] = useState()
1516
const [filteredChanges, setFilteredChanges] = useState()
1617

18+
const changesDict = {
19+
deleted: 'Suppression',
20+
updated: 'Mise à jour',
21+
created: 'Création'
22+
}
23+
1724
const getChanges = useCallback(async () => {
1825
const response = await getAllChanges(token)
1926

@@ -24,18 +31,6 @@ const Changes = ({token}) => {
2431
}
2532
}, [token])
2633

27-
function returnLastChange(change) {
28-
if (change._deleted) {
29-
return 'Suppression'
30-
}
31-
32-
if (change._updated !== change._created) {
33-
return 'Mise à jour'
34-
}
35-
36-
return 'Création'
37-
}
38-
3934
useEffect(() => {
4035
if (changes?.length > 0 && search) {
4136
setFilteredChanges(changes.filter(p => p.nom.toLowerCase().includes(search.toLowerCase())))
@@ -77,7 +72,7 @@ const Changes = ({token}) => {
7772
</thead>
7873
<tbody>
7974
{filteredChanges.map(change => {
80-
const lastChange = returnLastChange(change)
75+
const lastChange = changesDict[getUpdateStatus(change)]
8176
const modificationTime = new Date(change._updated)
8277

8378
return (

lib/utils/projet.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,17 @@ export const STOCKAGE_PARAMS = {
7070
url_externe: {label: 'Portail de téléchargement externe', defaultValue: 'Non renseignée'},
7171
secure: {label: 'Connexion sécurisée', defaultValue: false}
7272
}
73+
74+
export function getUpdateStatus(change) {
75+
if (change._deleted) {
76+
return 'deleted'
77+
}
78+
79+
if (change._updated !== change._created) {
80+
return 'updated'
81+
}
82+
83+
return 'created'
84+
}
85+
7386
/* eslint-enable camelcase */

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"start": "NODE_ENV=production node backend/index.js",
1313
"lint": "xo",
1414
"test": "ava",
15-
"scalingo-postbuild": "yarn download-contours && node scripts/migration-recouvrement.js && next build"
15+
"scalingo-postbuild": "yarn download-contours && next build"
1616
},
1717
"dependencies": {
1818
"@aws-sdk/client-s3": "^3.577.0",
@@ -124,6 +124,6 @@
124124
}
125125
},
126126
"engines": {
127-
"node": ">= 20.9 < 21"
127+
"node": ">= 20.9"
128128
}
129129
}

0 commit comments

Comments
 (0)