@@ -24,7 +24,7 @@ process.stdin.on('end', async () => {
2424 object [ object . _objecttype ] ,
2525 object . _objecttype ,
2626 object . _uuid ,
27- await getCurrentObjectData ( object [ object . _objecttype ] , object . _objecttype , object . _mask ) ,
27+ await getCurrentObjectData ( object [ object . _objecttype ] . _id , object . _objecttype ) ,
2828 configuration ,
2929 authorizationString
3030 ) ;
@@ -71,11 +71,11 @@ function getAuthorizationString(serverConfiguration) {
7171 return btoa ( username + ':' + password ) ;
7272}
7373
74- async function getCurrentObjectData ( object , objectType , mask ) {
75- if ( ! object . _id ) return undefined ;
74+ async function getCurrentObjectData ( objectId , objectType ) {
75+ if ( ! objectId ) return undefined ;
7676
77- const url = info . api_url + '/api/v1/db/' + objectType + '/' + mask + '/' + object . _id
78- + '?access_token=' + info . api_user_access_token ;
77+ const mask = await getPreferredMask ( objectType ) ;
78+ const url = info . api_url + '/api/v1/db/' + objectType + '/' + mask + '/' + objectId + '?access_token=' + info . api_user_access_token ;
7979
8080 try {
8181 const response = await fetch ( url , {
@@ -92,6 +92,25 @@ async function getCurrentObjectData(object, objectType, mask) {
9292 }
9393}
9494
95+ async function getPreferredMask ( objectType ) {
96+ const url = info . api_url + '/api/v1/mask/CURRENT?access_token=' + info . api_user_access_token ;
97+
98+ try {
99+ const response = await fetch ( url , {
100+ method : 'GET' ,
101+ headers : {
102+ 'Content-Type' : 'application/json'
103+ }
104+ } ) ;
105+ const result = await response . json ( ) ;
106+ const mask = result ?. masks ?. find ( mask => mask . table_name_hint === objectType && mask . is_preferred ) ?. name ;
107+ if ( ! mask ) throwErrorToFrontend ( 'Es konnte keine Maske für diesen Objekttyp gefunden werden.' ) ;
108+ return mask ;
109+ } catch ( err ) {
110+ throwErrorToFrontend ( 'Beim Abruf der Maske ist ein Fehler aufgetreten:' , err ) ;
111+ }
112+ }
113+
95114async function updateObject ( object , objectType , uuid , currentObject , configuration , authorizationString ) {
96115 const wfsConfiguration = getWFSConfiguration ( configuration , objectType ) ;
97116 if ( ! wfsConfiguration ) return ;
0 commit comments