Browse Source

Change validators name

pull/2093/head
Hironsan 2 years ago
parent
commit
28fef9167a
3 changed files with 13 additions and 16 deletions
  1. 4
      frontend/components/project/ProjectDescriptionField.vue
  2. 10
      frontend/components/project/ProjectNameField.vue
  3. 15
      frontend/domain/models/project/project.ts

4
frontend/components/project/ProjectDescriptionField.vue

@ -11,7 +11,7 @@
<script lang="ts">
import Vue from 'vue'
import { isEmptyText } from '~/domain/models/project/project'
import { validateMinLength } from '~/domain/models/project/project'
export default Vue.extend({
props: {
@ -24,7 +24,7 @@ export default Vue.extend({
data() {
return {
descriptionRules: [
(text: string) => !isEmptyText(text) || this.$t('rules.description.required')
(text: string) => validateMinLength(text) || this.$t('rules.description.required')
]
}
}

10
frontend/components/project/ProjectNameField.vue

@ -11,10 +11,7 @@
<script lang="ts">
import Vue from 'vue'
import {
isEmptyText,
projectNameMustBeLessThan100Characters
} from '~/domain/models/project/project'
import { validateMinLength, validateNameMaxLength } from '~/domain/models/project/project'
export default Vue.extend({
props: {
@ -27,9 +24,8 @@ export default Vue.extend({
data() {
return {
projectNameRules: [
(text: string) => !isEmptyText(text) || this.$t('rules.projectName.required'),
(text: string) =>
projectNameMustBeLessThan100Characters(text) || this.$t('rules.projectName.maxLength')
(text: string) => validateMinLength(text) || this.$t('rules.projectName.required'),
(text: string) => validateNameMaxLength(text) || this.$t('rules.projectName.maxLength')
]
}
}

15
frontend/domain/models/project/project.ts

@ -20,13 +20,14 @@ export const allProjectTypes = <const>[
Speech2text
]
export type ProjectType = typeof allProjectTypes[number]
const MIN_LENGTH = 1
const MAX_PROJECT_NAME_LENGTH = 100
export const isEmptyText = (text: string): boolean => {
return text.trim() === ''
export const validateMinLength = (text: string): boolean => {
return text.trim().length >= MIN_LENGTH
}
const MAX_PROJECT_NAME_LENGTH = 100
export const projectNameMustBeLessThan100Characters = (name: string): boolean => {
export const validateNameMaxLength = (name: string): boolean => {
return name.trim().length <= MAX_PROJECT_NAME_LENGTH
}
@ -53,13 +54,13 @@ export class Project {
readonly author: string = '',
readonly isTextProject: boolean = false
) {
if (isEmptyText(_name)) {
if (!validateMinLength(_name)) {
throw new Error('Project name is required')
}
if (!projectNameMustBeLessThan100Characters(_name)) {
if (!validateNameMaxLength(_name)) {
throw new Error('Project name must be less than 100 characters')
}
if (isEmptyText(_description)) {
if (!validateMinLength(_description)) {
throw new Error('Project description is required')
}
if (!allProjectTypes.includes(_projectType as ProjectType)) {

Loading…
Cancel
Save