import { FileLockBody, FileLockData } from '../../interfaces/files.interface' import { Api, ApiResponse } from '../api' import { ENDPOINTS } from '.' const ELEMENTS_API = '/service/elements/api' type Base64Image = string export type FileAction = 'archived' | 'relevant' | 'public' export class Files { api: Api constructor(api: Api) { this.api = api } async exportXls(postData: ReportData | ReportData[]) { const responseType = 'arraybuffer' return this.api.apisauce.post( `${ELEMENTS_API}/create-file/report`, postData, { responseType, }, ) } fileAction( { type, hash }: { hash: string; type: string }, attribute: string, fileHash: string, organization: string, method: 'post' | 'delete', action: FileAction, ) { return this.api.apisauce[method]( `${ENDPOINTS.MEMBRANE}/files/elements/${type}/${hash}/${attribute}/${fileHash}/${organization}/${action}`, ) } fileLock( elementHash: string, attribute: string, fileHash: string, method: 'post', body: FileLockBody, ): Promise> fileLock( elementHash: string, attribute: string, fileHash: string, method: 'delete' | 'get', ): Promise> fileLock( elementHash: string, attribute: string, fileHash: string, method: 'post' | 'delete' | 'get', body?: FileLockBody, ) { return this.api.apisauce.any({ method, url: `${ENDPOINTS.MEMBRANE}/files/${elementHash}/${attribute}/${fileHash}/lock`, data: body, }) } async signPdf(postData: SignPdfParams) { const data: Record = { file: postData.signatureData, elementHash: postData.elementHash, elementType: postData.elementType, organization: postData.organization, attributeName: postData.resultAttribute, } if (postData.sourcePdfUrl) { data.pdfurl = postData.sourcePdfUrl } if (postData.fillFormData) { data.fillFormData = JSON.stringify(postData.fillFormData) } return this.api.apisauce.post( `${ENDPOINTS.MEMBRANE}/file-creator/pdf-fill-template-formdata`, data, { headers: { 'Content-Type': 'multipart/form-data', }, }, ) } } interface SignPdfParams { signatureData: Base64Image elementHash: string elementType: string organization: string resultAttribute: string sourcePdfUrl?: string fillFormData?: Record // JSON Record } interface ReportData { filename: string data: (string | number)[][] mergedCells: string[][] sheetName?: string styles: { columns?: Record[] rows?: Record[] } }