fix(NocoDB Node): Fix for updating or deleting rows with not default primary keys

This commit is contained in:
Michael Kret
2023-04-12 16:27:19 +03:00
committed by GitHub
parent e79679c023
commit ee7f86394e
3 changed files with 85 additions and 42 deletions

View File

@@ -328,17 +328,24 @@ export class NocoDB implements INodeType {
if (operation === 'delete') {
requestMethod = 'DELETE';
let primaryKey = 'id';
if (version === 1) {
endPoint = `/nc/${projectId}/api/v1/${table}/bulk`;
} else if (version === 2) {
endPoint = `/api/v1/db/data/bulk/noco/${projectId}/${table}`;
primaryKey = this.getNodeParameter('primaryKey', 0) as string;
if (primaryKey === 'custom') {
primaryKey = this.getNodeParameter('customPrimaryKey', 0) as string;
}
}
const body: IDataObject[] = [];
for (let i = 0; i < items.length; i++) {
const id = this.getNodeParameter('id', i) as string;
body.push({ id });
body.push({ [primaryKey]: id });
}
try {
@@ -532,18 +539,25 @@ export class NocoDB implements INodeType {
if (operation === 'update') {
requestMethod = 'PATCH';
let primaryKey = 'id';
if (version === 1) {
endPoint = `/nc/${projectId}/api/v1/${table}/bulk`;
requestMethod = 'PUT';
} else if (version === 2) {
endPoint = `/api/v1/db/data/bulk/noco/${projectId}/${table}`;
primaryKey = this.getNodeParameter('primaryKey', 0) as string;
if (primaryKey === 'custom') {
primaryKey = this.getNodeParameter('customPrimaryKey', 0) as string;
}
}
const body: IDataObject[] = [];
for (let i = 0; i < items.length; i++) {
const id = this.getNodeParameter('id', i) as string;
const newItem: IDataObject = { id };
const newItem: IDataObject = { [primaryKey]: id };
const dataToSend = this.getNodeParameter('dataToSend', i) as
| 'defineBelow'
| 'autoMapInputData';