Skip to content

Commit

Permalink
getDuplicate returns empty array instead of null, removes unnecessary…
Browse files Browse the repository at this point in the history
… return logic
  • Loading branch information
dhurley14 committed Feb 12, 2020
1 parent e2609c1 commit ad56892
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const createCreateRulesBulkRoute = (server: ServerFacade): Hapi.ServerRou

const rules = await Promise.all(
ruleDefinitions
.filter(rule => !dupes?.includes(rule.rule_id ?? ''))
.filter(rule => !dupes.includes(rule.rule_id ?? ''))
.map(async payloadRule => {
const {
description,
Expand Down Expand Up @@ -141,19 +141,16 @@ export const createCreateRulesBulkRoute = (server: ServerFacade): Hapi.ServerRou
}
})
);
if (dupes) {
return [
...rules,
...dupes.map(ruleId =>
createBulkErrorObject({
ruleId,
statusCode: 409,
message: `rule_id: "${ruleId}" already exists`,
})
),
];
}
return [...rules];
return [
...rules,
...dupes.map(ruleId =>
createBulkErrorObject({
ruleId,
statusCode: 409,
message: `rule_id: "${ruleId}" already exists`,
})
),
];
},
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ describe('utils', () => {
value2: 1,
value3: 1,
});
const expected = null;
const expected: string[] = [];
expect(output).toEqual(expected);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ export const transformOrImportError = (
}
};

export const getDuplicates = (lodashDict: Dictionary<number>): string[] | null => {
export const getDuplicates = (lodashDict: Dictionary<number>): string[] => {
const hasDuplicates = Object.values(lodashDict).some(i => i > 1);
if (hasDuplicates) {
return Object.keys(lodashDict).filter(key => lodashDict[key] > 1);
}
return null;
return [];
};

0 comments on commit ad56892

Please sign in to comment.