Clyde/frontend/src/rest/msg.js

52 lines
1.2 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
export async function sendMessage(id, content, responseId){
let data = {
content: content,
response: responseId,
}
restPost("/discussion/" + id, data);
}
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();