116 lines
3.6 KiB
TypeScript
116 lines
3.6 KiB
TypeScript
import { apiClient } from './client';
|
|
|
|
export interface CounterpartSearchResultDto {
|
|
id: string;
|
|
name: string;
|
|
email: string;
|
|
phone: string | null;
|
|
owner: { email: string; name: string };
|
|
}
|
|
|
|
export interface CounterpartItemDto {
|
|
id: string;
|
|
requestedByOrganizationId: string | null;
|
|
counterpartOrganizationId: string | null;
|
|
organizationName: string;
|
|
ownerEmail: string;
|
|
phone: string | null;
|
|
status: 'PENDING' | 'ACTIVE' | 'REJECTED' | 'EXPIRED';
|
|
createdAt: string;
|
|
acceptedAt: string | null;
|
|
}
|
|
|
|
export interface OrganizationInvitationHistoryItemDto {
|
|
id: string;
|
|
organizationName: string;
|
|
ownerEmail: string;
|
|
status: 'PENDING' | 'ACTIVE' | 'REJECTED' | 'EXPIRED';
|
|
createdAt: string;
|
|
acceptedAt: string | null;
|
|
}
|
|
|
|
export const organizationApi = {
|
|
search: async (q: string): Promise<{ success: boolean; data: CounterpartSearchResultDto[] }> => {
|
|
const response = await apiClient.get(`/organizations/search?q=${encodeURIComponent(q)}`);
|
|
return response.data;
|
|
},
|
|
|
|
list: async (): Promise<{ success: boolean; data: { items: CounterpartItemDto[] } }> => {
|
|
const response = await apiClient.get('/organizations/links');
|
|
return response.data;
|
|
},
|
|
|
|
listInvitations: async (): Promise<{
|
|
success: boolean;
|
|
data: { items: OrganizationInvitationHistoryItemDto[] };
|
|
}> => {
|
|
const response = await apiClient.get('/organizations/invitations');
|
|
return response.data;
|
|
},
|
|
|
|
createLink: async (
|
|
targetOrganizationId: string,
|
|
): Promise<{ success: boolean; data: { id: string; status: 'PENDING' | 'ACTIVE' | 'REJECTED' } }> => {
|
|
const response = await apiClient.post('/organizations/links', { targetOrganizationId });
|
|
return response.data;
|
|
},
|
|
|
|
respondLink: async (
|
|
linkId: string,
|
|
action: 'ACCEPT' | 'REJECT',
|
|
): Promise<{ success: boolean; data: { id: string; status: 'PENDING' | 'ACTIVE' | 'REJECTED' } }> => {
|
|
const response = await apiClient.patch(`/organizations/links/${linkId}/respond`, { action });
|
|
return response.data;
|
|
},
|
|
|
|
deleteLink: async (linkId: string): Promise<{ success: boolean; data: { id: string }; message: string }> => {
|
|
const response = await apiClient.delete(`/organizations/links/${linkId}`);
|
|
return response.data;
|
|
},
|
|
|
|
invite: async (body: {
|
|
organizationName: string;
|
|
ownerEmail: string;
|
|
phone?: string;
|
|
}): Promise<{ success: boolean; data: { invitationId: string; invitationUrl: string; status: 'PENDING' } }> => {
|
|
const response = await apiClient.post('/organizations/invite', body);
|
|
return response.data;
|
|
},
|
|
|
|
getInvitationLink: async (
|
|
invitationId: string,
|
|
): Promise<{ success: boolean; data: { invitationId: string; invitationUrl: string } }> => {
|
|
const response = await apiClient.post(`/organizations/invitations/${invitationId}/link`);
|
|
return response.data;
|
|
},
|
|
|
|
previewInvite: async (
|
|
token: string,
|
|
): Promise<{
|
|
success: boolean;
|
|
data: {
|
|
ownerEmail: string;
|
|
organizationName: string;
|
|
organizationType: 'CLINIC' | 'LAB';
|
|
inviterOrganizationName: string;
|
|
expiresAt: string;
|
|
status: 'PENDING' | 'ACCEPTED';
|
|
};
|
|
}> => {
|
|
const response = await apiClient.get(
|
|
`/organizations/invitations/preview?token=${encodeURIComponent(token)}`,
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
acceptInvite: async (body: {
|
|
token: string;
|
|
organizationName: string;
|
|
ownerName: string;
|
|
password: string;
|
|
}): Promise<{ success: boolean; message: string; data: { organizationId: string } }> => {
|
|
const response = await apiClient.post('/organizations/invitations/accept', body);
|
|
return response.data;
|
|
},
|
|
};
|