Social: Use socialService.js instead of socialpost.js

pull/5426/head
Angel Fernando Quiroz Campos 1 year ago
parent a69a6f0c45
commit d776bc8d10
  1. 9
      assets/vue/components/social/SocialWallPostForm.vue
  2. 16
      assets/vue/services/socialService.js
  3. 14
      assets/vue/services/socialpost.js

@ -59,7 +59,7 @@ import BaseCheckbox from "../basecomponents/BaseCheckbox.vue"
import BaseInputTextWithVuelidate from "../basecomponents/BaseInputTextWithVuelidate.vue"
import { useRoute } from "vue-router"
import { useSecurityStore } from "../../store/securityStore"
import socialPostService from "../../services/socialpost"
import socialService from "../../services/socialService"
import { useNotification } from "../../composables/notification"
const emit = defineEmits(["post-created"])
@ -138,13 +138,13 @@ async function sendPost() {
}
try {
const response = await socialPostService.create({
const post = await socialService.createPost({
content: postState.content,
type: postState.isPromoted ? SOCIAL_TYPE_PROMOTED_MESSAGE : SOCIAL_TYPE_WALL_POST,
sender: securityStore.user["@id"],
userReceiver: securityStore.user["@id"] === user.value["@id"] ? null : user.value["@id"],
})
const post = await response.json()
if (selectedFile.value) {
const formData = new FormData()
let idUrl = post["@id"]
@ -152,7 +152,8 @@ async function sendPost() {
let socialPostId = parts[parts.length - 1]
formData.append("file", selectedFile.value)
formData.append("messageId", socialPostId)
await socialPostService.addPostAttachment(formData)
await socialService.addAttachment(formData)
}
postState.content = ""

@ -3,6 +3,10 @@ import baseService from "./baseService"
const API_URL = "/social-network"
async function createPost(params) {
return baseService.post("/api/social_posts", params)
}
/**
* @param {string} postIri
* @returns {Promise<Object>}
@ -19,6 +23,14 @@ async function sendPostDislike(postIri) {
return baseService.post(`${postIri}/dislike`)
}
/**
* @param {FormData} formData
* @returns {Promise<Object>}
*/
async function addAttachment(formData) {
return await baseService.postForm("/api/social_post_attachments", formData)
}
export default {
async fetchPersonalData(userId) {
try {
@ -168,9 +180,13 @@ export default {
}
},
createPost,
sendPostLike,
sendPostDislike,
addAttachment,
delete: baseService.delete,
}

@ -1,13 +1,3 @@
import makeService from './api';
import axios from "axios"
import makeService from "./api"
export default makeService('social_posts', {
async addPostAttachment(formData) {
const endpoint = "/api/social_post_attachments"
return await axios.post(endpoint, formData, {
headers: {
"Content-Type": "multipart/form-data",
},
})
}
});
export default makeService("social_posts")

Loading…
Cancel
Save