New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

estol-blog

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

estol-blog - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

package.json
{
"name": "estol-blog",
"version": "1.0.0",
"version": "1.0.1",
"description": "Blog's post management dependency",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -57,18 +57,96 @@ # estol-blog

Configures the estol-blog dependency with the provided configuration.
Configures the `estol-blog` dependency with the provided configuration.
config: An object containing the configuration options. It should have a databaseURL and optionally a model for the blog posts.
- `config`: An object containing the configuration options. It should have either a `databaseURL` or a `model`, but not both.
### `blogController`
- `databaseURL`: The URL of the database to connect to. If provided, the dependency will use its own default model for blog posts.
- `model`: The Mongoose model instance from the user's project. If provided, the dependency will use the user's Mongoose model for blog posts.
**Note**: The user must provide either `databaseURL` or `model`, not both. If `databaseURL` is provided, the dependency connects to the database using its default model. If `model` is provided, the dependency uses the user's Mongoose model. It's mandatory to provide one of the two options; providing both is not allowed.
**Important**: If the user decides to provide a model, it is important that this model has at least the same fields in the default model(author, title, content y views) to avoid dependency's malfunctions.
### Default Model
If the user chooses to use the default model provided by the `estol-blog` dependency, the model looks like this:
```javascript
// post.model.js
import { Schema, model } from "mongoose";
const { ObjectId } = Schema.Types;
const postSchema = new Schema(
{
author: { type: ObjectId, ref: "User", required: true },
title: { type: String, required: true },
content: { type: String, required: true },
views: { type: Number, default: 0 },
},
{
timestamps: true,
}
);
const Post = model("Post", postSchema);
export default Post;
```
**Important**: If you opt to use the default model, it's crucial to ensure that your project includes a Mongoose model for "User" to prevent errors. The "author" field in the default blog post model references the "User" model. If the "User" model is not defined in your project, it may lead to reference errors. Please make sure that the "User" model is available in your project to maintain the integrity of the default blog post model.
## `blogController`
A set of functions for managing blog-related operations.
`getPosts(options)`
### `getPosts(options)`
Retrieve blog posts based on specified options.
`options`: An object containing various options for retrieving posts.
`postManagement(options)`
#### Options
The `options` object can include several properties:
- `searchType`: Should be a string referring to the type of search to be performed. The available options are:
- `"All"`: Retrieve all the posts stored in the blog.
- `"Last"`: Retrieve posts in chronological order from the newest to the oldest.
- `"Trending"`: Retrieve posts ordered by views, from most viewed to least viewed.
- `"One"`: Retrieve a specific post by providing a `postID`.
- `"Search"`: Search for posts by providing a search string (`searchStr`).
- `fieldsToPopulate`: Should be an array of strings containing the names of all the fields of the model to be populated.
- `useLean`: An optional boolean property. By default, this field is set to `true` unless the dependency user needs to receive the complete model instance. In that case, the user should set this property as `useLean: false`, and the dependency will return a complete model instance instead of a plain JavaScript object.
- `flag`: An optional string property representing a date to facilitate pagination. When requesting the first page (e.g., using `"searchType: 'Last'"`), this property is not necessary to include. The dependency will include the flag for the next page in the returned object after the first page. The user only needs to include this flag in the next request.
- `quantity`: An optional property determining the extent of each page. If not provided, by default, each call will return a maximum of 10 posts.
- `id`: A mandatory property only in the case of requesting a specific post. This property is used by the dependency to perform a search in the database.
- `searchStr`: A mandatory property only in the case of wanting to perform a search for posts using a search string. In this case, the dependency will search for all occurrences of that search string in the title and content of all blogs in the database.
**Note**: Ensure consistency in the naming convention of properties, using `camelCase` throughout the `options` object.
### `postManagement(options)`
Perform blog post management actions like creating, updating, or deleting posts.
`options`: An object containing parameters for the desired action.
#### Options
The `options` object can include several properties:
- `action`: A mandatory string property that can have a value of `"create"`, `"update"`, or `"delete"`, depending on the action to be carried out.
- `fieldsToPopulate`: Should be an array of strings containing the names of all the fields of the model to be populated.
- `newPost`: A mandatory property when the `action` property is set to `"create"`. The `newPost` property will be an object containing all the information for the new post (author, title, and content in case the dependency's default model is used).
- `updateData`: A mandatory property in case the `action` property is set to `"update"`. The `updateData` property will be an object containing the information to be updated in the post. In this case, it is not necessary to provide all the properties, only those to be updated.
- `id`: A mandatory property in case the `action` property is set to `"update"` or `"delete"`. This property is used by the dependency to identify the post in the database that needs to be updated or deleted.
- `useLean`: An optional boolean property. By default, this field is set to `true` unless the dependency user needs to receive the complete model instance. In that case, the user should set this property as `useLean: false`, and the dependency will return a complete model instance instead of a plain JavaScript object.
**Note**: Ensure consistency in the naming convention of properties, using `camelCase` throughout the `options` object.
## Licence

@@ -75,0 +153,0 @@ This project is licensed under the MIT License - see the LICENSE.md file for details.

@@ -15,3 +15,3 @@ // blog.controller.js

export const getPosts = async ({ searchType = "Last", model, fieldsToPopulate, useLean, flag, quantity, id, searchStr }) => {
export const getPosts = async ({ searchType = "Last", fieldsToPopulate, useLean, flag, quantity, id: postID, searchStr }) => {
try {

@@ -24,3 +24,3 @@ const type = capitalizeFirstLetter(searchType);

const { success, posts, post, code, message, newFlag } = await blogService[`get${type}Posts`]({ model, fieldsToPopulate, useLean, originalQuantity: quantity, flag, id, searchStr });
const { success, posts, post, code, message, newFlag } = await blogService[`get${type}Posts`]({ model, fieldsToPopulate, useLean, originalQuantity: quantity, flag, id: postID, searchStr });

@@ -45,3 +45,3 @@ if (success) {

export const postManagement = async ({ action, model, fieldsToPopulate, newPost, updateData, id, useLean }) => {
export const postManagement = async ({ action, fieldsToPopulate, newPost, updateData, id, useLean }) => {
try {

@@ -48,0 +48,0 @@ const formatedAction = action.toLowerCase();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc