Skip to content

Commit e6130d8

Browse files
committed
pass selected cultures to validation end points
1 parent 9ce1564 commit e6130d8

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/packages/documents/documents/repository/validation/document-validation.server.data-source.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import type { UmbDocumentDetailModel } from '../../types.js';
22
import {
33
type CreateDocumentRequestModel,
44
DocumentService,
5-
type UpdateDocumentRequestModel,
5+
type ValidateUpdateDocumentRequestModel,
66
} from '@umbraco-cms/backoffice/external/backend-api';
77
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
88
import { tryExecute } from '@umbraco-cms/backoffice/resources';
9+
import type { UmbVariantId } from '@umbraco-cms/backoffice/variant';
910

1011
/**
1112
* A server data source for Document Validation
@@ -32,18 +33,27 @@ export class UmbDocumentValidationServerDataSource {
3233
* @param parentUnique
3334
* @returns {*}
3435
*/
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+
) {
3641
if (!model) throw new Error('Document is missing');
3742
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);
3847

3948
// TODO: make data mapper to prevent errors
40-
const requestBody: CreateDocumentRequestModel = {
49+
const requestBody: ValidateCreateDocumentRequestModel = {
4150
id: model.unique,
4251
parent: parentUnique ? { id: parentUnique } : null,
4352
documentType: { id: model.documentType.unique },
4453
template: model.template ? { id: model.template.unique } : null,
4554
values: model.values,
4655
variants: model.variants,
56+
cultures,
4757
};
4858

4959
// Maybe use: tryExecuteAndNotify
@@ -60,20 +70,23 @@ export class UmbDocumentValidationServerDataSource {
6070
* @param {UmbDocumentDetailModel} model - Document Model
6171
* @returns {*}
6272
*/
63-
async validateUpdate(model: UmbDocumentDetailModel) {
73+
async validateUpdate(model: UmbDocumentDetailModel, variantIds: Array<UmbVariantId>) {
6474
if (!model.unique) throw new Error('Unique is missing');
6575

76+
const cultures = variantIds.map((id) => id.culture).filter((culture) => culture !== null);
77+
6678
// TODO: make data mapper to prevent errors
67-
const requestBody: UpdateDocumentRequestModel = {
79+
const requestBody: ValidateUpdateDocumentRequestModel = {
6880
template: model.template ? { id: model.template.unique } : null,
6981
values: model.values,
7082
variants: model.variants,
83+
cultures,
7184
};
7285

7386
// Maybe use: tryExecuteAndNotify
7487
return tryExecute(
7588
//this.#host,
76-
DocumentService.putDocumentByIdValidate({
89+
DocumentService.putUmbracoManagementApiV11DocumentByIdValidate11({
7790
id: model.unique,
7891
requestBody,
7992
}),

0 commit comments

Comments
 (0)