make editable description template type code

This commit is contained in:
CITE\amentis 2024-07-31 10:42:21 +03:00
parent 12bfa519ca
commit 7980579dec
3 changed files with 7 additions and 7 deletions

View File

@ -103,8 +103,6 @@ public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTy
data = this.entityManager.find(DescriptionTemplateTypeEntity.class, model.getId());
if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DescriptionTemplateType.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
if (!data.getCode().equals(model.getCode()))
throw new MyForbiddenException("Code can not change");
} else {
this.usageLimitService.checkIncrease(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_TYPE_COUNT);
data = new DescriptionTemplateTypeEntity();
@ -118,10 +116,12 @@ public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTy
data.setStatus(model.getStatus());
data.setUpdatedAt(Instant.now());
Long descriptionTemplateTypeCodes = this.queryFactory.query(DescriptionTemplateTypeQuery.class).disableTracking().codes(model.getCode()).count();
if (isUpdate) {
if (descriptionTemplateTypeCodes > 1) throw new MyValidationException(this.errors.getDescriptionTemplateTypeCodeExists().getCode(), this.errors.getDescriptionTemplateTypeCodeExists().getMessage());
this.entityManager.merge(data);
} else {
Long descriptionTemplateTypeCodes = this.queryFactory.query(DescriptionTemplateTypeQuery.class).disableTracking().codes(model.getCode()).count();
if (descriptionTemplateTypeCodes > 0) throw new MyValidationException(this.errors.getDescriptionTemplateTypeCodeExists().getCode(), this.errors.getDescriptionTemplateTypeCodeExists().getMessage());
this.entityManager.persist(data);
this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_TYPE_COUNT.getValue());

View File

@ -118,7 +118,7 @@ export class DescriptionTemplateTypeEditorComponent extends BaseEditor<Descripti
}
buildForm() {
this.formGroup = this.editorModel.buildForm(null, this.isDeleted || !this.authService.hasPermission(AppPermission.EditDescriptionTemplateType), this.isNew);
this.formGroup = this.editorModel.buildForm(null, this.isDeleted || !this.authService.hasPermission(AppPermission.EditDescriptionTemplateType));
this.descriptionTemplateTypeEditorService.setValidationErrorModel(this.editorModel.validationErrorModel);
if (this.isFinalized) {
@ -137,7 +137,7 @@ export class DescriptionTemplateTypeEditorComponent extends BaseEditor<Descripti
}
persistEntity(onSuccess?: (response) => void): void {
const formData = this.formGroup.getRawValue() as DescriptionTemplateTypePersist;
const formData = this.formService.getValue(this.formGroup.value) as DescriptionTemplateTypePersist;
this.descriptionTemplateTypeService.persist(formData)
.pipe(takeUntil(this._destroyed)).subscribe(

View File

@ -32,13 +32,13 @@ export class DescriptionTemplateTypeEditorModel extends BaseEditorModel implemen
return this;
}
buildForm(context: ValidationContext = null, disabled: boolean = false, isNew: boolean = false): UntypedFormGroup {
buildForm(context: ValidationContext = null, disabled: boolean = false): UntypedFormGroup {
if (context == null) { context = this.createValidationContext(); }
return this.formBuilder.group({
id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators],
name: [{ value: this.name, disabled: disabled }, context.getValidation('name').validators],
code: [{ value: this.code, disabled: !isNew }, context.getValidation('code').validators],
code: [{ value: this.code, disabled: disabled }, context.getValidation('code').validators],
status: [{ value: this.status, disabled: disabled }, context.getValidation('status').validators],
hash: [{ value: this.hash, disabled: disabled }, context.getValidation('hash').validators]
});