Update clients fetch function
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import type { BUN_SQLITE_WGUI_CLIENTS } from "@/db/types/db";
|
||||
import type { BUN_SQLITE_WGUI_ALL_TYPEDEFS } from "@/db/types/db";
|
||||
import checkUserAccess from "@/src/functions/backend/auth/check-user-access";
|
||||
import type { AdminCrudAPIParams, TableType } from "@/src/types";
|
||||
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import checkAllowedJoins from "@/src/functions/backend/db/check-allowed-joins";
|
||||
import grabClients from "@/src/functions/backend/db/clients/grab-clients";
|
||||
import type { AdminCrudAPIParams, ApiReqParams, TableType } from "@/src/types";
|
||||
import type { APIResponseObject } from "@moduletrace/bunext/types";
|
||||
import _ from "lodash";
|
||||
|
||||
@@ -11,8 +12,22 @@ export default async function (
|
||||
const { table, user_types, body, id, query, user } = params;
|
||||
|
||||
let final_sql_query = _.merge(query?.sql_query, body?.sql_query) || {};
|
||||
let final_query =
|
||||
_.merge<
|
||||
ApiReqParams<BUN_SQLITE_WGUI_ALL_TYPEDEFS>,
|
||||
ApiReqParams<BUN_SQLITE_WGUI_ALL_TYPEDEFS>
|
||||
>(query || {}, { sql_query: final_sql_query }) || {};
|
||||
|
||||
delete final_sql_query.join;
|
||||
const allowed_joins: TableType[] = ["hosts"];
|
||||
|
||||
const check_allowed_joins = checkAllowedJoins({
|
||||
joins: allowed_joins,
|
||||
query: final_sql_query,
|
||||
});
|
||||
|
||||
if (!check_allowed_joins.success) {
|
||||
return check_allowed_joins;
|
||||
}
|
||||
|
||||
const can_user_see_all_clients = checkUserAccess({
|
||||
user_types,
|
||||
@@ -28,11 +43,18 @@ export default async function (
|
||||
};
|
||||
}
|
||||
|
||||
const GET = await BunSQLite.select<BUN_SQLITE_WGUI_CLIENTS, TableType>({
|
||||
table,
|
||||
query: final_sql_query,
|
||||
targetId: id,
|
||||
const GET = await grabClients({
|
||||
query: final_query,
|
||||
client_id: id,
|
||||
host_id: final_sql_query.query?.host_id?.value as
|
||||
| string
|
||||
| number
|
||||
| undefined,
|
||||
user_id: final_sql_query.query?.user_id?.value as
|
||||
| string
|
||||
| number
|
||||
| undefined,
|
||||
});
|
||||
|
||||
return GET;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user