Skip to content

Commit 126c64d

Browse files
committed
feat: add validation for the field name
1 parent 3da1270 commit 126c64d

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

index.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AdminForthPlugin } from "adminforth";
22
import type { IAdminForth, IHttpServer, AdminForthResourcePages, AdminForthResourceColumn, AdminForthDataTypes, AdminForthResource, AdminForthComponentDeclaration } from "adminforth";
33
import type { PluginOptions } from './types.js';
4-
4+
import { suggestIfTypo } from "adminforth";
55

66
export default class extends AdminForthPlugin {
77
options: PluginOptions;
@@ -30,7 +30,13 @@ export default class extends AdminForthPlugin {
3030
}
3131

3232
validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
33-
// optional method where you can safely check field types after database discovery was performed
33+
for ( const colOpt of this.options.columns ) {
34+
const column = resourceConfig.columns.find(c => c.name === colOpt.column);
35+
if ( !column ) {
36+
const similar = suggestIfTypo(resourceConfig.columns.map((column: any) => column.name), colOpt.column);
37+
throw new Error(`QuickFilters plugin: column '${colOpt.column}' not found in resource '${resourceConfig.resourceId}'. Did you mean '${similar}'?`);
38+
}
39+
}
3440
}
3541

3642
instanceUniqueRepresentation(pluginOptions: any) : string {
@@ -39,15 +45,4 @@ export default class extends AdminForthPlugin {
3945
return `single`;
4046
}
4147

42-
setupEndpoints(server: IHttpServer) {
43-
server.endpoint({
44-
method: 'POST',
45-
path: `/plugin/${this.pluginInstanceId}/example`,
46-
handler: async ({ body }) => {
47-
const { name } = body;
48-
return { hey: `Hello ${name}` };
49-
}
50-
});
51-
}
52-
5348
}

0 commit comments

Comments
 (0)