import { OnInit , Component } from '@angular/core' ; import { TranslationBaseComponent } from '../language-base/translation-base.component' ; import { FormGroup , FormBuilder , Validators } from '@angular/forms' ; import { IEquipmentSharingPolicy , IOrganization } from '@gauzy/contracts' ; import { NbDialogRef } from '@nebular/theme' ; import { TranslateService } from '@ngx-translate/core' ; import { EquipmentSharingPolicyService } from '../../@core/services/equipment-sharing-policy.service' ; @ Component ( { selector : 'ngx-equipment-sharing-policy-mutation' , templateUrl : './equipment-sharing-policy-mutation.component.html' } ) export class EquipmentSharingPolicyMutationComponent extends TranslationBaseComponent implements OnInit { form : FormGroup ; equipmentSharingPolicy : IEquipmentSharingPolicy ; isHasType = true ; selectedOrganization : IOrganization ; constructor ( public dialogRef , private equipmentSharingPolicyService , private fb , readonly translationService ) { super ( translationService ) ; } ngOnInit ( ) { this . initializeForm ( ) ; } async initializeForm ( ) { this . form = this . fb . group ( { name : [ this . equipmentSharingPolicy ? this . equipmentSharingPolicy . name : '' , Validators . required ] , description : [ this . equipmentSharingPolicy ? this . equipmentSharingPolicy . description : '' ] , organizationId : [ this . equipmentSharingPolicy ? this . equipmentSharingPolicy . organizationId : '' ] , id : [ this . equipmentSharingPolicy ? this . equipmentSharingPolicy . id : null ] } ) ; } async closeDialog ( requipmentSharingPolicy ? ) { this . dialogRef . close ( requipmentSharingPolicy ) ; } async saveEquipmentSharingPolicy ( ) { const { id : organizationId , tenantId } = this . selectedOrganization ; const equipPolicy = { name : this . form . value [ 'name' ] , description : this . form . value [ 'description' ] , id : this . form . value [ 'id' ] , organizationId , tenantId } ; let result ; result = await this . equipmentSharingPolicyService . save ( equipPolicy ) ; this . closeDialog ( result ) ; } }