File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
1212 HttpExtra ,
1313 IAdminForthAndOrFilter ,
1414 BackendOnlyInput ,
15+ Filters ,
1516} from "../types/Back.js" ;
1617
1718import { ADMINFORTH_VERSION , listify , md5hash , getLoginPromptHTML } from './utils.js' ;
@@ -1180,6 +1181,14 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
11801181 }
11811182 }
11821183
1184+ const primaryKeyColumn = resource . columns . find ( ( col ) => col . primaryKey ) ;
1185+ if ( record [ primaryKeyColumn . name ] !== undefined ) {
1186+ const existingRecord = await this . adminforth . resource ( resource . resourceId ) . get ( [ Filters . EQ ( primaryKeyColumn . name , record [ primaryKeyColumn . name ] ) ] ) ;
1187+ if ( existingRecord ) {
1188+ return { error : `Record with ${ primaryKeyColumn . name } '${ record [ primaryKeyColumn . name ] } ' already exists` , ok : false } ;
1189+ }
1190+ }
1191+
11831192 const ctxCreate = {
11841193 adminUser,
11851194 resource,
@@ -1296,6 +1305,14 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
12961305 return { error : allowedError } ;
12971306 }
12981307
1308+ const primaryKeyColumn = resource . columns . find ( ( col ) => col . primaryKey ) ;
1309+ if ( record [ primaryKeyColumn . name ] !== undefined ) {
1310+ const existingRecord = await this . adminforth . resource ( resource . resourceId ) . get ( [ Filters . EQ ( primaryKeyColumn . name , record [ primaryKeyColumn . name ] ) ] ) ;
1311+ if ( existingRecord ) {
1312+ return { error : `Record with ${ primaryKeyColumn . name } '${ record [ primaryKeyColumn . name ] } ' already exists` , ok : false } ;
1313+ }
1314+ }
1315+
12991316 const ctxEdit = {
13001317 adminUser,
13011318 resource,
You can’t perform that action at this time.
0 commit comments