@@ -2,10 +2,11 @@ import type { UmbDocumentDetailModel } from '../../types.js';
2
2
import {
3
3
type CreateDocumentRequestModel ,
4
4
DocumentService ,
5
- type UpdateDocumentRequestModel ,
5
+ type ValidateUpdateDocumentRequestModel ,
6
6
} from '@umbraco-cms/backoffice/external/backend-api' ;
7
7
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api' ;
8
8
import { tryExecute } from '@umbraco-cms/backoffice/resources' ;
9
+ import type { UmbVariantId } from '@umbraco-cms/backoffice/variant' ;
9
10
10
11
/**
11
12
* A server data source for Document Validation
@@ -32,18 +33,27 @@ export class UmbDocumentValidationServerDataSource {
32
33
* @param parentUnique
33
34
* @returns {* }
34
35
*/
35
- async validateCreate ( model : UmbDocumentDetailModel , parentUnique : string | null = null ) {
36
+ async validateCreate (
37
+ model : UmbDocumentDetailModel ,
38
+ parentUnique : string | null = null ,
39
+ variantIds : Array < UmbVariantId > ,
40
+ ) {
36
41
if ( ! model ) throw new Error ( 'Document is missing' ) ;
37
42
if ( ! model . unique ) throw new Error ( 'Document unique is missing' ) ;
43
+ if ( parentUnique === undefined ) throw new Error ( 'Parent unique is missing' ) ;
44
+ if ( ! variantIds ) throw new Error ( 'Variant ids are missing' ) ;
45
+
46
+ const cultures = variantIds . map ( ( id ) => id . culture ) . filter ( ( culture ) => culture !== null ) ;
38
47
39
48
// TODO: make data mapper to prevent errors
40
- const requestBody : CreateDocumentRequestModel = {
49
+ const requestBody : ValidateCreateDocumentRequestModel = {
41
50
id : model . unique ,
42
51
parent : parentUnique ? { id : parentUnique } : null ,
43
52
documentType : { id : model . documentType . unique } ,
44
53
template : model . template ? { id : model . template . unique } : null ,
45
54
values : model . values ,
46
55
variants : model . variants ,
56
+ cultures,
47
57
} ;
48
58
49
59
// Maybe use: tryExecuteAndNotify
@@ -60,20 +70,23 @@ export class UmbDocumentValidationServerDataSource {
60
70
* @param {UmbDocumentDetailModel } model - Document Model
61
71
* @returns {* }
62
72
*/
63
- async validateUpdate ( model : UmbDocumentDetailModel ) {
73
+ async validateUpdate ( model : UmbDocumentDetailModel , variantIds : Array < UmbVariantId > ) {
64
74
if ( ! model . unique ) throw new Error ( 'Unique is missing' ) ;
65
75
76
+ const cultures = variantIds . map ( ( id ) => id . culture ) . filter ( ( culture ) => culture !== null ) ;
77
+
66
78
// TODO: make data mapper to prevent errors
67
- const requestBody : UpdateDocumentRequestModel = {
79
+ const requestBody : ValidateUpdateDocumentRequestModel = {
68
80
template : model . template ? { id : model . template . unique } : null ,
69
81
values : model . values ,
70
82
variants : model . variants ,
83
+ cultures,
71
84
} ;
72
85
73
86
// Maybe use: tryExecuteAndNotify
74
87
return tryExecute (
75
88
//this.#host,
76
- DocumentService . putDocumentByIdValidate ( {
89
+ DocumentService . putUmbracoManagementApiV11DocumentByIdValidate11 ( {
77
90
id : model . unique ,
78
91
requestBody,
79
92
} ) ,
0 commit comments