Updates
This commit is contained in:
parent
0e5b5fea6e
commit
f95cf21ffd
@ -90,7 +90,7 @@ function googleAuth(_a) {
|
||||
*
|
||||
* @description make a request to datasquirel.com
|
||||
*/
|
||||
if ((httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.success) && (httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.payload) && database) {
|
||||
if ((httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.success) && (httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.singleRes) && database) {
|
||||
(0, post_login_response_handler_1.default)({
|
||||
database,
|
||||
httpResponse,
|
||||
|
||||
@ -3,4 +3,4 @@ export default function <T extends {
|
||||
[k: string]: any;
|
||||
} = {
|
||||
[k: string]: any;
|
||||
}>({ table, body, targetId, }: APIPathsCrudParams<T>): Promise<APIResponseObject>;
|
||||
}>({ table, body, targetId, query, }: APIPathsCrudParams<T>): Promise<APIResponseObject>;
|
||||
|
||||
@ -15,11 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
const crud_1 = __importDefault(require("../../utils/data-fetching/crud"));
|
||||
function default_1(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ table, body, targetId, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ table, body, targetId, query, }) {
|
||||
if (!targetId && !(body === null || body === void 0 ? void 0 : body.searchQuery)) {
|
||||
throw new Error(`Target ID or \`searchQuery\` field is required to delete Data.`);
|
||||
}
|
||||
const DELETE_RESLT = yield (0, crud_1.default)(Object.assign(Object.assign({}, body === null || body === void 0 ? void 0 : body.crudParams), { action: "delete", table, query: body === null || body === void 0 ? void 0 : body.searchQuery, targetId }));
|
||||
const DELETE_RESLT = yield (0, crud_1.default)(Object.assign(Object.assign({}, body === null || body === void 0 ? void 0 : body.crudParams), { action: "delete", table, query: query === null || query === void 0 ? void 0 : query.searchQuery, targetId }));
|
||||
return DELETE_RESLT;
|
||||
});
|
||||
}
|
||||
|
||||
@ -3,4 +3,4 @@ export default function <T extends {
|
||||
[k: string]: any;
|
||||
} = {
|
||||
[k: string]: any;
|
||||
}>({ table, body, targetId, }: APIPathsCrudParams<T>): Promise<APIResponseObject>;
|
||||
}>({ table, body, targetId, query, }: APIPathsCrudParams<T>): Promise<APIResponseObject>;
|
||||
|
||||
@ -15,11 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
const crud_1 = __importDefault(require("../../utils/data-fetching/crud"));
|
||||
function default_1(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ table, body, targetId, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ table, body, targetId, query, }) {
|
||||
if (!targetId && !(body === null || body === void 0 ? void 0 : body.searchQuery)) {
|
||||
throw new Error(`Target ID or \`searchQuery\` field is required to update Data.`);
|
||||
}
|
||||
const PUT_RESULT = yield (0, crud_1.default)(Object.assign(Object.assign({}, body === null || body === void 0 ? void 0 : body.crudParams), { action: "update", table, data: body === null || body === void 0 ? void 0 : body.data, query: body === null || body === void 0 ? void 0 : body.searchQuery, targetId }));
|
||||
const PUT_RESULT = yield (0, crud_1.default)(Object.assign(Object.assign({}, body === null || body === void 0 ? void 0 : body.crudParams), { action: "update", table, data: body === null || body === void 0 ? void 0 : body.data, query: query === null || query === void 0 ? void 0 : query.searchQuery, targetId }));
|
||||
return PUT_RESULT;
|
||||
});
|
||||
}
|
||||
|
||||
34
dist/package-shared/api-paths/index.js
vendored
34
dist/package-shared/api-paths/index.js
vendored
@ -22,6 +22,7 @@ const put_result_1 = __importDefault(require("./functions/put-result"));
|
||||
const delete_result_1 = __importDefault(require("./functions/delete-result"));
|
||||
function apiCrudHandler(params) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var _a, _b;
|
||||
try {
|
||||
const { auth, method } = params;
|
||||
const isAuthorized = yield (auth === null || auth === void 0 ? void 0 : auth());
|
||||
@ -34,17 +35,42 @@ function apiCrudHandler(params) {
|
||||
crudParams.body = checkedObj.body;
|
||||
crudParams.allowedTable = checkedObj.allowedTable;
|
||||
crudParams.url = url;
|
||||
const finalSearchQuery = lodash_1.default.merge((_a = crudParams.query) === null || _a === void 0 ? void 0 : _a.searchQuery, (_b = crudParams.body) === null || _b === void 0 ? void 0 : _b.searchQuery);
|
||||
if (finalSearchQuery) {
|
||||
crudParams.query = Object.assign(Object.assign({}, 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 = lodash_1.default.merge(crudParams.query.searchQuery, {
|
||||
query: {
|
||||
id: {
|
||||
value: String(targetId),
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
else {
|
||||
crudParams.query.crudParams = {
|
||||
targetId,
|
||||
crudParams.query.searchQuery = {
|
||||
query: {
|
||||
id: {
|
||||
value: String(targetId),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
else {
|
||||
crudParams.query = {
|
||||
searchQuery: {
|
||||
query: {
|
||||
id: {
|
||||
value: String(targetId),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
switch (method) {
|
||||
case "GET":
|
||||
|
||||
@ -57,6 +57,7 @@ function checks(_a) {
|
||||
const middRes = yield crudMiddleware({
|
||||
body: newBody || {},
|
||||
query: newQuery || {},
|
||||
table,
|
||||
});
|
||||
newBody = lodash_1.default.merge(newBody, middRes);
|
||||
}
|
||||
@ -64,6 +65,7 @@ function checks(_a) {
|
||||
const middRes = yield postMiddleware({
|
||||
body: newBody || {},
|
||||
query: newQuery || {},
|
||||
table,
|
||||
});
|
||||
newBody = lodash_1.default.merge(newBody, middRes);
|
||||
}
|
||||
@ -71,6 +73,7 @@ function checks(_a) {
|
||||
const middRes = yield putMiddleware({
|
||||
body: newBody || {},
|
||||
query: newQuery || {},
|
||||
table,
|
||||
});
|
||||
newBody = lodash_1.default.merge(newBody, middRes);
|
||||
}
|
||||
@ -78,6 +81,7 @@ function checks(_a) {
|
||||
const middRes = yield deleteMiddleware({
|
||||
body: newBody || {},
|
||||
query: newQuery || {},
|
||||
table,
|
||||
});
|
||||
newBody = lodash_1.default.merge(newBody, middRes);
|
||||
}
|
||||
|
||||
5
dist/package-shared/types/index.d.ts
vendored
5
dist/package-shared/types/index.d.ts
vendored
@ -2255,10 +2255,11 @@ export type APIPathsParamsCrudMiddleware<T extends {
|
||||
[k: string]: any;
|
||||
} = {
|
||||
[k: string]: any;
|
||||
}> = (params: {
|
||||
}, 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;
|
||||
allowedFields?: (string | RegExp)[];
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "5.6.0",
|
||||
"version": "5.6.1",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user