Arno Kaimbacher
49bd96ee77
Some checks failed
CI Pipeline / japa-tests (push) Failing after 1m8s
- **AdminuserController.ts**: enable editing `first_name` and `last_name` for user creation and updates - **MimetypeController.ts**: add creation support for mimetypes with selectable extensions - **Models**: add `Mimetype` model (mime_type.ts); add `SnakeCaseNamingStrategy` for User model - **Validators**: - **updateDatasetValidator**: increase title length to 255 and description length to 2500 - **User Validators**: refine `createUserValidator` and `updateUserValidator` to include `first_name` and `last_name` - **vanilla_error_reporter**: improve error reporting for wildcard fields - **SKOS Query**: refine keyword request in `SearchCategoryAutocomplete.vue` - **UI Enhancements**: - improve icon design in wizard (Wizard.vue) - add components for mimetype creation (Create.vue and button in Index.vue) - **Routes**: update `routes.ts` to include new AdonisJS routes
65 lines
2.5 KiB
TypeScript
65 lines
2.5 KiB
TypeScript
import vine, { SimpleMessagesProvider } from '@vinejs/vine';
|
|
|
|
/**
|
|
* Validates the role's creation action
|
|
* node ace make:validator role
|
|
*/
|
|
export const createRoleValidator = vine.compile(
|
|
vine.object({
|
|
name: vine
|
|
.string()
|
|
.isUnique({ table: 'roles', column: 'name' })
|
|
.trim()
|
|
.minLength(3)
|
|
.maxLength(255)
|
|
.regex(/^[a-zA-Z0-9]+$/), //Must be alphanumeric with hyphens or underscores
|
|
display_name: vine
|
|
.string()
|
|
.isUnique({ table: 'roles', column: 'display_name' })
|
|
.trim()
|
|
.minLength(3)
|
|
.maxLength(255)
|
|
.regex(/^[a-zA-Z0-9]+$/),
|
|
description: vine.string().trim().escape().minLength(3).maxLength(255).optional(),
|
|
permissions: vine.array(vine.number()).minLength(1), // define at least one permission for the new role
|
|
}),
|
|
);
|
|
|
|
export const updateRoleValidator = vine.withMetaData<{ roleId: number }>().compile(
|
|
vine.object({
|
|
name: vine
|
|
.string()
|
|
// .unique(async (db, value, field) => {
|
|
// const result = await db.from('roles').select('id').whereNot('id', field.meta.roleId).where('name', value).first();
|
|
// return result.length ? false : true;
|
|
// })
|
|
.isUnique({
|
|
table: 'roles',
|
|
column: 'name',
|
|
whereNot: (field) => field.meta.roleId,
|
|
})
|
|
.trim()
|
|
.minLength(3)
|
|
.maxLength(255),
|
|
|
|
description: vine.string().trim().escape().minLength(3).maxLength(255).optional(),
|
|
permissions: vine.array(vine.number()).minLength(1), // define at least one permission for the new role
|
|
}),
|
|
);
|
|
|
|
let messagesProvider = new SimpleMessagesProvider({
|
|
// Applicable for all fields
|
|
'required': 'The {{ field }} field is required',
|
|
'unique': '{{ field }} must be unique, and this value is already taken',
|
|
'string': 'The value of {{ field }} field must be a string',
|
|
'email': 'The value is not a valid email address',
|
|
|
|
// 'contacts.0.email.required': 'The primary email of the contact is required',
|
|
// 'contacts.*.email.required': 'Contact email is required',
|
|
'permissions.minLength': 'at least {{min }} permission must be defined',
|
|
'permissions.*.number': 'Define permissions as valid numbers',
|
|
});
|
|
|
|
createRoleValidator.messagesProvider = messagesProvider;
|
|
updateRoleValidator.messagesProvider = messagesProvider;
|