datasquirel/dist/package-shared/api/crud/post.js
2025-07-05 16:14:11 +01:00

38 lines
1.8 KiB
JavaScript

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = apiCrudPOST;
const path_1 = __importDefault(require("path"));
const query_dsql_api_1 = __importDefault(require("../../functions/api/query-dsql-api"));
const grab_api_base_path_1 = __importDefault(require("../../utils/grab-api-base-path"));
function apiCrudPOST(_a) {
return __awaiter(this, arguments, void 0, function* ({ dbName, tableName, body, update, apiKey, }) {
const basePath = (0, grab_api_base_path_1.default)({ paradigm: "crud" });
const passedID = body.id;
const finalID = update
? typeof passedID === "number"
? String(passedID)
: passedID
: undefined;
const finalPath = path_1.default.join(basePath, dbName, tableName, finalID || "");
const GET_RES = yield (0, query_dsql_api_1.default)({
method: update ? "PUT" : "POST",
path: finalPath,
body,
apiKey,
});
return GET_RES;
});
}