|
|
@@ -27,6 +27,7 @@ export interface Resource { |
|
|
|
routeName?: string; |
|
|
|
dataSource: DataSource; |
|
|
|
newId(dataSource: DataSource): string | number | unknown; |
|
|
|
schema: Parameters<typeof v.object>[0]; |
|
|
|
} |
|
|
|
|
|
|
|
interface GenerationStrategy { |
|
|
@@ -88,6 +89,9 @@ export const resource = (schema: Parameters<typeof v.object>[0]) => { |
|
|
|
}, |
|
|
|
get routeName() { |
|
|
|
return theRouteName; |
|
|
|
}, |
|
|
|
get schema() { |
|
|
|
return schema; |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
@@ -150,10 +154,21 @@ const handleCreate = async ( |
|
|
|
resolve(); |
|
|
|
return; |
|
|
|
} |
|
|
|
} catch { |
|
|
|
|
|
|
|
await v.parseAsync(v.object(resource.schema), bodyDeserialized, { abortEarly: false }); |
|
|
|
} catch (err) { |
|
|
|
res.statusCode = constants.HTTP_STATUS_BAD_REQUEST; |
|
|
|
res.statusMessage = `Invalid ${resource.itemName}`; |
|
|
|
res.end(); |
|
|
|
|
|
|
|
if (Array.isArray(err.issues)) { |
|
|
|
// TODO better error reporting, localizable messages |
|
|
|
res.end( |
|
|
|
err.issues.map((i) => `${i.path.map((p) => p.key).join('.')}:\n${i.message}`) |
|
|
|
.join('\n\n') |
|
|
|
) |
|
|
|
} else { |
|
|
|
res.end(); |
|
|
|
} |
|
|
|
resolve(); |
|
|
|
return; |
|
|
|
} |
|
|
|