Skip to content

Commit

Permalink
use generated types for account and audit listing
Browse files Browse the repository at this point in the history
  • Loading branch information
hissalht committed Dec 13, 2024
1 parent 0580f8c commit 6bc4ded
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 37 deletions.
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
2 changes: 2 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,7 @@ 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";

@Controller("audits")
@ApiTags("Audits")
Expand Down Expand Up @@ -76,6 +77,7 @@ export class AuditsController {
*/
@Get()
@AuthRequired()
@ApiOkResponse({ type: AuditListingItemDto, isArray: true })
async getAuditList(@User() user: AuthenticationJwtPayload) {
return this.auditService.getAuditsByAuditorEmail(user.email);
}
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;
}
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
4 changes: 2 additions & 2 deletions confiture-web-app/src/store/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const useResultsStore = defineStore("results", {
everyCriteriumAreTested(): boolean {
const auditStore = useAuditStore();
const transversePageId =
auditStore.currentAudit?.transverseElementsPage.id;
auditStore.currentAudit?.transverseElementsPage!.id;

return !(
this.allResults
Expand Down Expand Up @@ -159,7 +159,7 @@ export const useResultsStore = defineStore("results", {

const auditStore = useAuditStore();
const transversePageId =
auditStore.currentAudit?.transverseElementsPage.id;
auditStore.currentAudit?.transverseElementsPage!.id;

const r = Object.values(this.data)
.flatMap(Object.values)
Expand Down
37 changes: 6 additions & 31 deletions confiture-web-app/src/types/account.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
import { AuditStatus, AuditType } from "./types";
import { components, paths } from "./confiture-api";

export interface Account {
id: string;
email: string;
name?: string;
orgName?: string;
}
export type UpdateProfileRequestData =
paths["/profile"]["patch"]["requestBody"]["content"]["application/json"];

export interface UpdateProfileRequestData {
/** John Doe */
name: string | null;
/** ACME */
orgName?: string | null;
}
export type AccountDeletionResponse =
paths["/auth/account"]["delete"]["responses"]["200"]["content"]["application/json"];

export interface AccountDeletionResponse {
feedbackToken: string;
}

export interface AccountAudit {
procedureName: string;
status:
| AuditStatus.NOT_STARTED
| AuditStatus.IN_PROGRESS
| AuditStatus.COMPLETED;
creationDate: string;
auditType: AuditType;
complianceLevel: number;
editUniqueId: string;
consultUniqueId: string;
estimatedCsvSize: number;
statementIsPublished: boolean;
}
export type AccountAudit = components["schemas"]["AuditListingItemDto"];

0 comments on commit 6bc4ded

Please sign in to comment.