services/category

Service to create, update, and retrieve training category information.

Methods

(static) create(categoryToAdd) → {Promise.<(CategoryDTO|null)>}

Create category with the provided data.
Source:
Parameters:
Name Type Description
categoryToAdd * The category data to be added.
Throws:
- If the operation fails or encounters an error.
Type
Error
Returns:
Type:
Promise.<(CategoryDTO|null)>
A promise that resolves to a new CategoryDTO instance representing the created category, or null if creation fails.

(static) delete(id) → {Promise.<boolean>}

Delete category with the provided ID.
Source:
Parameters:
Name Type Description
id * The ID of the training to delete.
Throws:
- If the operation fails or encounters an error.
Type
Error
Returns:
Type:
Promise.<boolean>
- A promise that resolves to true if the category was successfully deleted, otherwise false.

(static) getAll(offset, limit) → {Promise.<{categories: Array.<CategoryDTO>, count: number}>}

Retrieve a list of paginated category.
Source:
Parameters:
Name Type Description
offset number The number of items to skip before starting to return results.
limit number The maximum number of items to return.
Throws:
- If the operation fails or encounters an error.
Type
Error
Returns:
Type:
Promise.<{categories: Array.<CategoryDTO>, count: number}>
A promise that resolves to an object containing an array of CategoryDTO instances representing the retrieved categories and the total count of categories.

(static) getById(id) → {Promise.<(CategoryTO|null)>}

Retrieve category details with the provided ID.
Source:
Parameters:
Name Type Description
id * The ID of the category to retrieve.
Throws:
- If the operation fails or encounters an error.
Type
Error
Returns:
Type:
Promise.<(CategoryTO|null)>
A promise that resolves to a CategoryDTO instance representing the retrieved category, or null if the course is not found.

(static) nameAlreadyExists(name) → {Promise.<boolean>}

Checks if a category with the provided name already exists.
Source:
Parameters:
Name Type Description
name * The name of the category to check for existence.
Throws:
- If the operation fails or encounters an error.
Type
Error
Returns:
Type:
Promise.<boolean>
- A promise that resolves to true if a category with the provided name already exists, or false otherwise.

(static) search(terms) → {Promise.<Array.<CategoryDTO>>}

Search for categories based on the provided search terms.
Source:
Parameters:
Name Type Description
terms * The search terms to match against category name.
Throws:
- If the operation fails or encounters an error.
Type
Error
Returns:
Type:
Promise.<Array.<CategoryDTO>>
A promise that resolves to an array of CategoryDTO objects matching the search terms.

(static) updateCover(id, filename) → {Promise.<boolean>}

Updates the cover image for a category with the provided ID.
Source:
Parameters:
Name Type Description
id string The ID of the category to update the cover image for.
filename string The filename of the new cover image.
Throws:
- If the operation fails or encounters an error.
Type
Error
Returns:
Type:
Promise.<boolean>
- A promise that resolves to true if the cover image update was successful, or false otherwise.