File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed
Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -319,6 +319,23 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
319319 }
320320 recordWithOriginalValues [ col . name ] = this . setFieldValue ( col , newValues [ col . name ] ) ;
321321 }
322+
323+ let error : string | null = null ;
324+ await Promise . all (
325+ resource . dataSourceColumns . map ( async ( col ) => {
326+ if ( col . isUnique && ! col . virtual && ! error ) {
327+ const exists = await this . checkUnique ( resource , col , recordWithOriginalValues [ col . name ] ) ;
328+ if ( exists ) {
329+ error = `Record with ${ col . name } ${ recordWithOriginalValues [ col . name ] } already exists` ;
330+ }
331+ }
332+ } )
333+ ) ;
334+ if ( error ) {
335+ process . env . HEAVY_DEBUG && console . log ( '🪲🆕 check unique error' , error ) ;
336+ return { error, ok : false } ;
337+ }
338+
322339
323340 process . env . HEAVY_DEBUG && console . log ( `🪲✏️ updating record id:${ recordId } , values: ${ JSON . stringify ( recordWithOriginalValues ) } ` ) ;
324341
Original file line number Diff line number Diff line change @@ -645,7 +645,10 @@ class AdminForth implements IAdminForth {
645645 }
646646
647647 if ( Object . keys ( newValues ) . length > 0 ) {
648- await connector . updateRecord ( { resource, recordId, newValues } ) ;
648+ const { error } = await connector . updateRecord ( { resource, recordId, newValues } ) ;
649+ if ( error ) {
650+ return { error } ;
651+ }
649652 }
650653
651654 // execute hook if needed
Original file line number Diff line number Diff line change @@ -191,9 +191,9 @@ async function saveRecord() {
191191 variant: ' success' ,
192192 timeout: 400000
193193 });
194+ router .push ({ name: ' resource-show' , params: { resourceId: route .params .resourceId , primaryKey: resp .recordId } });
194195 }
195196 saving .value = false ;
196- router .push ({ name: ' resource-show' , params: { resourceId: route .params .resourceId , primaryKey: resp .recordId } });
197197}
198198
199199 </script >
You can’t perform that action at this time.
0 commit comments