Skip to content

Commit

Permalink
Merge pull request #29 from montasim/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
montasim authored Sep 8, 2024
2 parents 07974bc + bbb4f4d commit 433d831
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [1.3.1](https://github.com/montasim/node-express-boilerplate/compare/v1.3.0...v1.3.1) (2024-08-17)

### Code Refactoring

- sync with remote ([dfa9b76](https://github.com/montasim/node-express-boilerplate/commit/dfa9b7683f99cbfc9cbec78a2990f488fc05acb9))

## [1.3.0](https://github.com/montasim/node-express-boilerplate/compare/v1.2.0...v1.3.0) (2024-08-17)

### Features
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-express-boilerplate",
"version": "1.3.0",
"version": "1.3.1",
"description": "",
"private": true,
"main": "server.js",
Expand Down
9 changes: 6 additions & 3 deletions src/shared/validateWithSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import asyncErrorHandlerService from '../service/asyncErrorHandler.service.js';
import customValidationMessage from './customValidationMessage.js';
import httpStatus from '../constant/httpStatus.constants.js';
import loggerService from '../service/logger.service.js';

/**
* @function validateWithSchema
Expand All @@ -36,14 +37,16 @@ const validateWithSchema = (schemas, options = {}) => {
);

if (error) {
const message = error.details
.map((detail) => detail.message)
.join(', ');
loggerService.debug(message);
const errorData = {
route: req.originalUrl,
timeStamp: new Date(),
success: false,
data: {},
message: error.details
.map((detail) => detail.message)
.join(', '),
message,
status: httpStatus.BAD_REQUEST,
};

Expand Down
20 changes: 13 additions & 7 deletions src/utilities/errorResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import httpStatus from '../constant/httpStatus.constants.js';
import loggerService from '../service/logger.service.js';

/**
* errorResponse - A function that generates a standardized error response object.
Expand All @@ -20,12 +21,17 @@ import httpStatus from '../constant/httpStatus.constants.js';
* @returns {Object} - An object representing the error response, including the timestamp,
* success flag, data payload, error message, and status code.
*/
const errorResponse = (message, status = httpStatus.BAD_REQUEST) => ({
timeStamp: new Date(),
success: false,
data: {},
message,
status,
});
const errorResponse = (message, status = httpStatus.BAD_REQUEST) => {
toString(status).startsWith('5')
? loggerService.error(message)
: loggerService.debug(message);
return {
timeStamp: new Date(),
success: false,
data: {},
message,
status,
};
};

export default errorResponse;
20 changes: 13 additions & 7 deletions src/utilities/sendResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import httpStatus from '../constant/httpStatus.constants.js';
import loggerService from '../service/logger.service.js';

/**
* sendResponse - A function that creates a standardized response object for successful
Expand All @@ -21,12 +22,17 @@ import httpStatus from '../constant/httpStatus.constants.js';
* @returns {Object} - An object representing the response, including the timestamp,
* success flag, data payload, message, and status code.
*/
const sendResponse = (data, message, status = httpStatus.OK) => ({
timeStamp: new Date(),
success: true,
data,
message,
status,
});
const sendResponse = (data, message, status = httpStatus.OK) => {
toString(status).startsWith('5')
? loggerService.error(message)
: loggerService.debug(message);
return {
timeStamp: new Date(),
success: true,
data,
message,
status,
};
};

export default sendResponse;

0 comments on commit 433d831

Please sign in to comment.