Skip to content

Commit

Permalink
Feat/show error on duplicate key (#867)
Browse files Browse the repository at this point in the history
Shown error on widget if duplicate key found
  • Loading branch information
chavda-bhavik authored Nov 16, 2024
2 parents 73cc9f0 + cb30581 commit 8a3bdb2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,17 @@ export class ValidRequest {
);
}

const columnKeysSet = new Set(parsedSchema.map((column) => column.key));
const columnKeysSet = new Set();
const duplicateKeys = parsedSchema.reduce((acc, item) => {
if (columnKeysSet.has(item.key)) acc.add(item.key);
columnKeysSet.add(item.key);

return acc;
}, new Set());
if (columnKeysSet.size !== parsedSchema.length) {
throw new UniqueColumnException(APIMessages.COLUMN_KEY_TAKEN);
throw new UniqueColumnException(
`${APIMessages.COLUMN_KEY_DUPLICATED} Duplicate Keys Found for ${[...duplicateKeys].join(', ')}`
);
}

for (const item of parsedSchema) {
Expand Down Expand Up @@ -115,6 +123,16 @@ export class ValidRequest {

return { success: true };
} catch (error) {
if (error instanceof UniqueColumnException) {
throw new HttpException(
{
message: error.message,
errorCode: error.getStatus(),
},
HttpStatus.UNPROCESSABLE_ENTITY
);
}

if (error instanceof DocumentNotFoundException) {
throw new HttpException(
{
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/app/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const APIMessages = {
INVALID_AUTH_TOKEN: 'Invalid authentication token',
INVALID_RSS_URL: 'The Specified URL doesn`t contain any RSS XML Feed, Please enter a Valid RSS XML URL',
COLUMN_KEY_TAKEN: 'Column with the same key already exists. Please provide a unique key from "Validations".',
COLUMN_KEY_DUPLICATED: 'Column with the same key already exists. Please provide a unique key.',
COLUMN_KEY_DUPLICATED: 'Column with the same key already exists. Please use a unique key in column.',
ERROR_DURING_VALIDATION:
'Something went wrong while validating data. Data is not imported yet, but team is informed about issue. Please try again after sometime.',
FEATURE_UNAVAILABLE: {
Expand Down

0 comments on commit 8a3bdb2

Please sign in to comment.