Skip to content

Commit 2a7c484

Browse files
committed
docs: clarify beforeSave usage and return contract in create hook
1 parent 39d7037 commit 2a7c484

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

adminforth/types/Back.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,9 +1346,13 @@ export interface AdminForthResource extends Omit<AdminForthResourceInput, 'optio
13461346
},
13471347
create?: {
13481348
/**
1349+
* Should return ok: true to continue saving pipeline and allow creating record in database, and ok: false to interrupt pipeline and prevent record creation.
1350+
* If you need to show error on UI, set error: <error message> in response.
1351+
*
13491352
* Typical use-cases:
1350-
* - Validate record before saving to database and interrupt execution if validation failed (`allowedActions.create` should be preferred in most cases)
1351-
* - fill-in adminUser as creator of record
1353+
* - Create record by custom code (return `{ ok: false, newRecordId: <id of created record from custom code>}`)
1354+
* - Validate record before saving to database and interrupt execution if validation failed (return `{ok: false, error: <validation error>}`), though `allowedActions.create` should be preferred in most cases
1355+
* - fill-in adminUser as creator of record (set record.<some field> = x; return {ok: true})
13521356
* - Attach additional data to record before saving to database (mostly fillOnCreate should be used instead)
13531357
*/
13541358
beforeSave?: Array<BeforeCreateSaveFunction>,

0 commit comments

Comments
 (0)