set correct path for duplicate create error

This commit is contained in:
Pierre Noël 2022-05-04 16:55:21 +02:00
parent 3024e94438
commit d724b1a1f6

View File

@ -15,7 +15,12 @@ const validateCreateFolderSchema = yup
.min(1) .min(1)
.matches(NO_SLASH_REGEX, 'name cannot contain slashes') .matches(NO_SLASH_REGEX, 'name cannot contain slashes')
.matches(NO_SPACES_AROUND, 'name cannot start or end with a whitespace') .matches(NO_SPACES_AROUND, 'name cannot start or end with a whitespace')
.required(), .required()
.test('is-folder-unique', 'name already taken', async function(name) {
const { exists } = getService('folder');
const doesExist = await exists({ parent: this.parent.parent || null, name });
return !doesExist;
}),
parent: yup parent: yup
.strapiID() .strapiID()
.nullable() .nullable()
@ -30,12 +35,7 @@ const validateCreateFolderSchema = yup
}), }),
}) })
.noUnknown() .noUnknown()
.required() .required();
.test('is-folder-unique', 'name already taken', async folder => {
const { exists } = getService('folder');
const doesExist = await exists({ parent: folder.parent || null, name: folder.name });
return !doesExist;
});
module.exports = { module.exports = {
validateCreateFolder: validateYupSchema(validateCreateFolderSchema), validateCreateFolder: validateYupSchema(validateCreateFolderSchema),