Skip to content

Commit e729dc7

Browse files
committed
format recordData
1 parent 9c8d0de commit e729dc7

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

components/xata/actions/common/common.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,27 @@ export default {
7676
props.recordData.description = description;
7777
return {};
7878
},
79+
methods: {
80+
async formatRecordData() {
81+
const recordData = this.recordData;
82+
const { columns } = await this.app.listColumns({
83+
endpoint: this.endpoint,
84+
database: this.database,
85+
branch: this.branch,
86+
table: this.table,
87+
});
88+
if (!columns?.length) {
89+
return this.recordData;
90+
}
91+
for (const column of columns) {
92+
if (recordData[column.name] && (column.type === "int" || column.type === "float")) {
93+
recordData[column.name] = +recordData[column.name];
94+
}
95+
if (recordData[column.name] && column.type === "bool") {
96+
recordData[column.name] = !(recordData[column.name] === "false" || recordData[column.name === "0"]);
97+
}
98+
}
99+
return recordData;
100+
},
101+
},
79102
};

components/xata/actions/create-record/create-record.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default {
2323
database: this.database,
2424
branch: this.branch,
2525
table: this.table,
26-
data: this.recordData,
26+
data: await this.formatRecordData(),
2727
});
2828
$.export("$summary", `Successfully created Record with ID: '${response.id}'`);
2929
return response;

components/xata/actions/replace-record/replace-record.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default {
3636
branch: this.branch,
3737
table: this.table,
3838
recordId: this.recordId,
39-
data: this.recordData,
39+
data: await this.formatRecordData(),
4040
});
4141
$.export("$summary", `Successfully replaced Record with ID: '${response.id}'`);
4242
return response;

components/xata/actions/update-record/update-record.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default {
3636
branch: this.branch,
3737
table: this.table,
3838
recordId: this.recordId,
39-
data: this.recordData,
39+
data: await this.formatRecordData(),
4040
});
4141
$.export("$summary", `Successfully updated/created Record with ID: '${response.id}'`);
4242
return response;

0 commit comments

Comments
 (0)