Updates
This commit is contained in:
@@ -106,7 +106,7 @@ export default async function googleAuth({
|
||||
*
|
||||
* @description make a request to datasquirel.com
|
||||
*/
|
||||
if (httpResponse?.success && httpResponse?.payload && database) {
|
||||
if (httpResponse?.success && httpResponse?.singleRes && database) {
|
||||
postLoginResponseHandler({
|
||||
database,
|
||||
httpResponse,
|
||||
|
||||
@@ -7,6 +7,7 @@ export default async function <
|
||||
table,
|
||||
body,
|
||||
targetId,
|
||||
query,
|
||||
}: APIPathsCrudParams<T>): Promise<APIResponseObject> {
|
||||
if (!targetId && !body?.searchQuery) {
|
||||
throw new Error(
|
||||
@@ -18,7 +19,7 @@ export default async function <
|
||||
...body?.crudParams,
|
||||
action: "delete",
|
||||
table,
|
||||
query: body?.searchQuery,
|
||||
query: query?.searchQuery,
|
||||
targetId,
|
||||
});
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ export default async function <
|
||||
table,
|
||||
body,
|
||||
targetId,
|
||||
query,
|
||||
}: APIPathsCrudParams<T>): Promise<APIResponseObject> {
|
||||
if (!targetId && !body?.searchQuery) {
|
||||
throw new Error(
|
||||
@@ -19,7 +20,7 @@ export default async function <
|
||||
action: "update",
|
||||
table,
|
||||
data: body?.data,
|
||||
query: body?.searchQuery,
|
||||
query: query?.searchQuery,
|
||||
targetId,
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ import {
|
||||
APIPathsCrudParams,
|
||||
APIPathsParams,
|
||||
APIResponseObject,
|
||||
DsqlCrudQueryObject,
|
||||
ServerQueryQueryObject,
|
||||
} from "../types";
|
||||
import getResult from "./functions/get-result";
|
||||
import { grabPathData } from "./utils/grab-path-data";
|
||||
@@ -38,15 +40,50 @@ export default async function apiCrudHandler<
|
||||
crudParams.allowedTable = checkedObj.allowedTable;
|
||||
crudParams.url = url;
|
||||
|
||||
const finalSearchQuery = _.merge(
|
||||
crudParams.query?.searchQuery,
|
||||
crudParams.body?.searchQuery
|
||||
);
|
||||
|
||||
if (finalSearchQuery) {
|
||||
crudParams.query = {
|
||||
...crudParams.query,
|
||||
searchQuery: finalSearchQuery,
|
||||
};
|
||||
}
|
||||
|
||||
if (targetId) {
|
||||
if (crudParams.query) {
|
||||
if (crudParams.query.crudParams) {
|
||||
crudParams.query.crudParams.targetId = targetId;
|
||||
if (crudParams.query.searchQuery) {
|
||||
crudParams.query.searchQuery = _.merge<
|
||||
DsqlCrudQueryObject<T>,
|
||||
DsqlCrudQueryObject<T>
|
||||
>(crudParams.query.searchQuery, {
|
||||
query: {
|
||||
id: {
|
||||
value: String(targetId),
|
||||
},
|
||||
} as ServerQueryQueryObject<T, string>,
|
||||
});
|
||||
} else {
|
||||
crudParams.query.crudParams = {
|
||||
targetId,
|
||||
crudParams.query.searchQuery = {
|
||||
query: {
|
||||
id: {
|
||||
value: String(targetId),
|
||||
},
|
||||
} as ServerQueryQueryObject<T, string>,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
crudParams.query = {
|
||||
searchQuery: {
|
||||
query: {
|
||||
id: {
|
||||
value: String(targetId),
|
||||
},
|
||||
} as ServerQueryQueryObject<T, string>,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ export default async function checks<
|
||||
const middRes = await crudMiddleware({
|
||||
body: newBody || ({} as any),
|
||||
query: newQuery || {},
|
||||
table,
|
||||
});
|
||||
|
||||
newBody = _.merge(newBody, middRes);
|
||||
@@ -86,6 +87,7 @@ export default async function checks<
|
||||
const middRes = await postMiddleware({
|
||||
body: newBody || ({} as any),
|
||||
query: newQuery || {},
|
||||
table,
|
||||
});
|
||||
|
||||
newBody = _.merge(newBody, middRes);
|
||||
@@ -95,6 +97,7 @@ export default async function checks<
|
||||
const middRes = await putMiddleware({
|
||||
body: newBody || ({} as any),
|
||||
query: newQuery || {},
|
||||
table,
|
||||
});
|
||||
|
||||
newBody = _.merge(newBody, middRes);
|
||||
@@ -104,6 +107,7 @@ export default async function checks<
|
||||
const middRes = await deleteMiddleware({
|
||||
body: newBody || ({} as any),
|
||||
query: newQuery || {},
|
||||
table,
|
||||
});
|
||||
|
||||
newBody = _.merge(newBody, middRes);
|
||||
|
||||
@@ -2915,11 +2915,13 @@ export type APIPathsParamsGetMiddleware<
|
||||
> = (params: { query: APIPathsQuery<T> }) => Promise<DsqlCrudQueryObject<T>>;
|
||||
|
||||
export type APIPathsParamsCrudMiddleware<
|
||||
T extends { [k: string]: any } = { [k: string]: any }
|
||||
T extends { [k: string]: any } = { [k: string]: any },
|
||||
K extends string = string
|
||||
> = (params: {
|
||||
body: APIPathsBody<T>;
|
||||
query: DsqlCrudQueryObject<T>;
|
||||
}) => Promise<APIPathsBody<T>>;
|
||||
table: K;
|
||||
}) => Promise<APIPathsBody<T> | undefined>;
|
||||
|
||||
export type APIPathsParamsAllowedTable = {
|
||||
table: string;
|
||||
|
||||
Reference in New Issue
Block a user