1
0
forked from PGL/Clyde
Clyde/frontend/src/rest/msg.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-03-22 13:54:52 +01:00
/*******************************************************
* File: msg.js
* Author: Anthony Debucquoy
* Scope: Extension messagerie
* Description: Messages frontend api consumer
*******************************************************/
2024-03-27 19:52:48 +01:00
import { restGet, restPost, restPatch } from './restConsumer.js'
import { ref } from 'vue'
/**
* - id
* - name
* - members
*/
2024-03-27 23:54:59 +01:00
export const discussionsList = ref();
export const currentDiscussion = ref([]);
2024-03-22 13:54:52 +01:00
export async function createDiscussion(name){
2024-03-27 19:52:48 +01:00
let disc = await restPost("/discussion", {name: name});
discussionsList.value.push(disc);
}
export async function invite(id, regNo){
2024-03-27 23:54:59 +01:00
restPatch("/discussion/"+ id+ "/add", {regNo: parseInt(regNo)}).then(() => fetchDiscussion(id))
}
2024-03-27 19:52:48 +01:00
2024-03-29 14:30:46 +01:00
export async function removeMember(id, regNo){
restPatch("/discussion/"+ id+ "/remove", {regNo: parseInt(regNo)}).then(() => fetchDiscussion(id))
}
2024-03-27 19:52:48 +01:00
export async function sendMessage(id, content, responseId){
let data = {
content: content,
response: responseId,
}
2024-03-29 14:31:08 +01:00
restPost("/discussion/" + id, data).then(() => fetchDiscussion(id));
2024-03-27 19:52:48 +01:00
}
export async function updateDiscussionName(id, name){
restPatch("/discussion/" + id, {name: name}).then(() => fetchDiscussions());
}
async function fetchDiscussions(){
discussionsList.value = await restGet("/discussions");
}
export async function fetchDiscussion(id){
currentDiscussion.value = await restGet("/discussion/" + id);
}
await fetchDiscussions();