mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-30 22:16:14 +00:00
fix initialComment with patch endpoint
This commit is contained in:
parent
9ef397e935
commit
27f49b2aa3
@ -119,45 +119,10 @@ const postResource = (id, payload, method) => {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
* Endpoint v.2 chill_api_single_accompanying_course_comment,
|
||||
* method POST/DELETE/PATCH, add/remove a comment to the accompanyingCourse
|
||||
*
|
||||
* @id integer - id of accompanyingCourse
|
||||
* @payload
|
||||
* @method string - POST, DELETE or PATCH
|
||||
*/
|
||||
const postComment = (id, payload) => {
|
||||
console.log('payload', payload);
|
||||
const body = { type: "accompanying_period_comment" };
|
||||
switch (payload.method) {
|
||||
case 'POST':
|
||||
body['content'] = payload.content;
|
||||
break;
|
||||
case 'DELETE':
|
||||
body['id'] = 42;
|
||||
break;
|
||||
}
|
||||
console.log('body', body);
|
||||
const url = `/api/1.0/person/accompanying-course/${id}/comment.json`;
|
||||
return fetch(url, {
|
||||
method: payload.method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=utf-8'
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) { return response.json(); }
|
||||
throw Error('Error with request resource response');
|
||||
});
|
||||
};
|
||||
|
||||
export {
|
||||
getAccompanyingCourse,
|
||||
patchAccompanyingCourse,
|
||||
postParticipation,
|
||||
postRequestor,
|
||||
postResource,
|
||||
postComment
|
||||
};
|
||||
|
@ -6,12 +6,12 @@
|
||||
{{ errors[0] }}
|
||||
</div>
|
||||
|
||||
<div v-if="firstComment">
|
||||
créé par {{ firstComment.creator.text }}
|
||||
le {{ $d(firstComment.createdAt.datetime, 'long') }}
|
||||
<div v-if="firstComment.updatedAt.datetime !== firstComment.createdAt.datetime">
|
||||
modifié par {{ firstComment.updatedBy.text }}
|
||||
le {{ $d(firstComment.updatedAt.datetime, 'long') }}
|
||||
<div v-if="initialComment">
|
||||
créé par {{ initialComment.creator.text }}
|
||||
le {{ $d(initialComment.createdAt.datetime, 'long') }}
|
||||
<div v-if="initialComment.updatedAt.datetime !== initialComment.createdAt.datetime">
|
||||
modifié par {{ initialComment.updatedBy.text }}
|
||||
le {{ $d(initialComment.updatedAt.datetime, 'long') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -28,9 +28,17 @@
|
||||
<li>
|
||||
<button type="submit" class="sc-button bt-save">{{ $t('action.save') }}</button>
|
||||
</li>
|
||||
<li id="xyz">
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
|
||||
<button
|
||||
class="sc-button bt-delete"
|
||||
@click="removeComment">
|
||||
{{ $t('action.delete') }}
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -40,23 +48,21 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
formdata: {
|
||||
type: "accompanying_period_comment",
|
||||
content: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
comments() {
|
||||
return this.$store.state.accompanyingCourse.comments;
|
||||
},
|
||||
firstComment() {
|
||||
return this.comments[0];
|
||||
initialComment() {
|
||||
return this.$store.state.accompanyingCourse.initialComment;
|
||||
},
|
||||
content: {
|
||||
set(value) {
|
||||
this.formdata.content = value;
|
||||
},
|
||||
get() {
|
||||
return (this.comments.length > 0) ? this.comments[0].content : null ;
|
||||
return (this.initialComment)? this.initialComment.content : null;
|
||||
}
|
||||
},
|
||||
errors() {
|
||||
@ -65,8 +71,12 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
submitform() {
|
||||
this.formdata['method'] = (!this.firstComment)? 'POST' : 'PATCH';
|
||||
console.log('submit');
|
||||
this.$store.dispatch('postFirstComment', this.formdata);
|
||||
},
|
||||
removeComment() {
|
||||
console.log('remove');
|
||||
this.$store.dispatch('postFirstComment', null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ import { getAccompanyingCourse,
|
||||
patchAccompanyingCourse,
|
||||
postParticipation,
|
||||
postRequestor,
|
||||
postResource,
|
||||
postComment } from '../api';
|
||||
postResource } from '../api';
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
const id = window.accompanyingCourseId;
|
||||
@ -74,7 +73,8 @@ let initPromise = getAccompanyingCourse(id)
|
||||
state.accompanyingCourse.confidential = value;
|
||||
},
|
||||
postFirstComment(state, comment) {
|
||||
state.accompanyingCourse.comments.push(comment);
|
||||
console.log('### mutation: postFirstComment', comment);
|
||||
state.accompanyingCourse.initialComment = comment;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
@ -162,9 +162,10 @@ let initPromise = getAccompanyingCourse(id)
|
||||
})).catch((error) => { commit('catchError', error) });
|
||||
},
|
||||
postFirstComment({ commit }, payload) {
|
||||
postComment(id, payload)
|
||||
.then(comment => new Promise((resolve, reject) => {
|
||||
commit('postFirstComment', comment);
|
||||
console.log('## action: postFirstComment: payload', payload);
|
||||
patchAccompanyingCourse(id, { type: "accompanying_period", initialComment: payload })
|
||||
.then(course => new Promise((resolve, reject) => {
|
||||
commit('postFirstComment', course.initialComment);
|
||||
resolve();
|
||||
})).catch((error) => { commit('catchError', error) });
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user