Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix updatePost service to work for comments like it used to #324

Merged
merged 1 commit into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default {
this.formPending = true
this.$emit('update:pending', true)

try {
try {
const result = await updatePost(this.formData)
if (!result.errors) {
this.$emit('update:success', result.data.postUpdate.id)
Expand Down
30 changes: 15 additions & 15 deletions src/app/services/updatePost.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import http from "@/app/http";

export async function updatePost(formData, photo) {
//if post is coming in with an ID then remove that property.
const photoCopy = Object.assign({}, photo);
delete photoCopy.id;
photoCopy.post_id = formData.id;
const variables = {
id: formData.id,
post: formData.post
};
if (photo) {
// if post is coming in with an ID then remove that property.
const photoCopy = Object.assign({}, photo);
delete photoCopy.id;
photoCopy.post_id = formData.id;
variables.photo = photoCopy;
variables.photo_id = photo.id;
}
return http
.post("/graphql", {
query: `
mutation ($id:ID!, $photo_id: ID!, $photo: PhotoInput!, $post: PostInput!) {
mutation ($id:ID!, ${photo ? "$photo_id: ID!, $photo: PhotoInput!, " : ''}$post: PostInput!) {
postUpdate(id: $id, post:$post) {
id
detail
Expand All @@ -24,17 +32,9 @@ export async function updatePost(formData, photo) {
uid
}
}
photoUpdate(id: $photo_id, photo: $photo)
{
id
},
${photo ? "photoUpdate(id: $photo_id, photo: $photo) { id }," : '' }
}`,
variables: {
id: formData.id,
post: formData.post,
photo: photoCopy,
photo_id: photo.id,
},
variables: variables,
})
.then((response) => {
return response.data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default {
async submitPost () {
this.formPending = true
try {
//upload the details collected from the form, not just reach id etc.
// upload the details collected from the form, not just reach id etc.
await updatePost(this.postFormData, { ...this.formData.photo, id: this.formData.id })

this.$emit('form:success')
Expand Down