Browse Source

fix: validation corrections

pull/7268/head
Pranav C 11 months ago
parent
commit
bc9f106b44
  1. 43
      packages/nocodb-sdk/src/lib/formulaHelpers.ts

43
packages/nocodb-sdk/src/lib/formulaHelpers.ts

@ -389,7 +389,10 @@ const formulas: Record<string, FormulaMeta> = {
); );
} }
} }
if (parsedTree.arguments[2].type === JSEPNode.LITERAL) { if (
parsedTree.arguments[2] &&
parsedTree.arguments[2].type === JSEPNode.LITERAL
) {
if ( if (
![ ![
'milliseconds', 'milliseconds',
@ -410,7 +413,7 @@ const formulas: Record<string, FormulaMeta> = {
'Q', 'Q',
'years', 'years',
'y', 'y',
].includes(parsedTree.arguments[0].value) ].includes(parsedTree.arguments[2].value)
) { ) {
throw new FormulaError( throw new FormulaError(
FormulaErrorType.TYPE_MISMATCH, FormulaErrorType.TYPE_MISMATCH,
@ -896,8 +899,12 @@ const formulas: Record<string, FormulaMeta> = {
} }
} }
if (parsedTree.arguments[1].type === JSEPNode.LITERAL) { // if second argument is present and literal then validate it
const value = parsedTree.arguments[0].value; if (
parsedTree.arguments[1] &&
parsedTree.arguments[1].type === JSEPNode.LITERAL
) {
const value = parsedTree.arguments[1].value;
if ( if (
typeof value !== 'string' || typeof value !== 'string' ||
![ ![
@ -1343,23 +1350,37 @@ export function validateFormulaAndExtractTreeWithType(
case UITypes.LastModifiedTime: case UITypes.LastModifiedTime:
res.dataType = FormulaDataTypes.DATE; res.dataType = FormulaDataTypes.DATE;
break; break;
// not supported
case UITypes.ForeignKey:
case UITypes.Attachment:
case UITypes.ID:
case UITypes.Time:
case UITypes.Currency: case UITypes.Currency:
case UITypes.Percent: case UITypes.Percent:
case UITypes.Duration: case UITypes.Duration:
case UITypes.Links:
case UITypes.Rollup: case UITypes.Rollup:
res.dataType = FormulaDataTypes.NUMERIC;
break;
case UITypes.Attachment:
res.dataType = FormulaDataTypes.STRING;
break;
case UITypes.Checkbox:
res.dataType = FormulaDataTypes.NUMERIC;
break;
case UITypes.ID:
case UITypes.ForeignKey:
{
res.dataType = FormulaDataTypes.NUMERIC;
}
break;
// not supported
case UITypes.Time:
case UITypes.Lookup: case UITypes.Lookup:
case UITypes.Barcode: case UITypes.Barcode:
case UITypes.Button: case UITypes.Button:
case UITypes.Checkbox:
case UITypes.Collaborator: case UITypes.Collaborator:
case UITypes.QrCode: case UITypes.QrCode:
default: default:
throw new FormulaError(FormulaErrorType.NOT_SUPPORTED, {}); break;
// throw new FormulaError(FormulaErrorType.NOT_SUPPORTED, {});
} }
} }
} else if (parsedTree.type === JSEPNode.LITERAL) { } else if (parsedTree.type === JSEPNode.LITERAL) {

Loading…
Cancel
Save