mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Implement unique constraint support (#4467)
* Allow creating unique fields * Allow removing unique constriant * Show unique constraint error as validation error in app
This commit is contained in:
@@ -110,14 +110,16 @@ export function useItem(collection: Ref<string>, primaryKey: Ref<string | number
|
||||
return response.data.data;
|
||||
} catch (err) {
|
||||
if (err?.response?.data?.errors) {
|
||||
const validationTypes = ['FAILED_VALIDATION', 'RECORD_NOT_UNIQUE'];
|
||||
|
||||
validationErrors.value = err.response.data.errors
|
||||
.filter((err: APIError) => err?.extensions?.code === 'FAILED_VALIDATION')
|
||||
.filter((err: APIError) => validationTypes.includes(err?.extensions?.code))
|
||||
.map((err: APIError) => {
|
||||
return err.extensions;
|
||||
});
|
||||
|
||||
const otherErrors = err.response.data.errors.filter(
|
||||
(err: APIError) => err?.extensions?.code !== 'FAILED_VALIDATION'
|
||||
(err: APIError) => validationTypes.includes(err?.extensions?.code) === false
|
||||
);
|
||||
|
||||
if (otherErrors.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user