- additional functionality for DatasetController.ts
All checks were successful
CI Pipeline / japa-tests (push) Successful in 47s
All checks were successful
CI Pipeline / japa-tests (push) Successful in 47s
- additional validation rules like 'uniqueArray' - additional Lucid models like BaseModel.ts for filling attributes, Title.ts, Description.ts - npm updates for @adonisjs/core
This commit is contained in:
parent
c4f4eff0d9
commit
e0ff71b117
44 changed files with 2002 additions and 1556 deletions
|
@ -11,6 +11,34 @@ https://issuehunt.io/r/adonisjs/validator/issues/84
|
|||
// import { string } from '@ioc:Adonis/Core/Helpers';
|
||||
import { validator } from '@ioc:Adonis/Core/Validator';
|
||||
|
||||
validator.rule('uniqueArray', (dataArray, [field], { pointer, arrayExpressionPointer, errorReporter }) => {
|
||||
const array = dataArray; //validator.helpers.getFieldValue(data, field, tip);
|
||||
|
||||
if (!Array.isArray(array)) {
|
||||
throw new Error(`The ${pointer} must be an array.`);
|
||||
}
|
||||
|
||||
const uniqueValues = new Set();
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
const item = array[i];
|
||||
const attributeValue = item[field]; // Extract the attribute value for uniqueness check
|
||||
|
||||
if (uniqueValues.has(attributeValue)) {
|
||||
// throw new Error(`The ${field} array contains duplicate values for the ${field} attribute.`)
|
||||
errorReporter.report(
|
||||
pointer,
|
||||
'uniqueArray', // Keep an eye on this
|
||||
`The ${pointer} array contains duplicate values for the ${field} attribute.`,
|
||||
arrayExpressionPointer,
|
||||
{ field, array: pointer },
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
uniqueValues.add(attributeValue);
|
||||
}
|
||||
});
|
||||
|
||||
validator.rule(
|
||||
'translatedLanguage',
|
||||
(value, [mainLanguageField, typeField], { root, tip, pointer, arrayExpressionPointer, errorReporter }) => {
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue