From 05bb2b7ea16e2afc754a5c54ba8630447ab65133 Mon Sep 17 00:00:00 2001 From: mertmit Date: Wed, 20 Jul 2022 11:33:16 +0300 Subject: [PATCH] feat: restrict duplicate select options Signed-off-by: mertmit --- packages/nocodb/src/lib/meta/api/columnApis.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/meta/api/columnApis.ts b/packages/nocodb/src/lib/meta/api/columnApis.ts index 95900cdc7b..d52d37d9d7 100644 --- a/packages/nocodb/src/lib/meta/api/columnApis.ts +++ b/packages/nocodb/src/lib/meta/api/columnApis.ts @@ -519,7 +519,6 @@ export async function columnAdd(req: Request, res: Response) { ? `${colBody.colOptions.options.map((o) => { if(o.title.includes(',')) { NcError.badRequest('Illegal char(\',\') for MultiSelect'); - throw new Error(''); } return `'${o.title.replace(/'/gi, '\'\'')}'`; }).join(',')}` @@ -680,7 +679,6 @@ export async function columnUpdate(req: Request, res: Response) { ? `${colBody.colOptions.options.map((o) => { if(o.title.includes(',')) { NcError.badRequest('Illegal char(\',\') for MultiSelect'); - throw new Error(''); } return `'${o.title.replace(/'/gi, '\'\'')}'`; }).join(',')}` @@ -698,6 +696,16 @@ export async function columnUpdate(req: Request, res: Response) { op.title = op.title.replace(/^'/, '').replace(/'$/, '') } + // Restrict duplicates + const titles = colBody.colOptions.options.map(el => el.title) + if (titles + .some( function(item) { + return titles.indexOf(item) !== titles.lastIndexOf(item); + }) + ) { + NcError.badRequest('Duplicates are not allowed!'); + } + // Handle option delete for (const option of column.colOptions.options.filter(oldOp => colBody.colOptions.options.find(newOp => newOp.id === oldOp.id) ? false : true)) { if (column.uidt === UITypes.SingleSelect) {