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