Skip to content

SudoSOS Back-end API / internal/files / FileService

Class: FileService ​

Constructors ​

Constructor ​

ts
new FileService(workdir?, storageMethod?): FileService;

Parameters ​

ParameterType
workdir?string
storageMethod?"disk"

Returns ​

FileService

Methods ​

createFile() ​

ts
createFile(file, fileData): Promise<BaseFile>;

Create a new file in storage, given the provided parameters

Parameters ​

ParameterType
fileBaseFile
fileDataBuffer

Returns ​

Promise<BaseFile>


deleteEntityFile() ​

ts
deleteEntityFile(entityFile): Promise<void>;

Delete entity file from database

Parameters ​

ParameterType
entityFile| ProductImage | BannerImage

Returns ​

Promise<void>


deleteSimpleFile() ​

ts
deleteSimpleFile(id): Promise<void>;

Delete the simple file with given ID from storage and database

Parameters ​

ParameterType
idnumber

Returns ​

Promise<void>


getSimpleFile() ​

ts
getSimpleFile(id): Promise<DownloadFileResponse>;

Get the given simple file object and data from storage

Parameters ​

ParameterType
idnumber

Returns ​

Promise<DownloadFileResponse>


uploadEntityImage() ​

ts
uploadEntityImage(
   entity, 
   uploadedFile, 
createdBy): Promise<ProductImage>;

Upload an entity image to the given entity and replace the old one, if it exists

Parameters ​

ParameterType
entity| Product | Banner
uploadedFileUploadedFile
createdByUser

Returns ​

Promise<ProductImage>


uploadPdf() ​

ts
uploadPdf<T, S>(
   entity, 
   PdfType, 
   fileData, 
createdBy): Promise<S>;

Upload a pdf file

Type Parameters ​

Type Parameter
T extends IPdfAble<S>
S extends Pdf

Parameters ​

ParameterTypeDescription
entityTThe entity that has the pdf property
PdfType() => SThe pdf type, must be manually specified since the entities pdf can be undefined
fileDataBufferThe file data
createdByUserThe user that created the file

Returns ​

Promise<S>


uploadSimpleFile() ​

ts
uploadSimpleFile(
   createdBy, 
   uploadedFile, 
fileEntity): Promise<BaseFile>;

Upload a simple file to the database and put in storage

Parameters ​

ParameterType
createdByUser
uploadedFileUploadedFile
fileEntitySimpleFileRequest

Returns ​

Promise<BaseFile>