Merge pull request #14702 from Budibase/view-calculation-validation
Validate that you cannot create a calculation view with more than 5 calculation fields.
This commit is contained in:
commit
50f628ab53
|
@ -571,6 +571,53 @@ describe.each([
|
|||
expect(sum.calculationType).toEqual(CalculationType.SUM)
|
||||
expect(sum.field).toEqual("Price")
|
||||
})
|
||||
|
||||
it("cannot create a calculation view with more than 5 aggregations", async () => {
|
||||
await config.api.viewV2.create(
|
||||
{
|
||||
tableId: table._id!,
|
||||
name: generator.guid(),
|
||||
schema: {
|
||||
sum: {
|
||||
visible: true,
|
||||
calculationType: CalculationType.SUM,
|
||||
field: "Price",
|
||||
},
|
||||
count: {
|
||||
visible: true,
|
||||
calculationType: CalculationType.COUNT,
|
||||
field: "Price",
|
||||
},
|
||||
min: {
|
||||
visible: true,
|
||||
calculationType: CalculationType.MIN,
|
||||
field: "Price",
|
||||
},
|
||||
max: {
|
||||
visible: true,
|
||||
calculationType: CalculationType.MAX,
|
||||
field: "Price",
|
||||
},
|
||||
avg: {
|
||||
visible: true,
|
||||
calculationType: CalculationType.AVG,
|
||||
field: "Price",
|
||||
},
|
||||
sum2: {
|
||||
visible: true,
|
||||
calculationType: CalculationType.SUM,
|
||||
field: "Price",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
status: 400,
|
||||
body: {
|
||||
message: "Calculation views can only have a maximum of 5 fields",
|
||||
},
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("update", () => {
|
||||
|
|
|
@ -64,6 +64,14 @@ async function guardCalculationViewSchema(
|
|||
view: Omit<ViewV2, "id" | "version">
|
||||
) {
|
||||
const calculationFields = helpers.views.calculationFields(view)
|
||||
|
||||
if (Object.keys(calculationFields).length > 5) {
|
||||
throw new HTTPError(
|
||||
"Calculation views can only have a maximum of 5 fields",
|
||||
400
|
||||
)
|
||||
}
|
||||
|
||||
for (const calculationFieldName of Object.keys(calculationFields)) {
|
||||
const schema = calculationFields[calculationFieldName]
|
||||
const isCount = schema.calculationType === CalculationType.COUNT
|
||||
|
|
Loading…
Reference in New Issue