mirror of https://github.com/wg-easy/wg-easy
9 changed files with 22 additions and 75 deletions
@ -83,9 +83,6 @@ importers: |
|||
zod: |
|||
specifier: ^3.24.1 |
|||
version: 3.24.1 |
|||
zod-form-data: |
|||
specifier: ^2.0.5 |
|||
version: 2.0.5([email protected]) |
|||
devDependencies: |
|||
'@nuxt/eslint-config': |
|||
specifier: ^0.7.3 |
|||
@ -4541,11 +4538,6 @@ packages: |
|||
resolution: {integrity: sha512-zK7YHHz4ZXpW89AHXUPbQVGKI7uvkd3hzusTdotCg1UxyaVtg0zFJSTfW/Dq5f7OBBVnq6cZIaC8Ti4hb6dtCA==} |
|||
engines: {node: '>= 14'} |
|||
|
|||
[email protected]: |
|||
resolution: {integrity: sha512-T7dV6lTBCwkd8PyvJVCnjXKpgXomU8gEm/TcvEZY7qNdRhIo9T17HrdlHIK68PzTAYaV2HxR9rgwpTSWv0L+QQ==} |
|||
peerDependencies: |
|||
zod: '>= 3.11.0' |
|||
|
|||
[email protected]: |
|||
resolution: {integrity: sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A==} |
|||
|
|||
@ -9426,8 +9418,4 @@ snapshots: |
|||
compress-commons: 6.0.2 |
|||
readable-stream: 4.5.2 |
|||
|
|||
[email protected]([email protected]): |
|||
dependencies: |
|||
zod: 3.24.1 |
|||
|
|||
[email protected]: {} |
|||
|
@ -1,31 +0,0 @@ |
|||
import type { H3Event, InferEventInput } from 'h3'; |
|||
|
|||
export async function readValidatedFormData< |
|||
Event extends H3Event = H3Event, |
|||
T = InferEventInput<'body', Event, null>, |
|||
>(event: Event, validate: (data: FormData) => T) { |
|||
const _form = await readFormData(event); |
|||
return validateData(_form, validate); |
|||
} |
|||
|
|||
async function validateData<T, K>(data: T, fn: (data: T) => K) { |
|||
try { |
|||
const res = await fn(data); |
|||
if (res === false) { |
|||
throw createValidationError(); |
|||
} |
|||
return res; |
|||
} catch (error) { |
|||
throw createValidationError(error); |
|||
} |
|||
} |
|||
|
|||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|||
function createValidationError(validateError?: any) { |
|||
throw createError({ |
|||
status: 400, |
|||
statusMessage: 'Validation Error', |
|||
message: validateError?.message || 'Validation Error', |
|||
data: validateError, |
|||
}); |
|||
} |
Loading…
Reference in new issue