Spaces:
Sleeping
Sleeping
File size: 3,349 Bytes
97f53b4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
// responseUtils.js
/**
* Standard response for successful operations.
* @param {string} message - Success message
* @param {object} [data=null] - Optional data to include in the response
* @returns {object} - Response object
*/
function successResponse(message, data = null) {
return {
status: 200,
connection: 'Connected',
message: message,
data: data,
};
}
/**
* Standard response for failed operations.
* @param {string} message - Error message
* @param {number} [statusCode=400] - HTTP status code
* @param {object} [errors=null] - Optional error details
* @returns {object} - Response object
*/
function failedResponse(message, statusCode = 400, errors = null) {
return {
status: statusCode,
connection: 'Disconnected',
message: message,
errors: errors,
};
}
/**
* Response format for profile data.
* @param {string} message - Success or error message
* @param {number} statusCode - HTTP status code
* @param {object} data - User data
* @returns {object} - Response object
*/
function profileResponse(message, statusCode, data) {
return {
status: statusCode,
connection: 'Connected',
message: message,
userData: {
user_id: data.unique_id,
username: data.username,
email: data.email,
dateOfBirth: data.dateOfBirth,
mobileNumber: data.mobileNumber,
profilePic: data.profilePic
},
};
}
/**
* Response format for login operations.
* @param {boolean} success - Indicates if the operation was successful
* @param {string} message - Success or error message
* @param {object} [data=null] - Optional data to include in the response
* @returns {object} - Response object
*/
function responseLogin(success, message, data = null) {
return {
success: success,
message: message,
data: data,
};
}
/**
* Response format for registration operations.
* @param {boolean} success - Indicates if the operation was successful
* @param {string} message - Success or error message
* @param {object} [data=null] - Optional data to include in the response
* @returns {object} - Response object
*/
function responseRegistration(success, message, data = null) {
return {
success: success,
message: message,
data: data,
};
}
/**
* Response format for adding products.
* @param {boolean} success - Indicates if the operation was successful
* @param {string} message - Success or error message
* @param {object} [errors=null] - Optional error details
* @returns {object} - Response object
*/
function responseAddProduct(success, message, errors = null) {
return {
success: success,
message: message,
errors: errors,
};
}
/**
* Response format for fetching products.
* @param {boolean} success - Indicates if the operation was successful
* @param {object} data - Data to include in the response
* @returns {object} - Response object
*/
function responseFetchProduct(success, data) {
return {
success: success,
data: data,
};
}
module.exports = {
successResponse,
failedResponse,
profileResponse,
responseLogin,
responseRegistration,
responseAddProduct,
responseFetchProduct,
};
|