Constructor
new BlogModel(id, title, content, userId, created, deleted, updatedBy)
Parameters:
| Name | Type | Description |
|---|---|---|
id |
number | null | Blog post identifier. |
title |
string | Blog post title. |
content |
string | Blog post content. |
userId |
number | ID of the user who authored the post. |
created |
string | Date | Blog post creation timestamp. |
deleted |
number | Soft-delete flag. |
updatedBy |
number | ID of the user who last updated the post. |
- Source:
Classes
Members
SORTABLE_COLUMNS
Columns that may be used to sort blog listings.
- Source:
Methods
(static) create(blog) → {Promise.<OkPacket>}
Create a blog post with a generated identifier.
Parameters:
| Name | Type | Description |
|---|---|---|
blog |
BlogModel | Blog post to create. |
- Source:
Returns:
Database result.
- Type
- Promise.<OkPacket>
(static) createWithExistingID(blog) → {Promise.<OkPacket>}
Create a blog post with a caller-provided identifier.
Parameters:
| Name | Type | Description |
|---|---|---|
blog |
BlogModel | Blog post to create. |
- Source:
Returns:
Database result.
- Type
- Promise.<OkPacket>
(static) delete(id) → {Promise.<OkPacket>}
Delete a blog post by its identifier.
Parameters:
| Name | Type | Description |
|---|---|---|
id |
number | Blog post identifier. |
- Source:
Returns:
Database result.
- Type
- Promise.<OkPacket>
(async, static) getAll() → {Promise.<Array.<BlogModel>>}
Retrieve all blog posts.
- Source:
Returns:
Active blog posts.
- Type
- Promise.<Array.<BlogModel>>
(async, static) getById(id) → {Promise.<BlogModel>}
Retrieve a blog post by its identifier.
Parameters:
| Name | Type | Description |
|---|---|---|
id |
number | Blog post identifier. |
- Source:
Throws:
-
"not found" when no post matches the identifier.
- Type
- string
Returns:
Matching blog post.
- Type
- Promise.<BlogModel>
(async, static) getBySearch(term) → {Promise.<Array.<BlogModel>>}
Search non-deleted blog posts by title or content.
Parameters:
| Name | Type | Description |
|---|---|---|
term |
string | Search term. |
- Source:
Returns:
Matching blog posts.
- Type
- Promise.<Array.<BlogModel>>
(async, static) list(optionsopt) → {Promise.<{blogs: Array.<BlogModel>, total: number}>}
Search and sort blog posts server-side.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Search and sort options. Properties
|
- Source:
Returns:
Matching blog posts and total match count.
- Type
- Promise.<{blogs: Array.<BlogModel>, total: number}>
(static) tableToModel(row) → {BlogModel}
Convert a database row into a BlogModel instance.
Parameters:
| Name | Type | Description |
|---|---|---|
row |
Object | Database row. |
- Source:
Returns:
Mapped blog post.
- Type
- BlogModel
(static) update(blog) → {Promise.<OkPacket>}
Update an existing blog post.
Parameters:
| Name | Type | Description |
|---|---|---|
blog |
BlogModel | Blog post to update. |
- Source:
Returns:
Database result.
- Type
- Promise.<OkPacket>