Updates
This commit is contained in:
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -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>;
|
||||
|
||||
+2
-2
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
+30
-4
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user