gb_utils
Version:
All utils file for beta
142 lines (125 loc) • 3.8 kB
JavaScript
const langJson = require("gb_json/en.json");
const responseUtils = {};
//Utils Import
const helperUtils = require("./helperUtils");
const constantUtils = require("./constantUtils");
const configPayload = {
SECRECTENCRYPECODE: constantUtils.SECRECTENCRYPECODE,
}
responseUtils.successResponse = async function (res, msg, data) {
const responseJson = {
customcode: 200,
message: msg,
status: langJson.SUCCESS,
data: data,
config: configPayload,
};
const encrypeData = await helperUtils.dataEncryption(responseJson);
return res.status(200).json(encrypeData);
};
responseUtils.successListResponse = async function (res, skip, limit, msg, total, data) {
const responseJson = {
customcode: 200,
message: msg,
status: langJson.SUCCESS,
skip: skip,
limit: limit,
total: total,
data: data,
config: configPayload,
};
const encrypeData = await helperUtils.dataEncryption(responseJson);
return res.status(200).json(encrypeData);
};
responseUtils.unauthorizedResponse = async function (res) {
const responseJson = {
customcode: 201,
message: langJson.UNAUTHORIZEDERROR,
status: langJson.FAIL,
config: configPayload,
};
const encrypeData = await helperUtils.dataEncryption(responseJson);
return res.status(401).json(encrypeData);
};
responseUtils.serverErrorResponse = async function (res) {
const responseJson = {
customcode: 500,
message: langJson.SOMETHINGWENTWRONG,
status: langJson.FAIL,
config: configPayload,
};
const encrypeData = await helperUtils.dataEncryption(responseJson);
return res.status(500).json(encrypeData);
};
responseUtils.requestError = async function (res, code, msg) {
const responseJson = {
customcode: code,
message: msg,
status: langJson.FAIL,
config: configPayload,
};
const encrypeData = await helperUtils.dataEncryption(responseJson);
return res.status(400).json(encrypeData);
};
responseUtils.validationError = async function (res, msg) {
const responseJson = {
customcode: 205,
message: msg,
status: langJson.FAIL,
config: configPayload,
};
const encrypeData = await helperUtils.dataEncryption(responseJson);
return res.status(422).json(encrypeData);
};
responseUtils.userExistResponse = async function (res) {
const responseJson = {
customcode: 201,
message: langJson.USERDOESNOTEXIST,
status: langJson.FAIL,
config: configPayload,
};
const encrypeData = await helperUtils.dataEncryption(responseJson);
return res.status(201).json(encrypeData);
};
responseUtils.dataNotAvailResponse = async function (res) {
const responseJson = {
customcode: 210,
message: langJson.NODATAAVAILABLE,
status: langJson.FAIL,
config: configPayload,
};
const encrypeData = await helperUtils.dataEncryption(responseJson);
return res.status(210).json(encrypeData);
};
responseUtils.duplicationDataResponse = async function (res) {
const responseJson = {
customcode: 211,
message: langJson.DATAALREADYEXISTS,
status: langJson.FAIL,
config: configPayload,
};
const encrypeData = await helperUtils.dataEncryption(responseJson);
return res.status(210).json(encrypeData);
};
// responseUtils.InvalidUsernameResponse = function (res) {
// const responseJson = {
// customcode: 202,
// message: langJson.INVALIDUSERNAMEANDPASSWORD,
// }
// return res.status(202).json(responseJson)
// }
// responseUtils.inactiveAccountResponse = function (res) {
// const responseJson = {
// customcode: 203,
// message: langJson.YOURACCOUNTISNOTACTIVE,
// }
// return res.status(203).json(responseJson)
// }
// responseUtils.profileResponse = function (res) {
// const responseJson = {
// customcode: 203,
// message: langJson.YOURACCOUNTISNOTACTIVE,
// }
// return res.status(203).json(responseJson)
// }
module.exports = responseUtils;