-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into helper-error-translate
- Loading branch information
Showing
15 changed files
with
365 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,59 @@ | ||
import {Assistant} from '@/types/Assistant.ts'; | ||
import { Response } from '@/types/Response'; | ||
import {ref} from 'vue'; | ||
import {endpoints} from '@/config/endpoints.ts'; | ||
import { get, getList } from '@/composables/services/helpers.ts'; | ||
import { get, getList, create, delete_id } from '@/composables/services/helpers.ts'; | ||
import { useToast } from 'primevue/usetoast'; | ||
import {ComposerTranslation} from "vue-i18n"; | ||
|
||
export function useAssistant() { | ||
const assistants = ref<Assistant[]|null>(null); | ||
const assistant = ref<Assistant|null>(null); | ||
const response = ref<Response|null>(null); | ||
const toast = useToast(); | ||
|
||
async function getAssistantByID(id: number, t: ComposerTranslation) { | ||
const endpoint = endpoints.assistants.retrieve.replace('{id}', id.toString()); | ||
async function getAssistantByID(id: string, t: ComposerTranslation) { | ||
const endpoint = endpoints.assistants.retrieve.replace('{id}', id); | ||
get<Assistant>(endpoint, assistant, Assistant.fromJSON, toast, t); | ||
} | ||
|
||
async function getAssistantByCourse(course_id: string, t: ComposerTranslation) { | ||
const endpoint = endpoints.assistants.byCourse.replace('{course_id}', course_id); | ||
get<Assistant>(endpoint, assistant, Assistant.fromJSON, toast, t); | ||
console.log(assistant) | ||
} | ||
|
||
async function getAssistants(t: ComposerTranslation) { | ||
const endpoint = endpoints.assistants.index; | ||
getList<Assistant>(endpoint, assistants, Assistant.fromJSON, toast, t); | ||
console.log(assistants.value ? assistants.value.map((assistant, index) => `Assistant ${index + 1}: ${JSON.stringify(assistant)}`) : 'assistants is null'); | ||
} | ||
|
||
async function assistantJoinCourse(course_id: string, assistant_id: string, t: ComposerTranslation) { | ||
const endpoint = endpoints.assistants.byCourse.replace('{course_id}', course_id); | ||
create<Response>(endpoint, {assistant_id: assistant_id}, response, Response.fromJSON, toast, t); | ||
} | ||
|
||
async function createAssistant(assistant_data: any, t: ComposerTranslation) { | ||
const endpoint = endpoints.assistants.index; | ||
create<Assistant>(endpoint, assistant_data, assistant, Assistant.fromJSON, toast, t); | ||
} | ||
|
||
async function deleteAssistant(id: string, t: ComposerTranslation) { | ||
const endpoint = endpoints.admins.retrieve.replace('{id}', id); | ||
delete_id<Assistant>(endpoint, assistant, Assistant.fromJSON, toast, t); | ||
} | ||
|
||
return { | ||
assistants, | ||
assistant, | ||
response, | ||
|
||
getAssistantByID, | ||
getAssistants | ||
getAssistantByCourse, | ||
getAssistants, | ||
|
||
createAssistant, | ||
deleteAssistant, | ||
|
||
assistantJoinCourse | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.