Tech4biz-channel/Channel-Frontend/src/services/assets-api.ts

55 lines
1.7 KiB
TypeScript

import { axiosInstance } from './axios';
import type { Asset, Organization } from '../types/assets';
export const getAssets = async (): Promise<Asset[]> => {
const response = await axiosInstance.get<Asset[]>('/assets');
return response.data;
};
export const getOrganizations = async (): Promise<Organization[]> => {
const response = await axiosInstance.get<Organization[]>('/organizations');
return response.data;
};
export const uploadAsset = async (formData: FormData): Promise<void> => {
await axiosInstance.post('/assets/upload', formData, {
headers: { 'Content-Type': 'multipart/form-data' }
});
};
export const updateAsset = async (
id: string,
payload: {
title?: string;
description?: string;
categoryId?: string;
subcategory?: string;
tags?: string[];
githubUrl?: string;
isDownloadable?: boolean;
shares?: Array<{ organizationId: string; userId: string | null }>;
}
): Promise<void> => {
await axiosInstance.patch(`/assets/${id}`, payload);
};
export const deleteAsset = async (id: string): Promise<void> => {
await axiosInstance.delete(`/assets/${id}`);
};
export const requestDownload = async (id: string): Promise<void> => {
await axiosInstance.post(`/assets/${id}/request-download`);
};
export const approveDownloadRequest = async (assetId: string, requestId: string): Promise<void> => {
await axiosInstance.post(`/assets/${assetId}/approve-download/${requestId}`);
};
export const rejectDownloadRequest = async (assetId: string, requestId: string): Promise<void> => {
await axiosInstance.post(`/assets/${assetId}/reject-download/${requestId}`);
};
export const downloadAssetFile = async (id: string): Promise<void> => {
await axiosInstance.post(`/assets/${id}/download`);
};