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

Génère les types des payloads de l'API #722

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.github
.husky
cypress
node_modules
7 changes: 7 additions & 0 deletions Dockerfile.app
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ ARG VITE_SENTRY_ENVIRONMENT
ARG VITE_SENTRY_RELEASE
WORKDIR /app
RUN mkdir -p confiture-web-app/src/assets
RUN mkdir -p confiture-web-app/src/types
COPY package.json yarn.lock CHANGELOG.md ROADMAP.md .
COPY confiture-web-app/package.json confiture-web-app/
COPY confiture-rest-api/ confiture-rest-api/
RUN pwd
RUN ls
RUN yarn install --frozen-lockfile --non-interactive --production=false
RUN ls confiture-web-app/src/types


WORKDIR /app/confiture-web-app
COPY confiture-web-app/ .
RUN VITE_MATOMO_ENABLE=1 SENTRY_ORG=${SENTRY_ORG} SENTRY_PROJECT=${SENTRY_PROJECT} SENTRY_AUTH_TOKEN=${SENTRY_AUTH_TOKEN} VITE_SENTRY_DSN=${VITE_SENTRY_DSN} VITE_SENTRY_ENVIRONMENT=${VITE_SENTRY_ENVIRONMENT} VITE_SENTRY_RELEASE=${VITE_SENTRY_RELEASE} yarn build
Expand Down
3 changes: 3 additions & 0 deletions confiture-rest-api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ lerna-debug.log*
.env

src/generated

# Generated API typings
confiture-api.ts
4 changes: 3 additions & 1 deletion confiture-rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"lint": "eslint \"src/**/*.ts\" --fix",
"migrate:dev": "prisma migrate dev",
"migrate:prod": "prisma migrate deploy",
"postinstall": "prisma generate"
"postinstall": "yarn generate-api-types",
"generate-api-types": "prisma generate && rimraf dist && GENERATE_TYPES=1 nest start --entryFile generate-api-typings.js"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.218.0",
Expand Down Expand Up @@ -62,6 +63,7 @@
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-simple-import-sort": "^12.1.0",
"eslint-plugin-unused-imports": "^3.1.0",
"openapi-typescript": "^6.7.6",
"prettier": "^3.1.1",
"source-map-support": "^0.5.20",
"ts-loader": "^9.2.3",
Expand Down
9 changes: 9 additions & 0 deletions confiture-rest-api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ model TestEnvironment {
assistiveTechnology String
browser String

/// @DtoEntityHidden
audit Audit? @relation(fields: [auditUniqueId], references: [editUniqueId], onDelete: Cascade)
/// @DtoEntityHidden
auditUniqueId String?

@@unique([platform, operatingSystem, assistiveTechnology, browser, auditUniqueId])
Expand All @@ -115,12 +117,15 @@ model AuditedPage {
url String

// parent audit when the page is a user made page
/// @DtoEntityHidden
audit Audit? @relation(name: "UserPages", fields: [auditUniqueId], references: [editUniqueId], onDelete: Cascade)
auditUniqueId String?

// parent audit when the page is a transverse page
/// @DtoEntityHidden
auditTransverse Audit? @relation(name: "TransversePage")

/// @DtoEntityHidden
results CriterionResult[]
}

Expand Down Expand Up @@ -184,7 +189,9 @@ model StoredFile {
key String
thumbnailKey String

/// @DtoEntityHidden
criterionResult CriterionResult? @relation(fields: [criterionResultId], references: [id], onDelete: Cascade, onUpdate: Cascade)
/// @DtoEntityHidden
criterionResultId Int?
}

Expand All @@ -203,7 +210,9 @@ model AuditFile {
key String
thumbnailKey String?

/// @DtoEntityHidden
audit Audit? @relation(fields: [auditUniqueId], references: [editUniqueId], onDelete: Cascade)
/// @DtoEntityHidden
auditUniqueId String?
}

Expand Down
4 changes: 3 additions & 1 deletion confiture-rest-api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import { PrismaService } from "./prisma.service";
imports: [
ConfigModule.forRoot({
isGlobal: true,
validationSchema: configValidationSchema
validationSchema: !process.env.GENERATE_TYPES
? configValidationSchema
: undefined
}),
FeedbackModule,
AuditsModule,
Expand Down
5 changes: 3 additions & 2 deletions confiture-rest-api/src/audits/audit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { FileStorageService } from "./file-storage.service";
import { UpdateAuditDto } from "./dto/update-audit.dto";
import { UpdateResultsDto } from "./dto/update-results.dto";
import { PatchAuditDto } from "./dto/patch-audit.dto";
import { AuditListingItemDto } from "./dto/audit-listing-item.dto";

const AUDIT_EDIT_INCLUDE = {
recipients: true,
Expand Down Expand Up @@ -1287,7 +1288,7 @@ export class AuditService {
});
}

async getAuditsByAuditorEmail(email: string) {
async getAuditsByAuditorEmail(email: string): Promise<AuditListingItemDto[]> {
const audits = await this.prisma.audit.findMany({
where: {
auditorEmail: email,
Expand All @@ -1314,7 +1315,7 @@ export class AuditService {
}
});

const unorderedAudits = audits.map((a) => {
const unorderedAudits: AuditListingItemDto[] = audits.map((a) => {
const allResults = [
...a.transverseElementsPage.results,
...a.pages.flatMap((p) => p.results)
Expand Down
4 changes: 4 additions & 0 deletions confiture-rest-api/src/audits/audits.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import { UploadImageDto } from "./dto/upload-image.dto";
import { AuthRequired } from "src/auth/auth-required.decorator";
import { User } from "src/auth/user.decorator";
import { AuthenticationJwtPayload } from "src/auth/jwt-payloads";
import { AuditListingItemDto } from "./dto/audit-listing-item.dto";
import { StoredFile } from "src/generated/nestjs-dto/storedFile.entity";

@Controller("audits")
@ApiTags("Audits")
Expand Down Expand Up @@ -76,6 +78,7 @@ export class AuditsController {
*/
@Get()
@AuthRequired()
@ApiOkResponse({ type: AuditListingItemDto, isArray: true })
async getAuditList(@User() user: AuthenticationJwtPayload) {
return this.auditService.getAuditsByAuditorEmail(user.email);
}
Expand Down Expand Up @@ -146,6 +149,7 @@ export class AuditsController {

@Post("/:uniqueId/results/examples")
@UseInterceptors(FileInterceptor("image"))
@ApiCreatedResponse({ type: StoredFile })
async uploadExampleImage(
@Param("uniqueId") uniqueId: string,
@UploadedFile(
Expand Down
16 changes: 16 additions & 0 deletions confiture-rest-api/src/audits/dto/audit-listing-item.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ApiProperty } from "@nestjs/swagger";
import { AuditType } from "@prisma/client";

export class AuditListingItemDto {
procedureName: string;
editUniqueId: string;
consultUniqueId: string;
creationDate: Date;
@ApiProperty({ enum: AuditType })
auditType: AuditType;
complianceLevel: number;
@ApiProperty({ enum: ["NOT_STARTED", "COMPLETED", "IN_PROGRESS"] })
status: "NOT_STARTED" | "COMPLETED" | "IN_PROGRESS";
estimatedCsvSize: number;
statementIsPublished: boolean;
}
36 changes: 18 additions & 18 deletions confiture-rest-api/src/audits/dto/audit-report.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,7 @@ export class AuditReportDto {
*/
accessibilityRate: number;

/**
* @example {
* total: 106;
* compliant: 30;
* notCompliant: 46;
* blocking: 12;
* applicable: 76;
* notApplicable: 30;
* }
*/
criteriaCount: {
total: number;
compliant: number;
notCompliant: number;
blocking: number;
applicable: number;
notApplicable: number;
};
criteriaCount: CriteriaCount;

/** Global distribution of criteria by result */
resultDistribution: ResultDistribution;
Expand All @@ -68,6 +51,21 @@ export class AuditReportDto {
results: ReportCriterionResult[];
}

class CriteriaCount {
/** @example 106 */
total: number;
/** @example 30 */
compliant: number;
/** @example 46 */
notCompliant: number;
/** @example 12 */
blocking: number;
/** @example 76 */
applicable: number;
/** @example 30 */
notApplicable: number;
}

class RawAndPercentage {
/**
* @example 47
Expand Down Expand Up @@ -187,6 +185,8 @@ class ReportCriterionResult {
userImpact: CriterionResultUserImpact | null;

notApplicableComment: string | null;

quickWin: boolean;
}

class ExampleImage {
Expand Down
24 changes: 24 additions & 0 deletions confiture-rest-api/src/generate-api-typings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NestFactory } from "@nestjs/core";
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
import { writeFile } from "fs/promises";
import openapiTS, { OpenAPI3 } from "openapi-typescript";
import { resolve } from "path";

import { AppModule } from "./app.module";

async function main() {
const app = await NestFactory.create(AppModule);

const config = new DocumentBuilder().setTitle("Confiture API").build();
const document = SwaggerModule.createDocument(app, config);

const ast = await openapiTS(document as OpenAPI3);
const fileContent = "/* eslint-disable */\n" + ast;
const resolvedPath = resolve(__dirname, "../confiture-api.ts");
await writeFile(resolvedPath, fileContent, {
encoding: "utf-8"
});
console.log("✅ Typings saved to", resolvedPath);
}

main();
9 changes: 8 additions & 1 deletion confiture-rest-api/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts", "scripts"]
"exclude": [
"node_modules",
"test",
"dist",
"**/*spec.ts",
"scripts",
"confiture-api.ts"
]
}
3 changes: 2 additions & 1 deletion confiture-web-app/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
accessibilite.numerique.gouv.fr
coverage
dist
.vscode
.vscode
src/types/confiture-api.ts
1 change: 1 addition & 0 deletions confiture-web-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ coverage
accessibilite.numerique.gouv.fr
src/methodologies.json
src/criteres.json
src/types/confiture-api.ts
4 changes: 2 additions & 2 deletions confiture-web-app/src/components/account/settings/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const showActions = computed(() => {
function updateProfile() {
accountStore
.updateProfile({
name: name.value || null,
orgName: orgName.value || null
name: name.value,
orgName: orgName.value
})
.then(() => {
notify("success", undefined, "Profil mis à jour avec succès");
Expand Down
8 changes: 6 additions & 2 deletions confiture-web-app/src/components/report/ReportErrors.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import { computed, ref } from "vue";

import { useReportStore } from "../../store";
import { CriterionResultUserImpact, CriteriumResultStatus } from "../../types";
import {
CriterionResultUserImpact,
CriteriumResultStatus,
ReportUserImpact
} from "../../types";
import { getReportErrors } from "./getReportErrors";
import ReportCriteria from "./ReportCriteria.vue";
import ReportErrorCriterium from "./ReportErrorCriterium.vue";
Expand All @@ -17,7 +21,7 @@ const defaultUserImpactFillters = [
null
];

const userImpactFilters = ref<Array<CriterionResultUserImpact | null>>(
const userImpactFilters = ref<Array<ReportUserImpact>>(
defaultUserImpactFillters
);

Expand Down
6 changes: 3 additions & 3 deletions confiture-web-app/src/components/report/getReportErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import rgaa from "../../criteres.json";
import { ReportStoreState } from "../../store";
import {
AuditReport,
CriterionResultUserImpact,
CriteriumResultStatus,
ReportCriteriumResult
ReportCriteriumResult,
ReportUserImpact
} from "../../types";

export type ReportError = {
Expand All @@ -24,7 +24,7 @@ export type ReportError = {
export function getReportErrors(
report: ReportStoreState,
quickWinFilter: boolean,
userImpactFilters: Array<CriterionResultUserImpact | null>
userImpactFilters: Array<ReportUserImpact>
): ReportError[] {
const resultsGroupedByPage = {
// include pages with no errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function getReportImprovements(
improvements: sortBy(
results.filter(hasImprovement).map(getImprovementObject),
"criterium"
)
) as ReportImprovement["topics"][0]["improvements"]
};
})
),
Expand Down
Loading
Loading