Browse Source

fix(nocodb): revise convertAttachmentType logic

pull/4502/head
Wing-Kam Wong 2 years ago
parent
commit
159f0037bb
  1. 27
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

27
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -2737,6 +2737,15 @@ class BaseModelSqlv2 {
: await this.dbDriver.raw(query); : await this.dbDriver.raw(query);
} }
private _convertAttachmentType(attachmentColumns, d) {
attachmentColumns.forEach((col) => {
if (d[col.title] && typeof d[col.title] === 'string') {
d[col.title] = JSON.parse(d[col.title]);
}
});
return d;
}
private convertAttachmentType(data) { private convertAttachmentType(data) {
// attachment is stored in text and parse in UI // attachment is stored in text and parse in UI
// convertAttachmentType is used to convert the response in string to array of object in API response // convertAttachmentType is used to convert the response in string to array of object in API response
@ -2745,20 +2754,16 @@ class BaseModelSqlv2 {
(c) => c.uidt === UITypes.Attachment (c) => c.uidt === UITypes.Attachment
); );
if (attachmentColumns.length) { if (attachmentColumns.length) {
if (!Array.isArray(data)) { if (Array.isArray(data)) {
data = [data]; data = data.map((d) =>
this._convertAttachmentType(attachmentColumns, d)
);
} else {
this._convertAttachmentType(attachmentColumns, data);
} }
data = data.map((d) => {
attachmentColumns.forEach((col) => {
if (d[col.title] && typeof d[col.title] === 'string') {
d[col.title] = JSON.parse(d[col.title]);
}
});
return d;
});
} }
} }
return data.length === 1 ? data[0] : data; return data;
} }
} }

Loading…
Cancel
Save