@@ -78,18 +78,10 @@ export const lists = {
7878 // defaultValue: { kind: 'now' }
7979
8080 hooks : {
81- resolveInput : ( { context, operation, resolvedData } ) => {
82- if ( operation === 'create' ) return new Date ( )
83- return resolvedData . createdAt
84- } ,
85- } ,
86-
87- // TODO: this would be nice
88- // hooks: {
89- // resolveInput: {
90- // create: () => new Date()
91- // }
92- // }
81+ resolveInput : {
82+ create : ( ) => new Date ( )
83+ }
84+ }
9385 } ) ,
9486
9587 updatedBy : text ( { ...readOnly } ) ,
@@ -102,18 +94,10 @@ export const lists = {
10294 // },
10395
10496 hooks : {
105- resolveInput : ( { context, operation, resolvedData } ) => {
106- if ( operation === 'update' ) return new Date ( )
107- return resolvedData . updatedAt
108- } ,
109- } ,
110-
111- // TODO: this would be nice
112- // hooks: {
113- // resolveInput: {
114- // update: () => new Date()
115- // }
116- // }
97+ resolveInput : {
98+ update : ( ) => new Date ( )
99+ }
100+ }
117101 } ) ,
118102 } ,
119103 } ) ,
@@ -131,29 +115,37 @@ export const lists = {
131115 return resolvedData
132116 } ,
133117 } ,
134- validateInput : ( { context, operation, inputData, addValidationError } ) => {
135- const { title, content } = inputData
136-
137- if ( operation === 'update' && 'feedback' in inputData ) {
138- const { feedback } = inputData
139- if ( / p r o f a n i t y / i. test ( feedback ?? '' ) ) return addValidationError ( 'Unacceptable feedback' )
140- }
118+ validate : {
119+ create : ( { inputData, addValidationError } ) => {
120+ const { title, content } = inputData
121+
122+
123+ // an example of a content filter, the prevents the title or content containing the word "Profanity"
124+ if ( / p r o f a n i t y / i. test ( title ) ) return addValidationError ( 'Unacceptable title' )
125+ if ( / p r o f a n i t y / i. test ( content ) ) return addValidationError ( 'Unacceptable content' )
126+ } ,
127+ update : ( { inputData, addValidationError } ) => {
128+ const { title, content } = inputData
141129
142- // an example of a content filter, the prevents the title or content containing the word "Profanity"
143- if ( / p r o f a n i t y / i. test ( title ) ) return addValidationError ( 'Unacceptable title' )
144- if ( / p r o f a n i t y / i. test ( content ) ) return addValidationError ( 'Unacceptable content' )
145- } ,
146- validateDelete : ( { context, item, addValidationError } ) => {
147- const { preventDelete } = item
130+ if ( 'feedback' in inputData ) {
131+ const { feedback } = inputData
132+ if ( / p r o f a n i t y / i. test ( feedback ?? '' ) ) return addValidationError ( 'Unacceptable feedback' )
133+ }
148134
149- // an example of a content filter, the prevents the title or content containing the word "Profanity"
150- if ( preventDelete ) return addValidationError ( 'Cannot delete Post, preventDelete is true' )
135+ // an example of a content filter, the prevents the title or content containing the word "Profanity"
136+ if ( / p r o f a n i t y / i. test ( title ) ) return addValidationError ( 'Unacceptable title' )
137+ if ( / p r o f a n i t y / i. test ( content ) ) return addValidationError ( 'Unacceptable content' )
138+ } ,
139+ delete : ( { context, item, addValidationError } ) => {
140+ const { preventDelete } = item
141+
142+ // an example of a content filter, the prevents the title or content containing the word "Profanity"
143+ if ( preventDelete ) return addValidationError ( 'Cannot delete Post, preventDelete is true' )
144+ } ,
151145 } ,
152-
153146 beforeOperation : ( { item, resolvedData, operation } ) => {
154147 console . log ( `Post beforeOperation.${ operation } ` , resolvedData )
155148 } ,
156-
157149 afterOperation : {
158150 create : ( { inputData, item } ) => {
159151 console . log ( `Post afterOperation.create` , inputData , '->' , item )
@@ -162,7 +154,6 @@ export const lists = {
162154 update : ( { originalItem, item } ) => {
163155 console . log ( `Post afterOperation.update` , originalItem , '->' , item )
164156 } ,
165-
166157 delete : ( { originalItem } ) => {
167158 console . log ( `Post afterOperation.delete` , originalItem , '-> deleted' )
168159 } ,
0 commit comments