@@ -67,7 +67,7 @@ const emits = defineEmits(['refreshTarget'])
6767const $q = useQuasar ()
6868const router = useRouter ()
6969const { getStateColor, getStateName } = useIdentityStates ()
70- const { handleError } = useErrorHandling ()
70+ const { handleError, handleErrorReq } = useErrorHandling ()
7171
7272const identity = ref <Identity >(props .identity )
7373const tabs = ref (props .identity ?.additionalFields ?.objectClasses ?? [])
@@ -106,37 +106,60 @@ async function addSchema(schema) {
106106}
107107
108108async function submit() {
109- const sanitizedIdentity = { ... props . identity }
109+ const sanitizedIdentity = { ... identity . value }
110110 delete sanitizedIdentity .metadata
111111 if (sanitizedIdentity ?.additionalFields ?.validations ) delete sanitizedIdentity .additionalFields .validations
112112
113- const { data : result, pending, error, refresh } = await useHttp <any >(` /management/identities/${props .identity ._id } ` , { method: ' PATCH' , body: sanitizedIdentity })
114- if (error .value ) {
115- console .log (' error' , error .value .data .validations )
116- validations .value = { ... error .value .data .validations }
117- // error.value = error.value.cause.response._data
118- handleError ({ error: error .value , message: ' Erreur lors de la sauvegarde' })
119- } else {
120- validations .value = null
113+ const requestOptions = { method: ' PATCH' , body: JSON .stringify (sanitizedIdentity ) }
114+ try {
115+ const result = await $http .patch (` /management/identities/${identity .value ._id } ` , requestOptions )
121116 $q .notify ({ message: ' Sauvegarde effectuée' , color: ' positive' , position: ' top-right' , icon: ' mdi-check-circle-outline' })
122- emits (' refreshTarget' , { ... result .value .data })
117+ validations .value = null
118+ } catch (error ) {
119+ handleErrorReq ({ error: error , message: ' Erreur lors de la sauvegarde' })
120+ console .log (' error' , error .data .validations )
121+ validations .value = { ... error .data .validations }
123122 }
123+
124+ // const { data: result, pending, error, refresh } = await useHttp<any>(`/management/identities/${identity.value._id}`, { method: 'PATCH', body: sanitizedIdentity })
125+ // if (error.value) {
126+ // console.log('error', error.value.data.validations)
127+ // validations.value = { ...error.value.data.validations }
128+ // // error.value = error.value.cause.response._data
129+ // handleError({ error: error.value, message: 'Erreur lors de la sauvegarde' })
130+ // } else {
131+ // validations.value = null
132+ // $q.notify({ message: 'Sauvegarde effectuée', color: 'positive', position: 'top-right', icon: 'mdi-check-circle-outline' })
133+ // emits('refreshTarget', { ...result.value.data })
134+ // }
124135}
125136
126137async function create() {
127- console .log (' create from form' )
128- const sanitizedIdentity = { ... props .identity }
138+ const sanitizedIdentity = { ... identity .value }
129139 delete sanitizedIdentity .metadata
140+ console .log (' create from form' , sanitizedIdentity )
130141
131- const { data : result, pending, error, refresh } = await useHttp (` /management/identities ` , { method: ' POST' , body: { ... sanitizedIdentity } })
132- if (error .value ) {
133- handleError ({ error: error .value , message: ' Erreur lors de la création' })
134- console .log (' error' , error .value .data .validations )
135- validations .value = { ... error .value .data .validations }
136- } else {
142+ const requestOptions = { method: ' POST' , body: JSON .stringify (sanitizedIdentity ) }
143+ try {
144+ const data = await $http .post (` /management/identities ` , requestOptions )
137145 $q .notify ({ message: ' Création effectuée' , color: ' positive' , position: ' top-right' , icon: ' mdi-check-circle-outline' })
138146 emits (' refreshTarget' , {})
147+ validations .value = null
148+ } catch (error ) {
149+ handleErrorReq ({ error: error , message: ' Erreur lors de la création' })
150+ console .log (' error' , error .data .validations )
151+ validations .value = { ... error .data .validations }
139152 }
153+
154+ // const { data: result, pending, error, refresh } = await useHttp(`/management/identities`, { method: 'POST', body: { ...sanitizedIdentity } })
155+ // if (error.value) {
156+ // handleError({ error: error.value, message: 'Erreur lors de la création' })
157+ // console.log('error', error.value.data.validations)
158+ // validations.value = { ...error.value.data.validations }
159+ // } else {
160+ // $q.notify({ message: 'Création effectuée', color: 'positive', position: 'top-right', icon: 'mdi-check-circle-outline' })
161+ // emits('refreshTarget', {})
162+ // }
140163}
141164
142165const stateName = computed (() => {
0 commit comments