chore: fix build errors
All checks were successful
Build and Push Docker Image / tests (push) Successful in 39s
Build and Push Docker Image / build (push) Successful in 4m38s

This commit is contained in:
Lars Hampe 2024-11-01 21:45:18 +01:00
parent 1be0facd64
commit 3e67d18749
4 changed files with 26 additions and 13 deletions

View File

@ -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<typeof VersionCreateAutoInput> = 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,
})

View File

@ -25,7 +25,7 @@ export const ChangelogVersionCreateStep02 = () => {
resolver: zodResolver(VersionCreateAutoInput),
defaultValues: {
changelogId: id,
version: null,
version: '',
},
})

View File

@ -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<z.infer<typeof VersionUpdateInput>>({
resolver: zodResolver(VersionUpdateInput),
defaultValues: data,

View File

@ -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({