feat: Add boilerplate for the file module (#6956)

This commit is contained in:
Stevche Radevski authored and GitHub committed 2024-04-05 14:46:02 +02:00
1 parent eb93e8f386
commit 9ccd88d025
36 files changed
+887

No files matched your search

+1
View File
@@ -25,3 +25,4 @@ export * as WorkflowTypes from "./workflow"
export * as ApiKeyTypes from "./api-key"
export * as StoreTypes from "./store"
export * as CurrencyTypes from "./currency"
export * as FileTypes from "./file"
+13
View File
@@ -0,0 +1,13 @@
/**
* The File details.
*/
export interface FileDTO {
/**
* The ID of the File.
*/
id: string
/**
* The URL of the File.
*/
url: string
}
+3
View File
@@ -0,0 +1,3 @@
export * from "./common"
export * from "./mutations"
export * from "./service"
+19
View File
@@ -0,0 +1,19 @@
/**
* The File to be created.
*/
export interface CreateFileDTO {
/**
* The filename of the uploaded file
*/
filename: string
/**
* The mimetype of the uploaded file
*/
mimeType: string
/**
* The file content
*/
content: Blob
}
+85
View File
@@ -0,0 +1,85 @@
import { IModuleService } from "../modules-sdk"
import { FileDTO } from "./common"
import { FindConfig } from "../common"
import { Context } from "../shared-context"
import { CreateFileDTO } from "./mutations"
/**
* The main service interface for the File Module.
*/
export interface IFileModuleService extends IModuleService {
/**
* This method uploads files to the designated file storage system.
*
* @param {CreateFileDTO[]} data - The files to be created.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<FileDTO[]>} The created files.
*
* @example
* const [file] = await fileModuleService.create([{
* filename: "product.png",
* mimeType: "image/png",
* content: "somecontent"
* }])
*/
create(data: CreateFileDTO[], sharedContext?: Context): Promise<FileDTO[]>
/**
* This method uploads a file to the designated file storage system.
*
* @param {CreateFileDTO} data - The file to be created.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<FileDTO>} The created file.
*
* @example
* const file = await fileModuleService.create({
* filename: "product.png",
* mimeType: "image/png",
* content: "somecontent"
* })
*/
create(data: CreateFileDTO, sharedContext?: Context): Promise<FileDTO>
/**
* This method deletes files by their IDs.
*
* @param {string[]} ids - The IDs of the files.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<void>} Resolves when the files are deleted successfully.
*
* @example
* await fileModuleService.delete(["file_123"])
*/
delete(ids: string[], sharedContext?: Context): Promise<void>
/**
* This method deletes a file by its ID.
*
* @param {string} id - The ID of the file.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<void>} Resolves when the file is deleted successfully.
*
* @example
* await fileModuleService.delete("file_123")
*/
delete(id: string, sharedContext?: Context): Promise<void>
/**
* This method retrieves a file with a downloadable URL by its ID.
*
* @param {string} id - The ID of the file.
* @param {FindConfig<FileDTO>} config - The configurations determining how the file is retrieved. Its properties, such as `select` or `relations`, accept the
* attributes or relations associated with a file.
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
* @returns {Promise<FileDTO>} The retrieved file.
*
* @example
* const file = await fileModuleService.retrieve("file_123")
*/
retrieve(
id: string,
config?: FindConfig<FileDTO>,
sharedContext?: Context
): Promise<FileDTO>
}
+1
View File
@@ -35,3 +35,4 @@ export * from "./transaction-base"
export * from "./user"
export * from "./workflow"
export * from "./currency"
export * from "./file"