2023-05-12 14:54:58 +00:00
|
|
|
/**
|
|
|
|
* ==============================================================================
|
|
|
|
* Imports
|
|
|
|
* ==============================================================================
|
|
|
|
*/
|
|
|
|
const https = require("https");
|
|
|
|
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
|
2023-05-18 11:43:52 +00:00
|
|
|
/**
|
2023-05-18 11:51:11 +00:00
|
|
|
* @typedef {object} FunctionReturn
|
2023-05-18 11:43:52 +00:00
|
|
|
* @property {boolean} success - Did the function run successfully?
|
|
|
|
* @property {(Object[]|string)} [payload=[]] - Payload
|
|
|
|
*/
|
|
|
|
|
2023-05-12 14:54:58 +00:00
|
|
|
/**
|
|
|
|
* ==============================================================================
|
|
|
|
* Main Function
|
|
|
|
* ==============================================================================
|
2023-05-18 11:43:52 +00:00
|
|
|
* @async
|
|
|
|
*
|
|
|
|
* @param {object} params - API Key
|
|
|
|
* @param {String} params.key - API Key
|
|
|
|
* @param {String} params.database - Target Database
|
2023-05-23 13:01:49 +00:00
|
|
|
* @param {{ id: number }} params.payload - User Object
|
2023-05-18 11:43:52 +00:00
|
|
|
*
|
2023-05-22 07:51:33 +00:00
|
|
|
* @returns { Promise<FunctionReturn>}
|
2023-05-12 14:54:58 +00:00
|
|
|
*/
|
|
|
|
module.exports = async function ({ key, payload, database }) {
|
|
|
|
/**
|
|
|
|
* Make https request
|
|
|
|
*
|
|
|
|
* @description make a request to datasquirel.com
|
|
|
|
*/
|
|
|
|
const httpResponse = await new Promise((resolve, reject) => {
|
|
|
|
const reqPayload = JSON.stringify({
|
|
|
|
payload,
|
|
|
|
database,
|
|
|
|
});
|
|
|
|
|
|
|
|
const httpsRequest = https.request(
|
|
|
|
{
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
2023-05-22 10:52:27 +00:00
|
|
|
"Content-Length": Buffer.from(reqPayload).length,
|
2023-05-12 14:54:58 +00:00
|
|
|
Authorization: key,
|
|
|
|
},
|
|
|
|
port: 443,
|
|
|
|
hostname: "datasquirel.com",
|
|
|
|
path: `/api/user/update-user`,
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback Function
|
|
|
|
*
|
|
|
|
* @description https request callback
|
|
|
|
*/
|
|
|
|
(response) => {
|
|
|
|
var str = "";
|
|
|
|
|
|
|
|
response.on("data", function (chunk) {
|
|
|
|
str += chunk;
|
|
|
|
});
|
|
|
|
|
|
|
|
response.on("end", function () {
|
|
|
|
resolve(JSON.parse(str));
|
|
|
|
});
|
|
|
|
|
|
|
|
response.on("error", (err) => {
|
|
|
|
reject(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
httpsRequest.write(reqPayload);
|
|
|
|
httpsRequest.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
/** ********************************************** */
|
|
|
|
/** ********************************************** */
|
|
|
|
/** ********************************************** */
|
|
|
|
|
|
|
|
return httpResponse;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** ********************************************** */
|
|
|
|
/** ********************************************** */
|
|
|
|
/** ********************************************** */
|