dsql-admin/dsql-app/.local_dist/server/chunks/766.js
2024-11-05 12:12:42 +01:00

55 lines
2.4 KiB
JavaScript

"use strict";
exports.id = 766;
exports.ids = [766];
exports.modules = {
/***/ 766:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
// @ts-check
const DSQL_USER_DB_HANDLER = __webpack_require__(3403);
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* Handle Table Entries Order
* =================================================================
* @param {object} param0
* @param {string} param0.dbName
* @param {string} param0.tableName
* @param {number} param0.entryId
* @param {string} param0.entryOrder
* @param {import("@/package-shared/types").DSQL_TableSchemaType} param0.tableSchema
*/ module.exports = async function handleTableEntryOrder({ dbName , entryId , entryOrder , tableName , tableSchema , }) {
try {
const isOrderField = Boolean(tableSchema.fields.find((fld)=>Boolean(fld.fieldName?.match(/^order$/i))));
if (isOrderField && entryOrder) {
const existingOrder = await DSQL_USER_DB_HANDLER({
database: dbName,
paradigm: "Full Access",
queryString: `SELECT * FROM ${tableName} WHERE \`order\` = '${entryOrder}' AND id != ?`,
queryValues: [
String(entryId)
]
});
if (!existingOrder?.[0]) throw new Error("No Existing Order");
await DSQL_USER_DB_HANDLER({
database: dbName,
paradigm: "Full Access",
queryString: `UPDATE ${tableName} SET \`order\` = \`order\` + 1 WHERE \`order\` >= ${entryOrder} AND id != ?`,
queryValues: [
String(entryId)
]
});
}
return true;
} catch (/** @type {any} */ error) {
return false;
}
}; ////////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
/***/ })
};
;