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

[TRA 15238] Export SSD #3755

Open
wants to merge 25 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cf5dec8
feat(Registry): add registry export creation/update/delete on ssd cre…
silto Nov 6, 2024
302c4c6
feat(Registry): change db structure
silto Nov 6, 2024
315b186
broken commit for rebase
silto Nov 7, 2024
6bc9650
feat(Registry): add registry export mutations/queries and permissions…
silto Nov 8, 2024
d36fb42
docs|feat|fix|perf|refactor|revert|style|test(scope1,scope2): add reg…
silto Nov 12, 2024
175cd37
feat(Registry): complete registry export job
silto Nov 13, 2024
57cb230
feat(Registry): add companies resolvers on registry export with datal…
silto Nov 15, 2024
564e211
docs|feat|fix|perf|refactor|revert|style|test(scope1,scope2): add exp…
silto Nov 16, 2024
2039932
feat(Registry): add exports table + minor fixes
silto Nov 16, 2024
c16d64f
feat(Registry): make filters depend on registry type
silto Nov 19, 2024
73ca8bd
feat(Registry): add proper file name on exports
silto Nov 19, 2024
9b1d8d6
feat(Registry): fixes/imporvements after review
silto Nov 19, 2024
e610461
fix(Registry): cleanup export processing, fix frontend build
silto Nov 20, 2024
b743d45
fix(Registry): minor fixes to export page
silto Nov 21, 2024
0c46cd4
fix(Registry): remove useless css class
silto Nov 21, 2024
dada431
fix(Registry): remove log
silto Nov 21, 2024
4a65d93
refactor(Registry): group registryLookup util functions in their own …
silto Nov 21, 2024
181b43b
fix(Registry): call upload stream generation with new params
silto Nov 22, 2024
6e70003
docs(Registry): move FormsRegisterExportFormat to common gql definiti…
silto Nov 23, 2024
6b5417d
docs(Registry): minor fixes, comments and diagrams
silto Nov 26, 2024
0545c09
docs(Registry): minor fixes, docs
silto Nov 26, 2024
59f33a8
fix(Registry): typo
silto Nov 26, 2024
5b719d4
docs(Changelog): update Changelog
silto Nov 27, 2024
81f956f
feat(Registry): change RegistryLookup siret field, add lookup rebuild…
silto Nov 28, 2024
9b897f1
docs(Registry): update docs
silto Nov 28, 2024
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
4 changes: 3 additions & 1 deletion .env.model
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ S3_REGION=*********
S3_ACCESS_KEY_ID=*********
S3_SECRET_ACCESS_KEY=*********
S3_BUCKET=*********

S3_REGISTRY_ERRORS_BUCKET=*********
S3_REGISTRY_IMPORTS_BUCKET=*********
S3_REGISTRY_EXPORTS_BUCKET=*********
# File storage configuration for empty bsds templates
S3_BSD_TEMPLATES_ACCESS_KEY_ID==*********
S3_BSD_TEMPLATES_SECRET_ACCESS_KEY==*********
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
- name: Init DB & ES index
run: |
npx nx run back:codegen
npx nx run @td/codegen-back:build
npx nx run @td/prisma:generate
npx nx run @td/codegen-ui:build
TERM=xterm bash ./scripts/deploy-db.sh
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
- name: Init DB & ES index
run: |
npx nx run back:codegen
npx nx run @td/codegen-back:build
npx nx run @td/prisma:generate
TERM=xterm bash ./scripts/deploy-db.sh
- name: Create MinIO buckets
Expand Down
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ et le projet suit un schéma de versionning inspiré de [Calendar Versioning](ht

# [2024.12.1] 17/12/2024

#### :rocket: Nouvelles fonctionnalités

- Ajout de l'export v2 des registres SSD [PR 3755](https://github.com/MTES-MCT/trackdechets/pull/3755)

#### :bug: Corrections de bugs

- Ne pas doubler les quantités restantes à regrouper lorsqu'on modifie un bordereau de groupement [PR 3760](https://github.com/MTES-MCT/trackdechets/pull/3760)
Expand Down
5 changes: 4 additions & 1 deletion apps/queues-runner/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {
updateAppendix2Queue,
updateAppendix2Job,
registryImportQueue,
processRegistryImportJob
processRegistryImportJob,
registryExportQueue,
processRegistryExportJob
} from "back";

import { schema } from "@td/env";
Expand All @@ -38,6 +40,7 @@ function startConsumers() {
administrativeTransferQueue.process(processAdministrativeTransferJob);
updateAppendix2Queue.process(updateAppendix2Job);
registryImportQueue.process(processRegistryImportJob);
registryExportQueue.process(processRegistryExportJob);
}

startConsumers();
1 change: 1 addition & 0 deletions back/codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ generates:
config:
contextType: ../../types#GraphQLContext
enumsAsTypes: true
allowParentTypeOverride: true
silto marked this conversation as resolved.
Show resolved Hide resolved
scalars:
DateTime: Date
URL: URL
Expand Down
9 changes: 9 additions & 0 deletions back/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@
"configurations": {
"integration": {}
}
},
"rebuild-registry-lookup": {
"executor": "nx:run-commands",
"options": {
"command": "tsx --tsconfig back/tsconfig.lib.json back/src/scripts/bin/rebuildRegistryLookup.ts"
},
"configurations": {
"integration": {}
}
}
},
"tags": []
Expand Down
1 change: 1 addition & 0 deletions back/src/bsdasris/edition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type EditableBsdasriFields = Required<
| "finalOperations"
| "FinalOperationToFinalBsdasri"
| "bsdasriRevisionRequests"
| "registryLookups"
>
>;
// Defines until which signature BSDASRI fields can be modified
Expand Down
10 changes: 7 additions & 3 deletions back/src/bsds/resolvers/mutations/utils/clone.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export const cloneBsda = async (user: Express.User, id: string) => {
| "grouping"
| "rowNumber"
// Done manually
// TODO(registry): clone associated registryLookup
| "finalOperations"
| "registryLookups"
> = {
id: getReadableId(ReadableIdPrefix.BSDA),
brokerCompanyAddress: bsda.brokerCompanyAddress,
Expand Down Expand Up @@ -244,6 +246,7 @@ export const cloneBsdasri = async (user: Express.User, id: string) => {
| "rowNumber"
// Done manually
| "finalOperations"
| "registryLookups"
> = {
id: getReadableId(ReadableIdPrefix.DASRI),
createdAt: bsdasri.createdAt,
Expand Down Expand Up @@ -419,7 +422,7 @@ export const cloneBsff = async (user: Express.User, id: string) => {
const newBsffCreateInput: Omit<
Required<Prisma.BsffCreateInput>,
// Ignored for the time being
"rowNumber"
"rowNumber" | "registryLookups"
> = {
id: getReadableId(ReadableIdPrefix.FF),
createdAt: bsff.createdAt,
Expand Down Expand Up @@ -541,7 +544,7 @@ export const cloneBsvhu = async (user: Express.User, id: string) => {
const newBsvhuCreateInput: Omit<
Required<Prisma.BsvhuCreateInput>,
// Ignored for the time being
"rowNumber"
"rowNumber" | "registryLookups"
> = {
id: getReadableId(ReadableIdPrefix.VHU),
createdAt: bsvhu.createdAt,
Expand Down Expand Up @@ -685,7 +688,7 @@ export const cloneBspaoh = async (user: Express.User, id: string) => {
const newBspaohCreateInput: Omit<
Required<Prisma.BspaohCreateInput>,
// Ignored for the time being
"rowNumber"
"rowNumber" | "registryLookups"
> = {
id: getReadableId(ReadableIdPrefix.PAOH),
canAccessDraftSirets: bspaoh.canAccessDraftSirets,
Expand Down Expand Up @@ -820,6 +823,7 @@ export const cloneBsdd = async (
| "bsddRevisionRequests"
// Done manually
| "finalOperations"
| "registryLookups"
> = {
owner: {
connect: {
Expand Down
1 change: 1 addition & 0 deletions back/src/bspaoh/validation/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type EditableBspaohFields = Required<
| "transportersSirets"
| "canAccessDraftSirets"
| "transporterTransportTakenOverAt"
| "registryLookups"
>
>;

Expand Down
24 changes: 24 additions & 0 deletions back/src/common/typeDefs/common.enums.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,27 @@ enum TransportMode {
"Autre (utilisé avec Packaging = PIPELINE par exemple)"
OTHER
}

"Type de déclaration"
enum DeclarationType {
"Bordereau"
BSD
"Registre"
REGISTRY
"Tous types"
ALL
}

"""
Format de l'export du registre
"""
enum FormsRegisterExportFormat {
"""
Fichier csv
"""
CSV
"""
Fichier Excel
"""
XLSX
}
13 changes: 12 additions & 1 deletion back/src/companies/converters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Company } from "@prisma/client";
import { CompanyPrivate } from "../generated/graphql/types";
import { CompanyPrivate, CompanyPublic } from "../generated/graphql/types";
import { libelleFromCodeNaf } from "./sirene/utils";

export function toGqlCompanyPrivate(company: Company): CompanyPrivate {
Expand All @@ -23,3 +23,14 @@ export function toGqlCompanyPrivate(company: Company): CompanyPrivate {
}
};
}

export function toGqlCompanyPublic(company: Company): CompanyPublic {
return {
...company,
ecoOrganismeAgreements:
company.ecoOrganismeAgreements?.map(a => new URL(a)) ?? [],
naf: company.codeNaf,
isDormant: company.isDormantSince !== null,
libelleNaf: company.codeNaf ? libelleFromCodeNaf(company.codeNaf) : ""
};
}
silto marked this conversation as resolved.
Show resolved Hide resolved
40 changes: 39 additions & 1 deletion back/src/companies/dataloaders.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import DataLoader from "dataloader";
import { prisma } from "@td/prisma";
import { UserRole } from "@prisma/client";
import { Company, UserRole } from "@prisma/client";

export function createCompanyDataLoaders() {
return {
companies: new DataLoader((sirets: string[]) => getCompanies(sirets)),
installations: new DataLoader((sirets: string[]) =>
getInstallations(sirets)
),
companiesAdmin: new DataLoader((companyIds: string[]) =>
getCompaniesAdmin(companyIds)
),
delegators: new DataLoader((companyIds: string[]) =>
getCompaniesDelegators(companyIds)
)
};
}

async function getCompanies(sirets: string[]) {
const companies = await prisma.company.findMany({
where: {
orgId: { in: sirets }
}
});

return sirets.map(
siret => companies.find(company => company.orgId === siret) ?? null
);
}

async function getInstallations(sirets: string[]) {
const installations = await prisma.installation.findMany({
where: {
Expand Down Expand Up @@ -91,3 +107,25 @@ async function getCompaniesAdmin(companyIds: string[]) {
return association?.admin ?? null;
});
}

const getCompaniesDelegators = async (
companyIds: string[]
): Promise<Company[][]> => {
const delegations = await prisma.registryDelegation.findMany({
where: {
delegateId: { in: companyIds },
revokedBy: null,
cancelledBy: null,
startDate: { lte: new Date() },
OR: [{ endDate: null }, { endDate: { gt: new Date() } }]
},
include: {
delegator: true
}
});
return companyIds.map(companyId =>
delegations
.filter(delegation => delegation.delegateId === companyId)
.map(delegation => delegation.delegator)
);
};
5 changes: 5 additions & 0 deletions back/src/companies/resolvers/CompanyPrivate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CompanyPrivateResolvers } from "../../generated/graphql/types";
import { getCompanyUsers } from "../database";
import { getUserRole, grants, toGraphQLPermission } from "../../permissions";
import { toGqlNotifications } from "../../users/notifications";
import { toGqlCompanyPublic } from "../converters";

const companyPrivateResolvers: CompanyPrivateResolvers = {
users: async (parent, _, context) => {
Expand Down Expand Up @@ -96,6 +97,10 @@ const companyPrivateResolvers: CompanyPrivateResolvers = {
return prisma.company
.findUnique({ where: { id: parent.id } })
.receivedAdministrativeTransfers() as any;
},
delegators: async (parent, _, context) => {
const res = await context.dataloaders.delegators.load(parent.id);
return res.map(toGqlCompanyPublic);
}
};

Expand Down
5 changes: 5 additions & 0 deletions back/src/companies/typeDefs/company.objects.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ type CompanyPrivate {
Liste des transferts administratifs reçus par l'établissement
"""
receivedAdministrativeTransfers: [AdministrativeTransfer!]

"""
Liste des entreprises ayant délégué la déclaration de leurs registres
"""
delegators: [CompanyPublic!]
}

type CompanyPrivateEdge {
Expand Down
1 change: 1 addition & 0 deletions back/src/forms/edition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type EditableBsddFields = Required<
| "finalOperations"
| "FinalOperationToFinalForm"
| "emptyReturnADR"
| "registryLookups"
>
>;

Expand Down
14 changes: 0 additions & 14 deletions back/src/forms/typeDefs/bsdd.enums.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,6 @@ enum FormsRegisterExportType {
BROKERED
}

"""
Format de l'export du registre
"""
enum FormsRegisterExportFormat {
"""
Fichier csv
"""
CSV
"""
Fichier Excel
"""
XLSX
}

"Charte citerne - Raison pour laquelle la citerne n'a pas été rincée"
enum CiterneNotWashedOutReason {
"Exemptions de rinçage (citerne dédiée)"
Expand Down
4 changes: 3 additions & 1 deletion back/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ export { operationHooksQueue } from "./queue/producers/operationHook";
export { administrativeTransferQueue } from "./queue/producers/administrativeTransfer";
export { updateAppendix2Queue } from "./queue/producers/updateAppendix2";
export { registryImportQueue } from "./queue/producers/registryImport";
export { registryExportQueue } from "./queue/producers/registryExport";
export {
indexBsdJob,
operationHookJob,
updateAppendix2Job,
sendMailJob,
postGericoJob,
processAdministrativeTransferJob,
processRegistryImportJob
processRegistryImportJob,
processRegistryExportJob
} from "./queue/jobs";

export {
Expand Down
1 change: 1 addition & 0 deletions back/src/queue/jobs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export { postGericoJob } from "./gerico";
export { processAdministrativeTransferJob } from "./administrativeTransfer";
export { updateAppendix2Job } from "./updateAppendix2";
export { processRegistryImportJob } from "./processRegistryImport";
export { processRegistryExportJob } from "./processRegistryExport";
Loading