diff --git a/index.js b/index.js index 5cadc9e..7c02760 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ const get = require("./utils/get"); const post = require("./utils/post"); const uploadImage = require("./utils/upload-image"); const createUser = require("./users/add-user"); +const updateUser = require("./users/update-user"); const loginUser = require("./users/login-user"); const logoutUser = require("./users/logout-user"); const userAuth = require("./users/user-auth"); @@ -35,6 +36,7 @@ const datasquirel = { loginUser: loginUser, logoutUser: logoutUser, userAuth: userAuth, + updateUser: updateUser, }, }; diff --git a/package.json b/package.json index 817ebbb..21bed05 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datasquirel", - "version": "1.1.2", + "version": "1.1.3", "description": "Cloud-based SQL data management tool", "main": "index.js", "scripts": { diff --git a/users/add-user.js b/users/add-user.js index d8921a4..c6f9567 100644 --- a/users/add-user.js +++ b/users/add-user.js @@ -19,13 +19,11 @@ const https = require("https"); * @param {String} key - API Key * @param {String} database - Target Database * @param {String | Object} payload - SQL query String or Request Object. Eg. { - action: "insert | update | delete", - data: { - user_id: user.id, - user_first_name: user.first_name, - user_last_name: user.last_name, - }, - table: "posts", + first_name: "Benjamin", + last_name:"Toby", + email:"benoti.san@gmail.com", + username:"tben", + password:"12345678", } */ module.exports = async function ({ key, payload, database }) { diff --git a/users/update-user.js b/users/update-user.js new file mode 100644 index 0000000..2ecc1c1 --- /dev/null +++ b/users/update-user.js @@ -0,0 +1,88 @@ +/** + * ============================================================================== + * Imports + * ============================================================================== + */ +const https = require("https"); + +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ +/** ****************************************************************************** */ + +/** + * ============================================================================== + * Main Function + * ============================================================================== + * @param {String} key - API Key + * @param {String} database - Target Database + * @param {String | Object} payload - SQL query String or Request Object. Eg. { + first_name: "Benjamin", + last_name:"Toby", + email:"benoti.san@gmail.com", + username:"tben", + password:"12345678", + } + */ +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", + "Content-Length": reqPayload.length, + 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; +}; + +/** ********************************************** */ +/** ********************************************** */ +/** ********************************************** */ diff --git a/utils/upload-image.js b/utils/upload-image.js index da25ec0..1146a8a 100644 --- a/utils/upload-image.js +++ b/utils/upload-image.js @@ -43,7 +43,7 @@ module.exports = async function ({ key, payload }) { }, port: 443, hostname: "datasquirel.com", - path: `/api/query/post`, + path: `/api/query/add-image`, }, /**