Skip to content

Agreement

AgreementService Usage Guide

This document provides instructions on how to use the AgreementService in an Angular application to manage Agreement entities.

Setup

How to install

npm install @dnext-angular/agreement

Step 1: Import Required Modules

Ensure that you have imported the necessary modules in your Angular application.

import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { AgreementService } from './services/agreement.service';
import { AuthorizationService, HttpHelperService } from '@dnext-angular/http';

@NgModule({
  imports: [
    HttpClientModule,
    // other imports
  ],
  providers: [
    AgreementService,
    AuthorizationService,
    HttpHelperService,
    // other providers
  ],
})
export class AppModule { }

Step 2: Inject AgreementService in a Component

Inject the AgreementService into a component where you want to manage agreements.

import { Component, OnInit } from '@angular/core';
import { AgreementService } from './services/agreement.service';
import { AgreementCreate, AgreementUpdate, Agreement } from './model/agreement';

@Component({
  selector: 'app-agreement',
  templateUrl: './agreement.component.html',
  styleUrls: ['./agreement.component.css']
})
export class AgreementComponent implements OnInit {

  constructor(private agreementService: AgreementService) { }

  ngOnInit(): void {
    this.createAgreement();
    this.retrieveAgreement('1');
    this.listAgreements();
    this.updateAgreement('1');
    this.deleteAgreement('1');
  }

  createAgreement(): void {
    const newAgreement: AgreementCreate = { /* initialize with appropriate values */ };
    this.agreementService.createAgreement(newAgreement).subscribe(
      (agreement: Agreement) => {
        console.log('Agreement created:', agreement);
      },
      (error) => {
        console.error('Error creating agreement:', error);
      }
    );
  }

  retrieveAgreement(id: string): void {
    this.agreementService.retrieveAgreement(id).subscribe(
      (agreement: Agreement) => {
        console.log('Agreement retrieved:', agreement);
      },
      (error) => {
        console.error('Error retrieving agreement:', error);
      }
    );
  }

  listAgreements(): void {
    this.agreementService.listAgreement().subscribe(
      (agreements: Agreement[]) => {
        console.log('Agreements list:', agreements);
      },
      (error) => {
        console.error('Error listing agreements:', error);
      }
    );
  }

  updateAgreement(id: string): void {
    const updatedAgreement: AgreementUpdate = { /* initialize with appropriate values */ };
    this.agreementService.patchAgreement(id, updatedAgreement).subscribe(
      (agreement: Agreement) => {
        console.log('Agreement updated:', agreement);
      },
      (error) => {
        console.error('Error updating agreement:', error);
      }
    );
  }

  deleteAgreement(id: string): void {
    this.agreementService.deleteAgreement(id).subscribe(
      () => {
        console.log('Agreement deleted');
      },
      (error) => {
        console.error('Error deleting agreement:', error);
      }
    );
  }
}

Step 3: Create HTML Template

Create an HTML template to interact with the component.

<!-- agreement.component.html -->
<div>
  <h1>Agreement Management</h1>
  <button (click)="createAgreement()">Create Agreement</button>
  <button (click)="retrieveAgreement('1')">Retrieve Agreement</button>
  <button (click)="listAgreements()">List Agreements</button>
  <button (click)="updateAgreement('1')">Update Agreement</button>
  <button (click)="deleteAgreement('1')">Delete Agreement</button>
</div>

Methods Overview

createAgreement

  • Creates a new Agreement entity.
createAgreement(agreement: AgreementCreate, observe?: 'body', reportProgress?: boolean): Observable<Agreement>;

deleteAgreement

  • Deletes an existing Agreement entity by ID.
deleteAgreement(id: string, observe?: 'body', reportProgress?: boolean): Observable<any>;

listAgreement

  • Lists all Agreement entities with optional query parameters.
listAgreement(fields?: string, offset?: number, limit?: number, observe?: 'body', reportProgress?: boolean): Observable<Array<Agreement>>;

patchAgreement

  • Updates an existing Agreement entity by ID.
patchAgreement(id: string, agreement: AgreementUpdate, observe?: 'body', reportProgress?: boolean): Observable<Agreement>;

retrieveAgreement

  • Retrieves a specific Agreement entity by ID.
retrieveAgreement(id: string, fields?: string, observe?: 'body', reportProgress?: boolean): Observable<Agreement>;