koel/resources/assets/js/services/invitationService.ts

25 lines
862 B
TypeScript
Raw Normal View History

import type { CompositeToken } from '@/services'
import { authService, http } from '@/services'
2023-08-20 22:35:58 +00:00
import { userStore } from '@/stores'
export const invitationService = {
getUserProspect: async (token: string) => await http.get<User>(`invitations?token=${token}`),
2023-08-20 22:35:58 +00:00
async accept (token: string, name: string, password: string) {
const compositeToken = await http.post<CompositeToken>('invitations/accept', { token, name, password })
authService.setAudioToken(compositeToken['audio-token'])
authService.setApiToken(compositeToken.token)
2023-08-20 22:35:58 +00:00
},
invite: async (emails: string[], isAdmin: boolean) => {
const users = await http.post<User[]>('invitations', { emails, is_admin: isAdmin })
userStore.add(users)
2023-08-20 22:35:58 +00:00
},
revoke: async (user: User) => {
await http.delete(`invitations`, { email: user.email })
userStore.remove(user)
},
2023-08-20 22:35:58 +00:00
}