Update version within PUT request

Try to add api logic

check for version being the same instead of smaller

implementing optimistic locking and displaying correct message in frontend

rector fixes

adjust violation message and add translation in translation.yaml

add translator in apiController
This commit is contained in:
2023-11-29 16:14:19 +01:00
committed by Julien Fastré
parent f00b39980c
commit 3bb911b4d0
7 changed files with 70 additions and 11 deletions

View File

@@ -599,7 +599,7 @@ export default {
},
submit() {
this.$store.dispatch('submit').catch((error) => {
if (error.name === 'ValidationException' || error.name === 'AccessException') {
if (error.name === 'ValidationException' || error.name === 'AccessException' || error.name === 'ConflictHttpException') {
error.violations.forEach((violation) => this.$toast.open({message: violation}));
} else {
this.$toast.open({message: 'An error occurred'});

View File

@@ -75,6 +75,7 @@ const store = createStore({
return {
type: 'accompanying_period_work',
id: state.work.id,
version: state.version,
startDate: state.startDate === null || state.startDate === '' ? null : {
datetime: datetimeToISO(ISOToDate(state.startDate))
},
@@ -505,19 +506,22 @@ const store = createStore({
url = `/api/1.0/person/accompanying-course/work/${state.work.id}.json`,
errors = []
;
commit('setIsPosting', true);
console.log('the social action', payload);
// console.log('the social action', payload);
return makeFetch('PUT', url, payload)
.then(data => {
if (typeof(callback) !== 'undefined') {
return callback(data);
} else {
console.info('nothing to do here, bye bye');
// console.log('payload', payload.privateComment)
// console.info('nothing to do here, bye bye');
window.location.assign(`/fr/person/accompanying-period/${state.work.accompanyingPeriod.id}/work`);
}
}).catch(error => {
console.log('error', error)
commit('setIsPosting', false);
throw error;
});