From 88beb563bfdbeee2374dea9c0d8fb8fcd48d5eb7 Mon Sep 17 00:00:00 2001 From: Aram <37216945+alimpens@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:14:41 +0100 Subject: [PATCH] Update api client (#638) --- .../filterFormResponse.test.tsx.snap | 2 + .../form/utils/filterFormResponse.test.tsx | 4 +- apps/public/src/app/(general)/page.tsx | 10 +- libs/api-client/src/schemas.gen.ts | 398 +++++++++++++++++- libs/api-client/src/sdk.gen.ts | 33 +- libs/api-client/src/types.gen.ts | 110 ++++- 6 files changed, 545 insertions(+), 12 deletions(-) diff --git a/apps/admin/src/pages/form/utils/__snapshots__/filterFormResponse.test.tsx.snap b/apps/admin/src/pages/form/utils/__snapshots__/filterFormResponse.test.tsx.snap index 4a66994..da2daef 100644 --- a/apps/admin/src/pages/form/utils/__snapshots__/filterFormResponse.test.tsx.snap +++ b/apps/admin/src/pages/form/utils/__snapshots__/filterFormResponse.test.tsx.snap @@ -105,6 +105,7 @@ exports[`filterFormResponse > renders the correct output 1`] = ` "input": false, "key": "page1", "label": "Page 1", + "title": "Page 1", "type": "panel", }, { @@ -243,6 +244,7 @@ exports[`filterFormResponse > renders the correct output 1`] = ` "input": false, "key": "page2", "label": "Page 2", + "title": "Page 2", "type": "panel", }, ], diff --git a/apps/admin/src/pages/form/utils/filterFormResponse.test.tsx b/apps/admin/src/pages/form/utils/filterFormResponse.test.tsx index 1d6f8f1..5ed41e4 100644 --- a/apps/admin/src/pages/form/utils/filterFormResponse.test.tsx +++ b/apps/admin/src/pages/form/utils/filterFormResponse.test.tsx @@ -2,8 +2,8 @@ import { filterFormResponse } from './filterFormResponse' import { mockData } from './filterFormResponseMock' // This test compares the output of the function to a snapshot. -// To update the snapshot, run the following command: -// npx nx test admin filterFormResponse.spec.tsx --updateSnapshot +// To update the snapshot, run the following command in apps/admin: +// npx vitest -u describe('filterFormResponse', () => { it('renders the correct output', () => { expect(filterFormResponse(mockData)).toMatchSnapshot() diff --git a/apps/public/src/app/(general)/page.tsx b/apps/public/src/app/(general)/page.tsx index ad90d49..9ec12c9 100644 --- a/apps/public/src/app/(general)/page.tsx +++ b/apps/public/src/app/(general)/page.tsx @@ -1,4 +1,4 @@ -import { getStaticForm } from '@meldingen/api-client' +import { getStaticForm, getStaticFormByStaticFormId } from '@meldingen/api-client' import { Home } from './Home' @@ -7,9 +7,11 @@ import { Home } from './Home' export const dynamic = 'force-dynamic' export default async () => { - const staticForm = await getStaticForm().then((response) => response.find((form) => form.type === 'primary')) + const primaryFormId = await getStaticForm().then((response) => response.find((form) => form.type === 'primary')?.id) - if (!staticForm) return undefined + if (!primaryFormId) return undefined - return + const primaryForm = (await getStaticFormByStaticFormId({ staticFormId: primaryFormId }))?.components + + return } diff --git a/libs/api-client/src/schemas.gen.ts b/libs/api-client/src/schemas.gen.ts index c948735..5305213 100644 --- a/libs/api-client/src/schemas.gen.ts +++ b/libs/api-client/src/schemas.gen.ts @@ -666,6 +666,12 @@ export const AttachmentTypesSchema = { title: 'AttachmentTypes' } as const; +export const BaseModelSchema = { + properties: {}, + type: 'object', + title: 'BaseModel' +} as const; + export const Body_melding_attachment_melding__melding_id__attachment_postSchema = { properties: { file: { @@ -1658,6 +1664,11 @@ export const FormPanelComponentInputSchema = { minLength: 3, title: 'Label' }, + title: { + type: 'string', + minLength: 3, + title: 'Title' + }, key: { type: 'string', minLength: 3, @@ -1698,12 +1709,16 @@ export const FormPanelComponentInputSchema = { }, additionalProperties: false, type: 'object', - required: ['label', 'key', 'components'], + required: ['label', 'title', 'key', 'components'], title: 'FormPanelComponentInput' } as const; export const FormPanelComponentOutputSchema = { properties: { + title: { + type: 'string', + title: 'Title' + }, label: { type: 'string', title: 'Label' @@ -1749,7 +1764,7 @@ export const FormPanelComponentOutputSchema = { } }, type: 'object', - required: ['label', 'key', 'type', 'input', 'position', 'components'], + required: ['title', 'label', 'key', 'type', 'input', 'position', 'components'], title: 'FormPanelComponentOutput' } as const; @@ -2226,6 +2241,212 @@ export const FormTextFieldInputComponentOutputSchema = { title: 'FormTextFieldInputComponentOutput' } as const; +export const GeoJson_InputSchema = { + properties: { + bbox: { + anyOf: [ + { + prefixItems: [ + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + } + ], + type: 'array', + maxItems: 4, + minItems: 4 + }, + { + prefixItems: [ + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + } + ], + type: 'array', + maxItems: 6, + minItems: 6 + }, + { + type: 'null' + } + ], + title: 'Bbox' + }, + type: { + type: 'string', + const: 'Feature', + title: 'Type' + }, + geometry: { + anyOf: [ + { + '$ref': '#/components/schemas/Point' + }, + { + type: 'null' + } + ] + }, + properties: { + anyOf: [ + { + type: 'object' + }, + { + '$ref': '#/components/schemas/BaseModel' + }, + { + type: 'null' + } + ], + title: 'Properties' + }, + id: { + anyOf: [ + { + type: 'integer' + }, + { + type: 'string' + }, + { + type: 'null' + } + ], + title: 'Id' + } + }, + type: 'object', + required: ['type', 'geometry', 'properties'], + title: 'GeoJson' +} as const; + +export const GeoJson_OutputSchema = { + properties: { + bbox: { + anyOf: [ + { + prefixItems: [ + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + } + ], + type: 'array', + maxItems: 4, + minItems: 4 + }, + { + prefixItems: [ + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + } + ], + type: 'array', + maxItems: 6, + minItems: 6 + }, + { + type: 'null' + } + ], + title: 'Bbox' + }, + type: { + type: 'string', + const: 'Feature', + title: 'Type' + }, + geometry: { + anyOf: [ + { + '$ref': '#/components/schemas/Point' + }, + { + type: 'null' + } + ] + }, + properties: { + anyOf: [ + { + type: 'object' + }, + { + '$ref': '#/components/schemas/BaseModel' + }, + { + type: 'null' + } + ], + title: 'Properties' + }, + id: { + anyOf: [ + { + type: 'integer' + }, + { + type: 'string' + }, + { + type: 'null' + } + ], + title: 'Id' + } + }, + type: 'object', + required: ['type', 'geometry', 'properties'], + title: 'GeoJson' +} as const; + export const GreaterThanSchema = { properties: { '>': { @@ -3136,6 +3357,16 @@ export const MeldingCreateOutputSchema = { ], title: 'Classification' }, + geo_location: { + anyOf: [ + { + '$ref': '#/components/schemas/GeoJson-Output' + }, + { + type: 'null' + } + ] + }, token: { type: 'string', title: 'Token' @@ -3193,6 +3424,16 @@ export const MeldingOutputSchema = { } ], title: 'Classification' + }, + geo_location: { + anyOf: [ + { + '$ref': '#/components/schemas/GeoJson-Output' + }, + { + type: 'null' + } + ] } }, type: 'object', @@ -4009,6 +4250,119 @@ export const Or_OutputSchema = { title: 'Or' } as const; +export const PointSchema = { + properties: { + bbox: { + anyOf: [ + { + prefixItems: [ + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + } + ], + type: 'array', + maxItems: 4, + minItems: 4 + }, + { + prefixItems: [ + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + }, + { + type: 'number' + } + ], + type: 'array', + maxItems: 6, + minItems: 6 + }, + { + type: 'null' + } + ], + title: 'Bbox' + }, + type: { + type: 'string', + const: 'Point', + title: 'Type' + }, + coordinates: { + anyOf: [ + { + '$ref': '#/components/schemas/Position2D' + }, + { + '$ref': '#/components/schemas/Position3D' + } + ], + title: 'Coordinates' + } + }, + type: 'object', + required: ['type', 'coordinates'], + title: 'Point', + description: 'Point Model' +} as const; + +export const Position2DSchema = { + prefixItems: [ + { + type: 'number', + title: 'Longitude' + }, + { + type: 'number', + title: 'Latitude' + } + ], + type: 'array', + maxItems: 2, + minItems: 2 +} as const; + +export const Position3DSchema = { + prefixItems: [ + { + type: 'number', + title: 'Longitude' + }, + { + type: 'number', + title: 'Latitude' + }, + { + type: 'number', + title: 'Altitude' + } + ], + type: 'array', + maxItems: 3, + minItems: 3 +} as const; + export const Reduce_InputSchema = { properties: { reduce: { @@ -4354,6 +4708,40 @@ export const SimpleFormOutputSchema = { title: 'SimpleFormOutput' } as const; +export const SimpleStaticFormOutputSchema = { + properties: { + id: { + type: 'integer', + title: 'Id' + }, + title: { + type: 'string', + title: 'Title' + }, + display: { + type: 'string', + title: 'Display' + }, + created_at: { + type: 'string', + format: 'date-time', + title: 'Created At' + }, + updated_at: { + type: 'string', + format: 'date-time', + title: 'Updated At' + }, + type: { + type: 'string', + title: 'Type' + } + }, + type: 'object', + required: ['id', 'title', 'display', 'created_at', 'updated_at', 'type'], + title: 'SimpleStaticFormOutput' +} as const; + export const Some_InputSchema = { properties: { some: { @@ -4815,6 +5203,10 @@ export const StaticFormOutputSchema = { export const StaticFormPanelComponentOutputSchema = { properties: { + title: { + type: 'string', + title: 'Title' + }, label: { type: 'string', title: 'Label' @@ -4860,7 +5252,7 @@ export const StaticFormPanelComponentOutputSchema = { } }, type: 'object', - required: ['label', 'key', 'type', 'input', 'position', 'components'], + required: ['title', 'label', 'key', 'type', 'input', 'position', 'components'], title: 'StaticFormPanelComponentOutput' } as const; diff --git a/libs/api-client/src/sdk.gen.ts b/libs/api-client/src/sdk.gen.ts index eefecc9..6ed03a1 100644 --- a/libs/api-client/src/sdk.gen.ts +++ b/libs/api-client/src/sdk.gen.ts @@ -3,7 +3,7 @@ import type { CancelablePromise } from './core/CancelablePromise'; import { OpenAPI } from './core/OpenAPI'; import { request as __request } from './core/request'; -import type { PostClassificationData, PostClassificationResponse, GetClassificationData, GetClassificationResponse, GetClassificationByClassificationIdData, GetClassificationByClassificationIdResponse, PatchClassificationByClassificationIdData, PatchClassificationByClassificationIdResponse, DeleteClassificationByClassificationIdData, DeleteClassificationByClassificationIdResponse, PostMeldingData, PostMeldingResponse, GetMeldingData, GetMeldingResponse, GetMeldingByMeldingIdData, GetMeldingByMeldingIdResponse, PatchMeldingByMeldingIdData, PatchMeldingByMeldingIdResponse, PutMeldingByMeldingIdAnswerQuestionsData, PutMeldingByMeldingIdAnswerQuestionsResponse, PutMeldingByMeldingIdAddAttachmentsData, PutMeldingByMeldingIdAddAttachmentsResponse, PutMeldingByMeldingIdSubmitLocationData, PutMeldingByMeldingIdSubmitLocationResponse, PutMeldingByMeldingIdProcessData, PutMeldingByMeldingIdProcessResponse, PutMeldingByMeldingIdCompleteData, PutMeldingByMeldingIdCompleteResponse, PostMeldingByMeldingIdQuestionByQuestionIdData, PostMeldingByMeldingIdQuestionByQuestionIdResponse, PostMeldingByMeldingIdAttachmentData, PostMeldingByMeldingIdAttachmentResponse, GetMeldingByMeldingIdAttachmentByAttachmentIdDownloadData, GetMeldingByMeldingIdAttachmentByAttachmentIdDownloadResponse, GetMeldingByMeldingIdAttachmentsData, GetMeldingByMeldingIdAttachmentsResponse, DeleteMeldingByMeldingIdAttachmentByAttachmentIdData, DeleteMeldingByMeldingIdAttachmentByAttachmentIdResponse, PostUserData, PostUserResponse, GetUserData, GetUserResponse, GetUserByUserIdData, GetUserByUserIdResponse, DeleteUserByUserIdData, DeleteUserByUserIdResponse, PatchUserByUserIdData, PatchUserByUserIdResponse, GetFormData, GetFormResponse, PostFormData, PostFormResponse, GetFormByFormIdData, GetFormByFormIdResponse, PutFormByFormIdData, PutFormByFormIdResponse, DeleteFormByFormIdData, DeleteFormByFormIdResponse, GetFormClassificationByClassificationIdData, GetFormClassificationByClassificationIdResponse, GetStaticFormByStaticFormIdData, GetStaticFormByStaticFormIdResponse, PutStaticFormByStaticFormIdData, PutStaticFormByStaticFormIdResponse, GetStaticFormData, GetStaticFormResponse } from './types.gen'; +import type { PostClassificationData, PostClassificationResponse, GetClassificationData, GetClassificationResponse, GetClassificationByClassificationIdData, GetClassificationByClassificationIdResponse, PatchClassificationByClassificationIdData, PatchClassificationByClassificationIdResponse, DeleteClassificationByClassificationIdData, DeleteClassificationByClassificationIdResponse, PostMeldingData, PostMeldingResponse, GetMeldingData, GetMeldingResponse, GetMeldingByMeldingIdData, GetMeldingByMeldingIdResponse, PatchMeldingByMeldingIdData, PatchMeldingByMeldingIdResponse, PutMeldingByMeldingIdAnswerQuestionsData, PutMeldingByMeldingIdAnswerQuestionsResponse, PutMeldingByMeldingIdAddAttachmentsData, PutMeldingByMeldingIdAddAttachmentsResponse, PutMeldingByMeldingIdSubmitLocationData, PutMeldingByMeldingIdSubmitLocationResponse, PutMeldingByMeldingIdProcessData, PutMeldingByMeldingIdProcessResponse, PutMeldingByMeldingIdCompleteData, PutMeldingByMeldingIdCompleteResponse, PostMeldingByMeldingIdQuestionByQuestionIdData, PostMeldingByMeldingIdQuestionByQuestionIdResponse, PostMeldingByMeldingIdAttachmentData, PostMeldingByMeldingIdAttachmentResponse, GetMeldingByMeldingIdAttachmentByAttachmentIdDownloadData, GetMeldingByMeldingIdAttachmentByAttachmentIdDownloadResponse, GetMeldingByMeldingIdAttachmentsData, GetMeldingByMeldingIdAttachmentsResponse, DeleteMeldingByMeldingIdAttachmentByAttachmentIdData, DeleteMeldingByMeldingIdAttachmentByAttachmentIdResponse, PostMeldingByMeldingIdLocationData, PostMeldingByMeldingIdLocationResponse, PostUserData, PostUserResponse, GetUserData, GetUserResponse, GetUserByUserIdData, GetUserByUserIdResponse, DeleteUserByUserIdData, DeleteUserByUserIdResponse, PatchUserByUserIdData, PatchUserByUserIdResponse, GetFormData, GetFormResponse, PostFormData, PostFormResponse, GetFormByFormIdData, GetFormByFormIdResponse, PutFormByFormIdData, PutFormByFormIdResponse, DeleteFormByFormIdData, DeleteFormByFormIdResponse, GetFormClassificationByClassificationIdData, GetFormClassificationByClassificationIdResponse, GetStaticFormByStaticFormIdData, GetStaticFormByStaticFormIdResponse, PutStaticFormByStaticFormIdData, PutStaticFormByStaticFormIdResponse, GetStaticFormData, GetStaticFormResponse } from './types.gen'; /** * Classification:Create @@ -490,6 +490,35 @@ export const deleteMeldingByMeldingIdAttachmentByAttachmentId = (data: DeleteMel }); }; +/** + * Melding:Add-Location + * @param data The data for the request. + * @param data.meldingId The id of the melding. + * @param data.token The token of the melding. + * @param data.requestBody + * @returns MeldingOutput Successful Response + * @throws ApiError + */ +export const postMeldingByMeldingIdLocation = (data: PostMeldingByMeldingIdLocationData): CancelablePromise => { + return __request(OpenAPI, { + method: 'POST', + url: '/melding/{melding_id}/location', + path: { + melding_id: data.meldingId + }, + query: { + token: data.token + }, + body: data.requestBody, + mediaType: 'application/json', + errors: { + 401: 'Unauthorized, perhaps the token was invalid or expired, or the user could not be found.', + 404: 'Not Found', + 422: 'Validation Error' + } + }); +}; + /** * User:Create * @param data The data for the request. @@ -795,7 +824,7 @@ export const putStaticFormByStaticFormId = (data: PutStaticFormByStaticFormIdDat * @param data.limit * @param data.offset * @param data.sort - * @returns StaticFormOutput Successful Response + * @returns SimpleStaticFormOutput Successful Response * @throws ApiError */ export const getStaticForm = (data: GetStaticFormData = {}): CancelablePromise => { diff --git a/libs/api-client/src/types.gen.ts b/libs/api-client/src/types.gen.ts index 2f86c22..ba551a1 100644 --- a/libs/api-client/src/types.gen.ts +++ b/libs/api-client/src/types.gen.ts @@ -45,6 +45,10 @@ export type AttachmentOutput = { export type AttachmentTypes = 'original' | 'optimized' | 'thumbnail'; +export type BaseModel = { + [key: string]: unknown; +}; + export type Body_melding_attachment_melding__melding_id__attachment_post = { file: (Blob | File); }; @@ -168,6 +172,7 @@ export type FormOutput = { export type FormPanelComponentInput = { label: string; + title: string; key: string; type?: FormIoComponentTypeEnum; input?: boolean; @@ -175,6 +180,7 @@ export type FormPanelComponentInput = { }; export type FormPanelComponentOutput = { + title: string; label: string; key: string; type: string; @@ -283,6 +289,50 @@ export type FormTextFieldInputComponentOutput = { question: number; }; +export type GeoJson_Input = { + bbox?: ([ + number, + number, + number, + number +] | [ + number, + number, + number, + number, + number, + number +] | null); + type: "Feature"; + geometry: (Point | null); + properties: ({ + [key: string]: unknown; +} | BaseModel | null); + id?: (number | string | null); +}; + +export type GeoJson_Output = { + bbox?: ([ + number, + number, + number, + number +] | [ + number, + number, + number, + number, + number, + number +] | null); + type: "Feature"; + geometry: (Point | null); + properties: ({ + [key: string]: unknown; +} | BaseModel | null); + id?: (number | string | null); +}; + export type GreaterThan = { '>': [ (number | string | Var), @@ -372,6 +422,7 @@ export type MeldingCreateOutput = { text: string; state: string; classification?: (number | null); + geo_location?: (GeoJson_Output | null); token: string; }; @@ -386,6 +437,7 @@ export type MeldingOutput = { text: string; state: string; classification?: (number | null); + geo_location?: (GeoJson_Output | null); }; export type Merge = { @@ -461,6 +513,38 @@ export type Or_Output = { or: Array<(boolean | number | string | Array<(null)> | Add | All_Output | And_Output | Cat | Divide | Equals | Filter_Output | GreaterThan | GreaterThanOrEqual | If | In_Output | LessThan | LessThanOrEqual | Log | Map_Output | Max | Merge | Min | Missing | MissingSome | Modulo | Multiply | None__Output | Not | NotEquals | NotNot | Or_Output | Reduce_Output | Some_Output | StrictEquals | StrictNotEquals | Substr | Subtract | Var)>; }; +/** + * Point Model + */ +export type Point = { + bbox?: ([ + number, + number, + number, + number +] | [ + number, + number, + number, + number, + number, + number +] | null); + type: "Point"; + coordinates: (Position2D | Position3D); +}; + +export type Position2D = [ + number, + number +]; + +export type Position3D = [ + number, + number, + number +]; + export type Reduce_Input = { reduce: [ (Array | Var | Missing | MissingSome | If | Merge | Filter_Input | Map_Input), @@ -486,6 +570,15 @@ export type SimpleFormOutput = { classification?: (number | null); }; +export type SimpleStaticFormOutput = { + id: number; + title: string; + display: string; + created_at: string; + updated_at: string; + type: string; +}; + export type Some_Input = { some: [ (Array | Var | Missing | MissingSome | If | Merge | Filter_Input | Map_Input), @@ -528,6 +621,7 @@ export type StaticFormOutput = { }; export type StaticFormPanelComponentOutput = { + title: string; label: string; key: string; type: string; @@ -868,6 +962,20 @@ export type DeleteMeldingByMeldingIdAttachmentByAttachmentIdData = { export type DeleteMeldingByMeldingIdAttachmentByAttachmentIdResponse = (unknown); +export type PostMeldingByMeldingIdLocationData = { + /** + * The id of the melding. + */ + meldingId: number; + requestBody: GeoJson_Input; + /** + * The token of the melding. + */ + token: string; +}; + +export type PostMeldingByMeldingIdLocationResponse = (MeldingOutput); + export type PostUserData = { requestBody: UserCreateInput; }; @@ -986,4 +1094,4 @@ export type GetStaticFormData = { sort?: string; }; -export type GetStaticFormResponse = (Array); \ No newline at end of file +export type GetStaticFormResponse = (Array); \ No newline at end of file