From d452c1c02431ba1ec8d82d3ac7944e04ff19c6b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Salazar?= <73718835+joshrs23@users.noreply.github.com> Date: Mon, 24 Nov 2025 17:15:08 -0500 Subject: [PATCH] adding news functions of vendor in krowSDK --- internal-api-harness/src/api/krowSDK.js | 142 +++++++++++++++++++++++- 1 file changed, 137 insertions(+), 5 deletions(-) diff --git a/internal-api-harness/src/api/krowSDK.js b/internal-api-harness/src/api/krowSDK.js index f543e36b..fb6a535e 100644 --- a/internal-api-harness/src/api/krowSDK.js +++ b/internal-api-harness/src/api/krowSDK.js @@ -155,7 +155,12 @@ const dataconnectEntityConfig = { }, Vendor: { - + list: 'listVendor', + get: 'getVendorById', + create: 'createVendor', + update: 'updateVendor', + delete: 'deleteVendor', + filter: 'filterVendors', }, VendorRate: { @@ -265,10 +270,137 @@ Object.entries(dataconnectEntityConfig).forEach(([entityName, ops]) => { }, }), - // ...(ops.get && { get: async (params) => { ... } }), - // ...(ops.update && { update: async (params) => { ... } }), - // ...(ops.delete && { delete: async (params) => { ... } }), - // ...(ops.filter && { filter: async (params) => { ... } }), + //get + ...(ops.get && { + get: async (params) => { + const fn = dcSdk[ops.get]; + if (typeof fn !== 'function') { + throw new Error( + `Data Connect operation "${ops.get}" not found for entity "${entityName}".` + ); + } + + if (!params || typeof params !== 'object') { + throw new Error(`${entityName}.get expects an object of variables (e.g. { id })`); + } + + return fn(dataConnect, params); + }, + }), + + //update + ...(ops.update && { + update: async (params) => { + const fn = dcSdk[ops.update]; + if (typeof fn !== 'function') { + throw new Error( + `Data Connect operation "${ops.update}" not found for entity "${entityName}".` + ); + } + + if (!params || typeof params !== 'object') { + throw new Error( + `${entityName}.update expects an object of variables matching the GraphQL mutation` + ); + } + + const { id, data } = params; + + if (!id) { + throw new Error(`${entityName}.update requires an "id" field`); + } + + if (!data || typeof data !== 'object') { + throw new Error( + `${entityName}.update requires a "data" object with the fields to update` + ); + } + + const vars = { id, ...data }; + + return fn(dataConnect, vars); + + }, + }), + + + // delete + ...(ops.delete && { + delete: async (params) => { + const fn = dcSdk[ops.delete]; + if (typeof fn !== 'function') { + throw new Error( + `Data Connect operation "${ops.delete}" not found for entity "${entityName}".` + ); + } + + if (!params || typeof params !== 'object') { + throw new Error( + `${entityName}.delete expects an object like { id }` + ); + } + + const { id } = params; + + if (!id) { + throw new Error(`${entityName}.delete requires an "id" field`); + } + + // Data Connect solo espera { id } como variables + return fn(dataConnect, { id }); + }, + }), + + + // filter + ...(ops.filter && { + filter: async (params) => { + const fn = dcSdk[ops.filter]; + if (typeof fn !== 'function') { + throw new Error( + `Data Connect operation "${ops.filter}" not found for entity "${entityName}".` + ); + } + + if (!params) { + if (ops.list) {//if no params, call to list() + const listFn = dcSdk[ops.list]; + if (typeof listFn !== 'function') { + throw new Error( + `Data Connect operation "${ops.list}" not found for entity "${entityName}".` + ); + } + return listFn(dataConnect); + } + throw new Error(`${entityName}.filter expects params or a list operation`); + } + const rawFilters = params.filters ?? params; + const variables = {}; + + for (const [key, value] of Object.entries(rawFilters)) {//cleaning undefined/null/'' values + if (value !== undefined && value !== null && value !== '') { + variables[key] = value; + } + } + + // if no valid filters, call to list() + if (Object.keys(variables).length === 0) { + if (ops.list) { + const listFn = dcSdk[ops.list]; + if (typeof listFn !== 'function') { + throw new Error( + `Data Connect operation "${ops.list}" not found for entity "${entityName}".` + ); + } + return listFn(dataConnect); + } + throw new Error(`${entityName}.filter received no valid filters and no list operation`); + } + + return fn(dataConnect, variables); + }, + }), + }; });