mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 06:26:15 +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 {
|
export {
|
||||||
getAccompanyingCourse,
|
getAccompanyingCourse,
|
||||||
patchAccompanyingCourse,
|
patchAccompanyingCourse,
|
||||||
postParticipation,
|
postParticipation,
|
||||||
postRequestor,
|
postRequestor,
|
||||||
postResource,
|
postResource,
|
||||||
postComment
|
|
||||||
};
|
};
|
||||||
|
@ -6,12 +6,12 @@
|
|||||||
{{ errors[0] }}
|
{{ errors[0] }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="firstComment">
|
<div v-if="initialComment">
|
||||||
créé par {{ firstComment.creator.text }}
|
créé par {{ initialComment.creator.text }}
|
||||||
le {{ $d(firstComment.createdAt.datetime, 'long') }}
|
le {{ $d(initialComment.createdAt.datetime, 'long') }}
|
||||||
<div v-if="firstComment.updatedAt.datetime !== firstComment.createdAt.datetime">
|
<div v-if="initialComment.updatedAt.datetime !== initialComment.createdAt.datetime">
|
||||||
modifié par {{ firstComment.updatedBy.text }}
|
modifié par {{ initialComment.updatedBy.text }}
|
||||||
le {{ $d(firstComment.updatedAt.datetime, 'long') }}
|
le {{ $d(initialComment.updatedAt.datetime, 'long') }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -28,9 +28,17 @@
|
|||||||
<li>
|
<li>
|
||||||
<button type="submit" class="sc-button bt-save">{{ $t('action.save') }}</button>
|
<button type="submit" class="sc-button bt-save">{{ $t('action.save') }}</button>
|
||||||
</li>
|
</li>
|
||||||
|
<li id="xyz">
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<button
|
||||||
|
class="sc-button bt-delete"
|
||||||
|
@click="removeComment">
|
||||||
|
{{ $t('action.delete') }}
|
||||||
|
</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -40,23 +48,21 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
formdata: {
|
formdata: {
|
||||||
|
type: "accompanying_period_comment",
|
||||||
content: ''
|
content: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
comments() {
|
initialComment() {
|
||||||
return this.$store.state.accompanyingCourse.comments;
|
return this.$store.state.accompanyingCourse.initialComment;
|
||||||
},
|
|
||||||
firstComment() {
|
|
||||||
return this.comments[0];
|
|
||||||
},
|
},
|
||||||
content: {
|
content: {
|
||||||
set(value) {
|
set(value) {
|
||||||
this.formdata.content = value;
|
this.formdata.content = value;
|
||||||
},
|
},
|
||||||
get() {
|
get() {
|
||||||
return (this.comments.length > 0) ? this.comments[0].content : null ;
|
return (this.initialComment)? this.initialComment.content : null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
errors() {
|
errors() {
|
||||||
@ -65,8 +71,12 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
submitform() {
|
submitform() {
|
||||||
this.formdata['method'] = (!this.firstComment)? 'POST' : 'PATCH';
|
console.log('submit');
|
||||||
this.$store.dispatch('postFirstComment', this.formdata);
|
this.$store.dispatch('postFirstComment', this.formdata);
|
||||||
|
},
|
||||||
|
removeComment() {
|
||||||
|
console.log('remove');
|
||||||
|
this.$store.dispatch('postFirstComment', null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,7 @@ import { getAccompanyingCourse,
|
|||||||
patchAccompanyingCourse,
|
patchAccompanyingCourse,
|
||||||
postParticipation,
|
postParticipation,
|
||||||
postRequestor,
|
postRequestor,
|
||||||
postResource,
|
postResource } from '../api';
|
||||||
postComment } from '../api';
|
|
||||||
|
|
||||||
const debug = process.env.NODE_ENV !== 'production';
|
const debug = process.env.NODE_ENV !== 'production';
|
||||||
const id = window.accompanyingCourseId;
|
const id = window.accompanyingCourseId;
|
||||||
@ -74,7 +73,8 @@ let initPromise = getAccompanyingCourse(id)
|
|||||||
state.accompanyingCourse.confidential = value;
|
state.accompanyingCourse.confidential = value;
|
||||||
},
|
},
|
||||||
postFirstComment(state, comment) {
|
postFirstComment(state, comment) {
|
||||||
state.accompanyingCourse.comments.push(comment);
|
console.log('### mutation: postFirstComment', comment);
|
||||||
|
state.accompanyingCourse.initialComment = comment;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
@ -162,9 +162,10 @@ let initPromise = getAccompanyingCourse(id)
|
|||||||
})).catch((error) => { commit('catchError', error) });
|
})).catch((error) => { commit('catchError', error) });
|
||||||
},
|
},
|
||||||
postFirstComment({ commit }, payload) {
|
postFirstComment({ commit }, payload) {
|
||||||
postComment(id, payload)
|
console.log('## action: postFirstComment: payload', payload);
|
||||||
.then(comment => new Promise((resolve, reject) => {
|
patchAccompanyingCourse(id, { type: "accompanying_period", initialComment: payload })
|
||||||
commit('postFirstComment', comment);
|
.then(course => new Promise((resolve, reject) => {
|
||||||
|
commit('postFirstComment', course.initialComment);
|
||||||
resolve();
|
resolve();
|
||||||
})).catch((error) => { commit('catchError', error) });
|
})).catch((error) => { commit('catchError', error) });
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user