2023-09-21 14:00:04 +00:00
|
|
|
// @ts-check
|
|
|
|
|
2024-11-06 06:26:23 +00:00
|
|
|
const runQuery = require("../../package-shared/functions/backend/db/runQuery");
|
2023-09-21 14:00:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make a get request to Datasquirel API
|
|
|
|
* ==============================================================================
|
|
|
|
* @async
|
|
|
|
*
|
|
|
|
* @param {Object} params - Single object passed
|
2024-11-06 11:23:58 +00:00
|
|
|
* @param {import("../../package-shared/types").LocalPostQueryObject} params.options
|
|
|
|
* @param {import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined} [params.dbSchema]
|
2023-09-21 14:00:04 +00:00
|
|
|
*
|
2024-11-06 11:23:58 +00:00
|
|
|
* @returns { Promise<import("../../package-shared/types").LocalPostReturn> }
|
2023-09-21 14:00:04 +00:00
|
|
|
*/
|
|
|
|
async function localPost({ options, dbSchema }) {
|
|
|
|
try {
|
|
|
|
/**
|
|
|
|
* Grab Body
|
|
|
|
*/
|
|
|
|
const { query, tableName, queryValues } = options;
|
|
|
|
const dbFullName = process.env.DSQL_DB_NAME || "";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create new user folder and file
|
|
|
|
*
|
|
|
|
* @description Create new user folder and file
|
|
|
|
*/
|
|
|
|
try {
|
|
|
|
let { result, error } = await runQuery({
|
|
|
|
dbFullName: dbFullName,
|
|
|
|
query: query,
|
|
|
|
dbSchema: dbSchema,
|
|
|
|
queryValuesArray: queryValues,
|
|
|
|
tableName,
|
2024-11-06 06:26:23 +00:00
|
|
|
local: true,
|
2023-09-21 14:00:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (error) throw error;
|
|
|
|
|
|
|
|
return {
|
|
|
|
success: true,
|
|
|
|
payload: result,
|
|
|
|
error: error,
|
|
|
|
};
|
|
|
|
} catch (/** @type {*} */ error) {
|
|
|
|
return {
|
|
|
|
success: false,
|
|
|
|
error: error.message,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} catch (/** @type {*} */ error) {
|
|
|
|
console.log("Error in local post Request =>", error.message);
|
|
|
|
|
|
|
|
return {
|
|
|
|
success: false,
|
|
|
|
msg: "Something went wrong!",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = localPost;
|