1

In my Angular app, I have a Job object & an Offer object.

Here are my Interfaces:

export interface IJob {
  id: number;
  title: string;
  description: string;
  employeeId?: number;
  managerId: string;
  imageUrl: string;
}

export interface IOffer {
  id: number;
  managerId: number;
  jobId: number;
  employeeId: number;
}

I'm displaying all the Job details like so:

<table">
    <thead>
        <tr>
            <th scope="col">Title</th>
            <th scope="col">Description</th>
            <th scope="col">Employee ID</th>
            <th scope="col">Manager ID</th>
            <th scope="col">Action</th>
        </tr>
    </thead>
    <tbody>
        <tr *ngFor="let job of jobs">
            <td>{{ job.title }}</td>
            <td>{{job.description}}</td>
            <td>{{job.employeeId}}</td>
            <td>{{job.managerId}}</td>
            <td>
                <button (click)="applyForJob(job)">Apply Now</button>
            </td>
        </tr>
    </tbody>
</table>

I want to use this applyForJob(job) method to create an Offer object for the associated job.

I have this method in my Offer Service at the moment, if that helps:

addOffer(offer: IOffer): Observable<IOffer> {
    return this.httpClient.post<IOffer>(this.baseUrl, offer, {
      headers: new HttpHeaders({
        'Content-Type': 'application/json'
      })
    })
      .pipe(catchError(this.handleError));
  }

Can someone please tell me how I can create an offer for a specific job with the above code?

0

1 Answer 1

1

You can do it as follows.

applyForJob(job) {

     let offer = new IOffer();
     offer.id = job.id; // use unique id for this
     offer.managerId = job.managerId;
     offer.jobId = job.id;
     offer.employeeId = job.employeeId;

     myOfficeService.addOffer(offer).subscribe((res: any) => {
        console.log(res);
     });

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.