Skip to content
Snippets Groups Projects
Commit 19c70481 authored by Timothee P's avatar Timothee P :sunflower:
Browse files

implement comment attachment post

parent d5b802ae
No related branches found
No related tags found
No related merge requests found
...@@ -22,31 +22,36 @@ const featureAPI = { ...@@ -22,31 +22,36 @@ const featureAPI = {
const response = await axios.post( const response = await axios.post(
`${baseUrl}features/${featureId}/comments/`, { comment } `${baseUrl}features/${featureId}/comments/`, { comment }
); );
console.log(response)
if ( if (
response.status === 200 && response.status === 200 &&
response.data response.data
) { ) {
return response.data; return response;
} else { } else {
return null; return null;
} }
}, },
/* async subscribeProject({ projectSlug, suscribe }) { async postCommentAttachment({ featureId, file, fileName, comment }) {
const response = await axios.put( let formdata = new FormData();
`${baseUrl}projects/${projectSlug}/subscription/`, formdata.append("file", file, fileName);
{ is_suscriber: suscribe } const data = {
comment
}
formdata.append("data", JSON.stringify(data));
const response = await axios.post(
`${baseUrl}features/${featureId}/attachments/`, formdata
); );
if ( if (
response.status === 200 && response.status === 200 &&
response.data response.data
) { ) {
return response.data; return response;
} else { } else {
return null; return null;
} }
}, */ },
} }
export default featureAPI; export default featureAPI;
...@@ -411,6 +411,7 @@ export default { ...@@ -411,6 +411,7 @@ export default {
attachment_file: { attachment_file: {
errors: null, errors: null,
value: null, value: null,
file: null,
}, },
title: { title: {
id_for_label: "title", id_for_label: "title",
...@@ -452,10 +453,21 @@ export default { ...@@ -452,10 +453,21 @@ export default {
methods: { methods: {
postComment() { postComment() {
featureAPI.postComment({ featureAPI
featureId: this.$route.params.slug_signal, .postComment({
comment: this.comment_form.comment.value, featureId: this.$route.params.slug_signal,
}); comment: this.comment_form.comment.value,
})
.then((response) => {
if (response && this.comment_form.attachment_file.file) {
featureAPI.postCommentAttachment({
featureId: this.$route.params.slug_signal,
file: this.comment_form.attachment_file.file,
fileName: this.comment_form.title.file,
comment: response.data.id,
});
}
});
}, },
getAttachmentFileData(evt) { getAttachmentFileData(evt) {
...@@ -464,6 +476,7 @@ export default { ...@@ -464,6 +476,7 @@ export default {
const fileName = files[0].name.substring(0, period); const fileName = files[0].name.substring(0, period);
const fileExtension = files[0].name.substring(period + 1); const fileExtension = files[0].name.substring(period + 1);
const shortName = fileName.slice(0, 10) + "[...]." + fileExtension; const shortName = fileName.slice(0, 10) + "[...]." + fileExtension;
this.comment_form.attachment_file.file = files[0];
this.comment_form.attachment_file.value = shortName; this.comment_form.attachment_file.value = shortName;
this.comment_form.title.value = shortName; this.comment_form.title.value = shortName;
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment