Browse Source

feat: restrict duplicate select options

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/2751/head
mertmit 2 years ago
parent
commit
05bb2b7ea1
  1. 12
      packages/nocodb/src/lib/meta/api/columnApis.ts

12
packages/nocodb/src/lib/meta/api/columnApis.ts

@ -519,7 +519,6 @@ export async function columnAdd(req: Request, res: Response<TableType>) {
? `${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<TableType>) {
? `${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<TableType>) {
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) {

Loading…
Cancel
Save