|
|
@@ -27,7 +27,7 @@ export interface Resource { |
|
|
|
routeName?: string; |
|
|
|
dataSource: DataSource; |
|
|
|
newId(dataSource: DataSource): string | number | unknown; |
|
|
|
schema: Parameters<typeof v.object>[0]; |
|
|
|
schema: v.BaseSchema; |
|
|
|
} |
|
|
|
|
|
|
|
interface GenerationStrategy { |
|
|
@@ -38,7 +38,7 @@ interface IdParams { |
|
|
|
generationStrategy: GenerationStrategy; |
|
|
|
} |
|
|
|
|
|
|
|
export const resource = (schema: Parameters<typeof v.object>[0]) => { |
|
|
|
export const resource = <T extends v.BaseSchema>(schema: T) => { |
|
|
|
let theIdAttr: string; |
|
|
|
let theItemName: string; |
|
|
|
let theCollectionName: string; |
|
|
@@ -56,7 +56,7 @@ export const resource = (schema: Parameters<typeof v.object>[0]) => { |
|
|
|
return idGenerationStrategy(dataSource); |
|
|
|
}, |
|
|
|
fullText(fullTextAttr: string) { |
|
|
|
if (schema[fullTextAttr]?.type === 'string') { |
|
|
|
if (schema.type === 'object' && (schema as unknown as v.ObjectSchema<Record<string, v.BaseSchema>, undefined, Record<string, string>>).entries[fullTextAttr]?.type === 'string') { |
|
|
|
fullTextAttrs.add(fullTextAttr); |
|
|
|
return this; |
|
|
|
} |
|
|
@@ -155,7 +155,7 @@ const handleCreate = async ( |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
await v.parseAsync(v.object(resource.schema), bodyDeserialized, { abortEarly: false }); |
|
|
|
bodyDeserialized = await v.parseAsync(resource.schema, bodyDeserialized, { abortEarly: false }); |
|
|
|
} catch (err) { |
|
|
|
res.statusCode = constants.HTTP_STATUS_BAD_REQUEST; |
|
|
|
res.statusMessage = `Invalid ${resource.itemName}`; |
|
|
|