Skip to content

Commit c9f9d8a

Browse files
fix: could not download application with existing name (#795)
* improved error message when trying to duplicate application with existing name * remove console log --------- Co-authored-by: Antoine Hurard <[email protected]>
1 parent 778f01b commit c9f9d8a

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@
8282
},
8383
"duplicate": {
8484
"errors": {
85-
"invalidArguments": "Application name must be provided."
85+
"invalidArguments": "Application name must be provided.",
86+
"namedDuplicated": "Application with name {{name}} already exists. This name cannot be used. Please provide a different name."
8687
}
8788
},
8889
"edit": {

src/i18n/test.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@
8282
},
8383
"duplicate": {
8484
"errors": {
85-
"invalidArguments": "******"
85+
"invalidArguments": "******",
86+
"namedDuplicated": "****** {{name}} ******"
8687
}
8788
},
8889
"edit": {

src/schema/mutation/duplicateApplication.mutation.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ export default {
7070
if (ability.can('create', 'Application')) {
7171
// Check that a name was provided for the application
7272
if (args.name !== '') {
73+
// check if name is unique
74+
const applicationWithName = await Application.findOne({
75+
name: args.name,
76+
});
77+
if (applicationWithName) {
78+
throw new GraphQLError(
79+
context.i18next.t(
80+
'mutations.application.duplicate.errors.namedDuplicated',
81+
{ name: args.name }
82+
)
83+
);
84+
}
7385
// Copy application, and its permissions
7486
const application = new Application({
7587
name: args.name,

0 commit comments

Comments
 (0)