Merge branch 'main' into v15/bugfix/create-dataset-again
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -2804,6 +2804,13 @@ export type UserTwoFactorProviderModel = {
|
||||
isEnabledOnUser: boolean;
|
||||
};
|
||||
|
||||
export type ValidateUpdateDocumentRequestModel = {
|
||||
values: Array<(DocumentValueModel)>;
|
||||
variants: Array<(DocumentVariantRequestModel)>;
|
||||
template?: ((ReferenceByIdModel) | null);
|
||||
cultures?: Array<(string)> | null;
|
||||
};
|
||||
|
||||
export type VariantItemResponseModel = {
|
||||
name: string;
|
||||
culture?: (string) | null;
|
||||
@@ -3512,6 +3519,13 @@ export type PutDocumentByIdValidateData = {
|
||||
|
||||
export type PutDocumentByIdValidateResponse = (string);
|
||||
|
||||
export type PutUmbracoManagementApiV11DocumentByIdValidate11Data = {
|
||||
id: string;
|
||||
requestBody?: (ValidateUpdateDocumentRequestModel);
|
||||
};
|
||||
|
||||
export type PutUmbracoManagementApiV11DocumentByIdValidate11Response = (string);
|
||||
|
||||
export type GetDocumentAreReferencedData = {
|
||||
id?: Array<(string)>;
|
||||
skip?: number;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { UmbDocumentDetailModel } from '../../types.js';
|
||||
import { UmbDocumentValidationServerDataSource } from './document-validation.server.data-source.js';
|
||||
import type { UmbVariantId } from '@umbraco-cms/backoffice/variant';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
@@ -30,14 +31,15 @@ export class UmbDocumentValidationRepository extends UmbRepositoryBase {
|
||||
/**
|
||||
* Saves the given data
|
||||
* @param {DetailModelType} model
|
||||
* @param variantIds
|
||||
* @returns {*}
|
||||
* @memberof UmbDetailRepositoryBase
|
||||
*/
|
||||
async validateSave(model: DetailModelType) {
|
||||
async validateSave(model: DetailModelType, variantIds: Array<UmbVariantId>) {
|
||||
if (!model) throw new Error('Data is missing');
|
||||
if (!model.unique) throw new Error('Unique is missing');
|
||||
|
||||
return this.#validationDataSource.validateUpdate(model);
|
||||
return this.#validationDataSource.validateUpdate(model, variantIds);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,12 @@ import type { UmbDocumentDetailModel } from '../../types.js';
|
||||
import {
|
||||
type CreateDocumentRequestModel,
|
||||
DocumentService,
|
||||
type UpdateDocumentRequestModel,
|
||||
type ValidateUpdateDocumentRequestModel,
|
||||
} from '@umbraco-cms/backoffice/external/backend-api';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { tryExecute } from '@umbraco-cms/backoffice/resources';
|
||||
import type { UmbVariantId } from '@umbraco-cms/backoffice/variant';
|
||||
import type { UmbEntityUnique } from '@umbraco-cms/backoffice/entity';
|
||||
|
||||
/**
|
||||
* A server data source for Document Validation
|
||||
@@ -29,12 +31,13 @@ export class UmbDocumentValidationServerDataSource {
|
||||
/**
|
||||
* Validate a new Document on the server
|
||||
* @param {UmbDocumentDetailModel} model - Document Model
|
||||
* @param parentUnique
|
||||
* @param parentUnique - Parent Unique
|
||||
* @returns {*}
|
||||
*/
|
||||
async validateCreate(model: UmbDocumentDetailModel, parentUnique: string | null = null) {
|
||||
async validateCreate(model: UmbDocumentDetailModel, parentUnique: UmbEntityUnique = null) {
|
||||
if (!model) throw new Error('Document is missing');
|
||||
if (!model.unique) throw new Error('Document unique is missing');
|
||||
if (parentUnique === undefined) throw new Error('Parent unique is missing');
|
||||
|
||||
// TODO: make data mapper to prevent errors
|
||||
const requestBody: CreateDocumentRequestModel = {
|
||||
@@ -58,22 +61,26 @@ export class UmbDocumentValidationServerDataSource {
|
||||
/**
|
||||
* Validate a existing Document
|
||||
* @param {UmbDocumentDetailModel} model - Document Model
|
||||
* @param {Array<UmbVariantId>} variantIds - Variant Ids
|
||||
* @returns {*}
|
||||
*/
|
||||
async validateUpdate(model: UmbDocumentDetailModel) {
|
||||
async validateUpdate(model: UmbDocumentDetailModel, variantIds: Array<UmbVariantId>) {
|
||||
if (!model.unique) throw new Error('Unique is missing');
|
||||
|
||||
const cultures = variantIds.map((id) => id.culture).filter((culture) => culture !== null) as Array<string>;
|
||||
|
||||
// TODO: make data mapper to prevent errors
|
||||
const requestBody: UpdateDocumentRequestModel = {
|
||||
const requestBody: ValidateUpdateDocumentRequestModel = {
|
||||
template: model.template ? { id: model.template.unique } : null,
|
||||
values: model.values,
|
||||
variants: model.variants,
|
||||
cultures,
|
||||
};
|
||||
|
||||
// Maybe use: tryExecuteAndNotify
|
||||
return tryExecute(
|
||||
//this.#host,
|
||||
DocumentService.putDocumentByIdValidate({
|
||||
DocumentService.putUmbracoManagementApiV11DocumentByIdValidate11({
|
||||
id: model.unique,
|
||||
requestBody,
|
||||
}),
|
||||
|
||||
@@ -647,7 +647,10 @@ export class UmbDocumentWorkspaceContext
|
||||
this.#validationRepository.validateCreate(saveData, parent.unique),
|
||||
);
|
||||
} else {
|
||||
this.#serverValidation.askServerForValidation(saveData, this.#validationRepository.validateSave(saveData));
|
||||
this.#serverValidation.askServerForValidation(
|
||||
saveData,
|
||||
this.#validationRepository.validateSave(saveData, variantIds),
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Only validate the specified selection.. [NL]
|
||||
|
||||
Reference in New Issue
Block a user