bfg-common 1.5.786 → 1.5.788
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
</template>
|
|
26
26
|
|
|
27
27
|
<script setup lang="ts">
|
|
28
|
-
import type { API_UI_I_Error } from '~/lib/models/store/interfaces'
|
|
28
|
+
// import type { API_UI_I_Error } from '~/lib/models/store/interfaces'
|
|
29
29
|
import type { UI_I_Localization } from '~/lib/models/interfaces'
|
|
30
30
|
import { validateObjectName } from '~/lib/utils/validation'
|
|
31
31
|
import type { UI_I_TreeNode } from '~/components/common/recursionTree/lib/models/interfaces'
|
|
@@ -121,42 +121,57 @@ const submit = async (cb: Function): Promise<void> => {
|
|
|
121
121
|
}
|
|
122
122
|
// TODO use for import vms
|
|
123
123
|
const checkNameIsValid = async (nameLocal: string): Promise<boolean> => {
|
|
124
|
-
const nameRequestUrlLocal: string = props.nameRequestUrl.replace(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
console.log(statusCode, 11)
|
|
124
|
+
const nameRequestUrlLocal: string = props.nameRequestUrl.replace(
|
|
125
|
+
'{name}',
|
|
126
|
+
nameLocal
|
|
127
|
+
)
|
|
130
128
|
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
129
|
+
const customMessages = {
|
|
130
|
+
400: localization.value.common.emptyNameValidationDescription,
|
|
131
|
+
405: localization.value.common.kindValidationDescription,
|
|
132
|
+
406: localization.value.common.nameValidationDescription,
|
|
133
|
+
409: props.nameExistValidationDescription,
|
|
134
|
+
}
|
|
135
|
+
const { isValid, statusCode, error } = await validateObjectName(
|
|
136
|
+
{ url: nameRequestUrlLocal },
|
|
137
|
+
customMessages
|
|
136
138
|
)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
localization.value.common.emptyNameValidationDescription,
|
|
142
|
-
])
|
|
143
|
-
return false
|
|
144
|
-
case 405: // Invalid kind
|
|
145
|
-
showValidationErrors([
|
|
146
|
-
localization.value.common.kindValidationDescription,
|
|
147
|
-
])
|
|
148
|
-
return false
|
|
149
|
-
case 406: // Invalid name
|
|
150
|
-
showValidationErrors([
|
|
151
|
-
localization.value.common.nameValidationDescription,
|
|
152
|
-
])
|
|
153
|
-
return false
|
|
154
|
-
case 409: // Name exist
|
|
155
|
-
showValidationErrors([props.nameExistValidationDescription])
|
|
156
|
-
return false
|
|
139
|
+
|
|
140
|
+
if (!isValid) {
|
|
141
|
+
showValidationErrors([error])
|
|
142
|
+
return isValid
|
|
157
143
|
}
|
|
158
144
|
|
|
159
|
-
return
|
|
145
|
+
return isValid
|
|
146
|
+
|
|
147
|
+
// const { error } = await useMyFetch<null, API_UI_I_Error>(
|
|
148
|
+
// nameRequestUrlLocal,
|
|
149
|
+
// {
|
|
150
|
+
// method: 'GET',
|
|
151
|
+
// }
|
|
152
|
+
// )
|
|
153
|
+
// const status = error.value?.statusCode || 200
|
|
154
|
+
// switch (statusCode) {
|
|
155
|
+
// case 400: // Empty name
|
|
156
|
+
// showValidationErrors([
|
|
157
|
+
// localization.value.common.emptyNameValidationDescription,
|
|
158
|
+
// ])
|
|
159
|
+
// return false
|
|
160
|
+
// case 405: // Invalid kind
|
|
161
|
+
// showValidationErrors([
|
|
162
|
+
// localization.value.common.kindValidationDescription,
|
|
163
|
+
// ])
|
|
164
|
+
// return false
|
|
165
|
+
// case 406: // Invalid name
|
|
166
|
+
// showValidationErrors([
|
|
167
|
+
// localization.value.common.nameValidationDescription,
|
|
168
|
+
// ])
|
|
169
|
+
// return false
|
|
170
|
+
// case 409: // Name exist
|
|
171
|
+
// showValidationErrors([props.nameExistValidationDescription])
|
|
172
|
+
// return false
|
|
173
|
+
// }
|
|
174
|
+
// return true
|
|
160
175
|
}
|
|
161
176
|
|
|
162
177
|
const errors = ref<string[]>([])
|
package/lib/utils/validation.ts
CHANGED
|
@@ -7,8 +7,9 @@ import type { UI_T_Project } from '~/lib/models/types'
|
|
|
7
7
|
import { UI_E_ObjectNodeKind } from '~/lib/models/enums'
|
|
8
8
|
|
|
9
9
|
export const validateObjectName = async (
|
|
10
|
-
args: UI_I_ValidateNameByParams | UI_I_ValidateNameByUrl
|
|
11
|
-
|
|
10
|
+
args: UI_I_ValidateNameByParams | UI_I_ValidateNameByUrl,
|
|
11
|
+
customMessages?: Partial<Record<number, string>>
|
|
12
|
+
): Promise<{ statusCode: number; error: string; isValid: boolean }> => {
|
|
12
13
|
const url =
|
|
13
14
|
'url' in args
|
|
14
15
|
? args.url
|
|
@@ -18,7 +19,6 @@ export const validateObjectName = async (
|
|
|
18
19
|
args.kind,
|
|
19
20
|
args.datacenterId
|
|
20
21
|
)
|
|
21
|
-
console.log(url, 'checkName URL')
|
|
22
22
|
|
|
23
23
|
const { error } = await useMyFetch<null, API_UI_I_Error>(url, {
|
|
24
24
|
method: 'GET',
|
|
@@ -28,12 +28,18 @@ export const validateObjectName = async (
|
|
|
28
28
|
return {
|
|
29
29
|
statusCode: 200,
|
|
30
30
|
error: '',
|
|
31
|
+
isValid: true,
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
const status = error.value?.statusCode ?? 500
|
|
34
36
|
return {
|
|
35
|
-
statusCode:
|
|
36
|
-
error:
|
|
37
|
+
statusCode: status,
|
|
38
|
+
error:
|
|
39
|
+
customMessages?.[status] ?? // сообщение снаружи
|
|
40
|
+
error.value.data?.error_message ??
|
|
41
|
+
error.value.data, // сообщение backend
|
|
42
|
+
isValid: false,
|
|
37
43
|
}
|
|
38
44
|
}
|
|
39
45
|
|
|
@@ -53,6 +59,7 @@ const buildValidationUrl = (
|
|
|
53
59
|
params.set('kind', String(kind))
|
|
54
60
|
if (datacenterId) params.set('datacenter', datacenterId)
|
|
55
61
|
|
|
62
|
+
// Если указан datacenterId — имя проверяется только в рамках этого датацентра.
|
|
56
63
|
const endpoint = datacenterId ? 'validate_name_datacenter' : 'validate_name'
|
|
57
64
|
return `/ui/object/${endpoint}?${params.toString()}`
|
|
58
65
|
}
|