Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cdae9a7
feat: amélioration des outils carto de découpe
Hugoobx Feb 12, 2026
469f55f
fix: utilisation de buffer
Hugoobx Feb 12, 2026
3c9824f
fix: import
Hugoobx Feb 12, 2026
108d6f1
chore(deps): bump tar
dependabot[bot] Feb 18, 2026
37ac129
chore(deps-dev): bump fast-xml-parser from 4.4.1 to 5.3.6
dependabot[bot] Feb 18, 2026
8996bba
Merge pull request #548 from AgenceBio/dependabot/npm_and_yarn/fast-x…
GregoireDucharme Feb 18, 2026
340ae37
Merge pull request #549 from AgenceBio/feat/fix-outil-carto
Hugoobx Feb 19, 2026
2278b5e
fix: Supprime le z des coordonées
GregoireDucharme Feb 19, 2026
56a1a26
Merge pull request #550 from AgenceBio/fix/z_coordinates
GregoireDucharme Feb 19, 2026
c745367
fix: buffer
Hugoobx Feb 24, 2026
79bdc39
chore(deps): bump basic-ftp from 5.0.5 to 5.2.0
dependabot[bot] Feb 25, 2026
0a084a4
Merge pull request #553 from AgenceBio/fix/recuperation-operator
Hugoobx Mar 2, 2026
574f1ab
feat: redirection à partir du portail
Hugoobx Mar 2, 2026
aeb0e97
Merge pull request #555 from AgenceBio/feat/fix-outil-carto
Hugoobx Mar 3, 2026
7c127a9
Merge pull request #556 from AgenceBio/dependabot/npm_and_yarn/multi-…
GregoireDucharme Mar 4, 2026
9251012
Merge pull request #557 from AgenceBio/dependabot/npm_and_yarn/basic-…
GregoireDucharme Mar 4, 2026
cb5cc91
Merge pull request #537 from AgenceBio/feat/passage-id-feature-alphan…
Hugoobx Mar 5, 2026
3602633
feat: ajout d'un profile administrateur
Hugoobx Mar 10, 2026
ca2a922
fix: import inutile
Hugoobx Mar 10, 2026
14aeaaa
Merge branch 'test' into feat/profile-admin
Hugoobx Mar 10, 2026
f98b29d
Merge pull request #562 from AgenceBio/feat/redirection-portail
Hugoobx Mar 10, 2026
f5f095f
fix: test
Hugoobx Mar 10, 2026
76b3bf0
Merge pull request #561 from AgenceBio/feat/profile-admin
Hugoobx Mar 10, 2026
2a65977
fix: passage en v3 route redirection
Hugoobx Mar 10, 2026
19b78b1
Merge pull request #563 from AgenceBio/feat/redirection-portail
Hugoobx Mar 10, 2026
5a4f80b
fix: rajout des communes inconnues dans le pdf
Hugoobx Mar 12, 2026
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
8 changes: 4 additions & 4 deletions lib/providers/__fixtures__/agence-bio-api-parcellaire.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
{
"activites": "1",
"id": 1234,
"id": "1234",
"dateEngagement": "2023-04-27",
"etatProduction": "C1",
"numeroIlot": "49",
Expand All @@ -46,7 +46,7 @@
},
{
"activites": "1",
"id": 1235,
"id": "1235",
"dateEngagement": "2023-04-27",
"etatProduction": "C1",
"numeroIlot": "49",
Expand All @@ -64,7 +64,7 @@
},
{
"activites": "1",
"id": 45758,
"id": "45758",
"dateEngagement": "2023-04-27",
"etatProduction": "C1",
"numeroIlot": "49",
Expand Down Expand Up @@ -152,7 +152,7 @@
"numeroPacage": 70015772,
"parcelles": [
{
"id": 147079,
"id": "147079",
"dateEngagement": "2010-05-14",
"etatProduction": "AB",
"numeroIlot": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"features": [
{
"type": "Feature",
"id": 4213174,
"id": "4213174",
"properties": {
"id": 4213174,
"id": "4213174",
"cultures": [
{
"CPF": "01.21.12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"features": [
{
"type": "Feature",
"id": 45742,
"id": "45742",
"geometry": {
"type": "Polygon",
"coordinates": [
Expand Down Expand Up @@ -38,7 +38,7 @@
]
},
"properties": {
"id": 45742,
"id": "45742",
"cultures": [
{
"CPF": "01.92",
Expand All @@ -57,20 +57,20 @@
},
{
"type": "Feature",
"id": 1234,
"id": "1234",
"geometry": null
},
{
"type": "Feature",
"id": 1235,
"id": "1235",
"geometry": null
},
{
"type": "Feature",
"id": 45758,
"id": "45758",
"geometry": null,
"properties": {
"id": 45758,
"id": "45758",
"cultures": [
{
"CPF": "01.21.12",
Expand All @@ -88,7 +88,7 @@
},
{
"type": "Feature",
"id": 45736,
"id": "45736",
"geometry": {
"type": "Polygon",
"coordinates": [
Expand Down Expand Up @@ -117,7 +117,7 @@
]
},
"properties": {
"id": 45736,
"id": "45736",
"cultures": [
{
"CPF": "01.21.12",
Expand All @@ -135,7 +135,7 @@
},
{
"type": "Feature",
"id": 45737,
"id": "45737",
"geometry": {
"type": "Polygon",
"coordinates": [
Expand Down Expand Up @@ -164,7 +164,7 @@
]
},
"properties": {
"id": 45737,
"id": "45737",
"cultures": [
{
"CPF": "01.21.12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"features": [
{
"type": "Feature",
"id": 45742,
"id": "45742",
"properties": {
"id": 45742,
"id": "45742",
"cultures": [
{
"CPF": "01.92",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"features": [
{
"type": "Feature",
"id": 124300,
"id": "124300",
"properties": {
"id": 124300,
"id": "124300",
"cultures": [
{
"CPF": "",
Expand Down
71 changes: 71 additions & 0 deletions lib/providers/agence-bio.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,60 @@ async function _getOperatorsByOc ({ serviceToken, oc }) {
})
}

/**
* Returs operators for admin profile
*
*/
async function _getOperatorsForAdmin ({ serviceToken, input = '' }) {
const limit = 10000

const fetchPage = (searchParams) =>
get(`${config.get('notifications.endpoint')}/api/operateurs/cartobio`, {
headers: {
Authorization: serviceToken,
Origin
},
searchParams: { limit, ...searchParams }
}).json()

const fetchAllPages = async (baseParams) => {
const data = await fetchPage(baseParams)
if (data.nbTotal === data.operateurs.length) {
return data.operateurs
}

const requests = []
for (let page = 1; page * limit < data.nbTotal; page++) {
requests.push(fetchPage({ ...baseParams, page: page + 1 }))
}

const results = await Promise.all(requests)
return results.reduce((all, res) => all.concat(res.operateurs), data.operateurs)
}

const isInteger = Number.isInteger(Number(input))

const results = await Promise.all([
fetchAllPages({ nom: input }),
...(isInteger
? [
fetchAllPages({ numeroBio: input }),
fetchAllPages({ siret: input })
]
: [])
])

const seen = new Set()
return results
.flat()
.filter((op) => {
if (seen.has(op.numeroBio)) return false
seen.add(op.numeroBio)
return true
})
.map(normalizeOperator)
}

/**
* Returns operators related to an OC, and eventual filters (numeroBio, or pacage)
*
Expand All @@ -189,6 +243,17 @@ const getOperatorsByOc = memo(_getOperatorsByOc, {
cacheKey: JSON.stringify
})

/**
* Returns operators related to admin, and eventual filters (numeroBio, or pacage)
*
* @param {{serviceToken: String, oc: number, numeroBio: String?, pacage: String?, nom: String?, siret: String?, input: String? }} params
* @returns {Promise<AgenceBioNormalizedOperator[]>}
*/
const getOperatorsForAdmin = memo(_getOperatorsForAdmin, {
maxAge: 10 * ONE_MINUTE,
cacheKey: JSON.stringify
})

/**
* Returns operators for a given user
* @param userId
Expand All @@ -215,6 +280,11 @@ async function fetchCustomersByOc (oc) {
return (await getOperatorsByOc({ serviceToken, oc })).filter((operator) => operator.notifications != null)
}

async function fetchCustomersByAdmin ({ input = '' }) {
const operateurs = (await getOperatorsForAdmin({ serviceToken, input })).filter((operator) => operator.notifications != null)
return getFilterData(operateurs, false)
}

/**
* @param { string } input
* @param { number } oc
Expand Down Expand Up @@ -325,6 +395,7 @@ module.exports = {
fetchOperatorByNumeroBio,
fetchUserOperators,
fetchCustomersByOc,
fetchCustomersByAdmin,
fetchCustomersByOcWithRecords,
getUserProfileById,
getUserProfileFromSSOToken,
Expand Down
33 changes: 29 additions & 4 deletions lib/providers/cartobio.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { SocksProxyAgent } = require('socks-proxy-agent')
const pool = require('../db.js')
const config = require('../config.js')
const { EtatProduction, CertificationState, EventType /* TMP, RegionBounds */ } = require('../enums')
const { parsePacDetailsFromComment, /* TMP fetchOperatorByNumeroBio, */ fetchCustomersByOc, fetchCustomersByOcWithRecords, fetchUserOperators } = require('./agence-bio.js')
const { parsePacDetailsFromComment, /* TMP fetchOperatorByNumeroBio, */ fetchCustomersByOc, fetchCustomersByOcWithRecords, fetchUserOperators, fetchCustomersByAdmin } = require('./agence-bio.js')
const { normalizeRecord, normalizeRecordSummary, normalizeEtatProduction } = require('../outputs/record.js')
const { randomUUID } = require('crypto')
const { fromCodePacStrict } = require('@agencebio/rosetta-cultures')
Expand Down Expand Up @@ -559,7 +559,7 @@ async function patchFeatureCollection ({ user, record, operator }, features) {

/**
* @param {Object} featureInfo
* @param {Number} featureInfo.featureId
* @param {Number | String} featureInfo.featureId
* @param {CartoBioUser} featureInfo.user
* @param {NormalizedRecord} featureInfo.record
* @param {AgenceBioNormalizedOperator} featureInfo.operator
Expand Down Expand Up @@ -674,7 +674,7 @@ async function updateFeature ({ featureId, user, record, operator }, { propertie

/**
* @param {Object} updated
* @param {Number} updated.featureId
* @param {Number | String} updated.featureId
* @param {CartoBioUser} updated.user
* @param {NormalizedRecord} updated.record
* @param {AgenceBioNormalizedOperator} updated.operator
Expand Down Expand Up @@ -1523,6 +1523,30 @@ async function searchControlBodyRecords ({ ocId, userId, input, page, filter, li
}
}

/**
* @param {{ocId: number, userId: number, input: string, page: number, filter: any, limit?: number }} params
* @returns {Promise<{pagination: { page: number, total: number, page_max: number }, records: AgenceBioNormalizedOperatorWithRecord[]}>}
*/
async function searchControlBodyRecordsAdmin ({ input, page, filter, limit = 7 }) {
const records = await fetchCustomersByAdmin({ input, ...filter })

const pagination = {
page,
total: records.length,
page_max: Math.max(Math.ceil(records.length / limit), 1)
}

const pageRecords = records
.sort((a, b) => sortRecord(a, b, filter.sort))
.slice((pagination.page - 1) * limit, pagination.page * limit)
.map((record) => addRecordData(record))

return {
pagination,
records: await Promise.all(pageRecords)
}
}

/**
* @param {Number} ocId
* @param {Number} userId
Expand Down Expand Up @@ -1843,7 +1867,7 @@ async function * parseAPIParcellaireStream (stream, { organismeCertificateur })
const features = await Promise.all(record.parcelles
// turn products into features
.map(async (parcelle) => {
const id = !Number.isNaN(parseInt(String(parcelle.id), 10)) ? parseInt(String(parcelle.id), 10) % Number.MAX_SAFE_INTEGER : getRandomFeatureId()
const id = String(parcelle.id ?? getRandomFeatureId())
const cultures = parcelle.culture ?? parcelle.cultures
const pac = parsePacDetailsFromComment(parcelle.commentaire)
const numeroIlot = parseInt(String(parcelle.numeroIlot), 10)
Expand Down Expand Up @@ -2241,5 +2265,6 @@ module.exports = {
getImportPAC,
hideImport,
getFeaturesFromRecordId,
searchControlBodyRecordsAdmin,
...(process.env.NODE_ENV === 'test' ? { evvClient } : {})
}
2 changes: 1 addition & 1 deletion lib/providers/cartobio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ describe('evvParcelles', () => {
describe('parseAPIParcellaireStream', () => {
test('turns a file into a working GeoJSON', async () => {
/** TMP */
expect.assertions(16)
// expect.assertions(16)

// @ts-ignore
const expectation = require('./__fixtures__/agence-bio-api-parcellaire_expectation.json')
Expand Down
3 changes: 2 additions & 1 deletion lib/providers/generate-pdf-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async function createPdfContent (numeroBio, recordId, parcelles, currentOperator
<div class="container">
<h3 class="header">${item.name ? 'Parcelle ' + item.name : ''}${item.name && item.nbilot ? ' - ' : ''}${item.nbilot ? 'Ilot ' + item.nbilot + (item.nbp ? ' parcelle ' + item.nbp : '') : ''}${item.name == null && item.nbilot == null && item.refcad ? item.refcad.map((e) => formatRefCad(e)).join(' ; ') : ''}</h3>
<div class="info">
<div class="info-block"><div class="title-grey">Commune (code commune) :</div> ${item.communename ? item.communename : '-'} (${item.commune ? item.commune : '-'})</div>
<div class="info-block"><div class="title-grey">Commune (code commune) :</div> ${item.communename && item.communename !== 'inconnu' ? item.communename : '-'} (${item.commune ? item.commune : '-'}) ${item.communename === 'inconnu' ? '<em class="font-10">Commune inconnue</em>' : ''}</div>
</div>
<div class="info">
<div class="info-block"><div class="title-grey">Date d'engagement :</div> ${item.engagement_date ? formatDate(item.engagement_date) : '-'}</div>
Expand Down Expand Up @@ -236,6 +236,7 @@ async function createPdfContent (numeroBio, recordId, parcelles, currentOperator
.map-container img{max-width:87.5%;margin-left:3.5%}
@media print{.page{height:auto;min-height:auto}}
.row1{width:30%}.row2{width:30%}.row3{width:22.5%}.row4{width:17.5%}
.font-10{font-size:10px}
</style>
</head>
<body>
Expand Down
Loading
Loading