/* * Copyright (c) 2022. * Author Peter Placzek (tada5hi) * For the full copyright and license information, * view the LICENSE file that was distributed with this source code. */ import {CollectionResponseType, ResourceResponseType} from "@/modules/api/type"; import {AuthUser} from "@chamesu/common/domains/auth/user"; import {AuthUserImageType} from "@chamesu/common/domains/auth/user/type"; import {useApi} from "~/modules/api"; import {formatRequestRecord, RequestRecord} from "~/modules/api/utils"; export async function getUsers>(options?: RequestRecord) : Promise { const { data: response } = await useApi('auth').get('auth/users' + formatRequestRecord(options)); return response; } export async function getUser>(id: number) : Promise { const { data: response } = await useApi('auth').get('auth/users/'+id); return response; } export async function dropUser>(id: number) : Promise { const { data: response } = await useApi('auth').delete('auth/users/'+id); return response; } export async function addUser>(data: {[key: string] : any}) : Promise { const { data: response } = await useApi('auth').post('auth/users',data); return response; } export async function editUser>(userId: number, data: {[key: string] : any}) : Promise { const { data: response } = await useApi('auth').post('auth/users/'+userId, data); return response; } export async function editUserImage>( userId: number, type: AuthUserImageType, image: string | Blob, data: { coordinates: Record, visibleArea: Record } ) : Promise { const formData = new FormData(); formData.append(type, image); for(let key in data) { for(let keySecond in data[key]) { if(!data[key].hasOwnProperty(keySecond)) continue; formData.append(key+keySecond.charAt(0).toUpperCase() + keySecond.substr(1), data[key][keySecond]); } } const { data: response } = await useApi('auth').post('auth/users/'+userId, formData, { headers: { 'Content-Type': 'multipart/form-data' } }); return response; }