Skip to content

Commit

Permalink
date getters
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Apr 11, 2024
1 parent c596d8b commit 8149185
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/codegen/makeClassMethods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,27 @@ describe("makeClassMethods", () => {
]),
).toContain("TheForeignTableNameRow[]");
});

it("returns Date object for date fields", () => {
expect(
run([
f({
name: "the_field_name",
type: "date",
}),
]),
).toContain("Date");
});

it("returns Date object for date rollups", () => {
expect(
run([
f({
name: "the_field_name",
type: "rollup",
formula_type: "date",
}),
]),
).toContain("Date");
});
});
7 changes: 7 additions & 0 deletions src/codegen/makeClassMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function makeGetter(
return parseFloat(this.getField<${t}>("${field.name}").toString());
}`;
}

if (field.type === "link_row") {
if (!field.link_row_table_id) {
throw new Error("link_row_table_id is missing");
Expand All @@ -28,6 +29,12 @@ function makeGetter(
}`;
}

if (field.type === "date" || field.formula_type === "date") {
return `public ${toCamelCase(`get ${field.name}`)}(): Date {
return new Date(this.getField<${t}>("${field.name}"));
}`;
}

return `public ${toCamelCase(`get ${field.name}`)}(): ${t} {
return this.getField<${t}>("${field.name}");
}`;
Expand Down

0 comments on commit 8149185

Please sign in to comment.