UNPKG

@webiny/api-form-builder-so-ddb

Version:

[![](https://img.shields.io/npm/dw/@webiny/api-form-builder-so-ddb.svg)](https://www.npmjs.com/package/@webiny/api-form-builder-so-ddb) [![](https://img.shields.io/npm/v/@webiny/api-form-builder-so-ddb.svg)](https://www.npmjs.com/package/@webiny/api-form

96 lines (94 loc) 2.33 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.createSystemStorageOperations = void 0; var _error = _interopRequireDefault(require("@webiny/error")); var _get = require("@webiny/db-dynamodb/utils/get"); var _dbDynamodb = require("@webiny/db-dynamodb"); const createSystemStorageOperations = params => { const { entity } = params; const createSystemPartitionKey = ({ tenant }) => { return `T#${tenant}#SYSTEM`; }; const createSystemSortKey = () => { return "FB"; }; const createKeys = params => { return { PK: createSystemPartitionKey(params), SK: createSystemSortKey() }; }; const createSystem = async params => { const { system } = params; const keys = createKeys(system); try { await (0, _dbDynamodb.put)({ entity, item: { ...system, ...keys } }); return system; } catch (ex) { throw new _error.default(ex.message || "Could not create the system record by given keys.", ex.code || "CREATE_SYSTEM_ERROR", { keys, system }); } }; const getSystem = async params => { const keys = createKeys(params); try { return await (0, _get.getClean)({ entity, keys }); } catch (ex) { throw new _error.default(ex.message || "Could not get the system record by given keys.", ex.code || "LOAD_SYSTEM_ERROR", { keys }); } }; const updateSystem = async params => { const { system, original } = params; const keys = createKeys(system); try { await (0, _dbDynamodb.put)({ entity, item: { ...system, ...keys } }); return system; } catch (ex) { throw new _error.default(ex.message || "Could not update the system record by given keys.", ex.code || "UPDATE_SYSTEM_ERROR", { keys, original, system }); } }; return { createSystem, getSystem, updateSystem, createSystemPartitionKey, createSystemSortKey }; }; exports.createSystemStorageOperations = createSystemStorageOperations; //# sourceMappingURL=index.js.map