From 3e67d18749687b2aeb44c300f0a5a7a752176d0c Mon Sep 17 00:00:00 2001 From: Lars Hampe Date: Fri, 1 Nov 2024 21:45:18 +0100 Subject: [PATCH] chore: fix build errors --- apps/api/src/changelog/version/createAuto.ts | 32 +++++++++++++------ .../Changelog/Version/Create/Step02.tsx | 2 +- .../changelog.$id.version.$versionId.tsx | 3 +- packages/schema/src/version/create.ts | 2 +- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/apps/api/src/changelog/version/createAuto.ts b/apps/api/src/changelog/version/createAuto.ts index b4bb119..85f91e3 100644 --- a/apps/api/src/changelog/version/createAuto.ts +++ b/apps/api/src/changelog/version/createAuto.ts @@ -44,6 +44,15 @@ export const route = createRoute({ }, }) +const getVersion = (version: string) => { + const isValid = semver.valid(semver.coerce(version)) + + if (isValid) { + return isValid + } + return format(new Date(), 'dd.MM.yy') +} + const getNextVersion = ({ version, isSemver, @@ -52,11 +61,15 @@ const getNextVersion = ({ if (version === '') { return '1.0.0' } - const nextVersion = semver.inc(version, 'patch') - if (!nextVersion) { - throw new Error('Incorrect semver') + const isValid = semver.valid(semver.coerce(version)) + + if (isValid) { + const nextVersion = semver.inc(isValid, 'patch') + if (!nextVersion) { + throw new Error('Incorrect semver') + } + return nextVersion } - return nextVersion } return format(new Date(), 'dd.MM.yy') } @@ -64,7 +77,6 @@ const getNextVersion = ({ export const registerVersionCreateAuto = (api: typeof changelogVersionApi) => { return api.openapi(route, async (c) => { const userId = verifyAuthentication(c) - const data: z.infer = await c.req.json() const changelogResult = await db.query.changelog.findFirst({ where: and( @@ -136,10 +148,12 @@ export const registerVersionCreateAuto = (api: typeof changelogVersionApi) => { .insert(changelog_version) .values({ changelogId: changelogResult.id, - version: getNextVersion({ - version: data.version ?? changelogResult.versions[0].version, - isSemver: changelogResult.isSemver ?? true, - }), + version: data.version + ? getVersion(data.version) + : getNextVersion({ + version: changelogResult.versions[0].version, + isSemver: changelogResult.isSemver ?? true, + }), status: 'draft', markdown, }) diff --git a/apps/app/src/components/Changelog/Version/Create/Step02.tsx b/apps/app/src/components/Changelog/Version/Create/Step02.tsx index f5431bb..f47b055 100644 --- a/apps/app/src/components/Changelog/Version/Create/Step02.tsx +++ b/apps/app/src/components/Changelog/Version/Create/Step02.tsx @@ -25,7 +25,7 @@ export const ChangelogVersionCreateStep02 = () => { resolver: zodResolver(VersionCreateAutoInput), defaultValues: { changelogId: id, - version: null, + version: '', }, }) diff --git a/apps/app/src/routes/changelog.$id.version.$versionId.tsx b/apps/app/src/routes/changelog.$id.version.$versionId.tsx index 2e3ab74..8729eae 100644 --- a/apps/app/src/routes/changelog.$id.version.$versionId.tsx +++ b/apps/app/src/routes/changelog.$id.version.$versionId.tsx @@ -43,7 +43,7 @@ import { import '@mdxeditor/editor/style.css' import { format } from 'date-fns' import { CalendarIcon } from 'lucide-react' -import { useEffect, useRef, useState } from 'react' +import { useEffect, useRef } from 'react' import { ChangelogVersionDelete } from '../components/Changelog/VersionDelete' import { VersionStatus } from '../components/Changelog/VersionStatus' @@ -55,7 +55,6 @@ const Component = () => { const { data, error, isPending, refetch } = useChangelogVersionById({ id: versionId, }) - const [editorValue, setEditorValue] = useState('') const form = useForm>({ resolver: zodResolver(VersionUpdateInput), defaultValues: data, diff --git a/packages/schema/src/version/create.ts b/packages/schema/src/version/create.ts index 4cc5169..0998631 100644 --- a/packages/schema/src/version/create.ts +++ b/packages/schema/src/version/create.ts @@ -17,7 +17,7 @@ export const VersionCreateInput = z export const VersionCreateAutoInput = z .object({ - version: z.string().optional().nullable(), + version: z.string().optional(), changelogId: z.string().uuid(), }) .openapi({