Skip to content

Adapter Interfaces

Ashwin Date edited this page Apr 1, 2022 · 2 revisions

The adapter interfaces allow any deployer to implement logic to connect to the backend of their choice. The adapters are essentially a services layer, and the deployer is expected to implement

Below is an example of the Attendance Adapter Interface

interface IAttendance {
    attendanceId: string;
    schoolId: string;
    userId: string;
    groupId: string;
    topicId: string;
    eventId: string;
    date: datetime;
    attendance: string;
    remark: string;
    approved: string;
    approvedBy: string;
}

The deployer will implement the interface, and write code within to

  1. Fetch data from their data source (could API, DB or any other source)
  2. Transform the data to the specific interface's properties, and return the transformed data

Below is an example implementation of the Attendance adapter

@Injectable()
export class AttendanceService {
  private attendance: AttendanceInterface;

  constructor(private httpService: HttpService) {}

  read(id: any): Observable<AttendanceInterface> {
    return this.httpService
      .get(
        process.env.BASEAPIURL+"Attendance/"+id
      )
      .pipe(
        map((axiosResponse: AxiosResponse) => {
          this.student = {
            attendanceId: id,
            userId: axiosResponse.data.student_id,
            groupId: axiosResponse.data.class_id,
            schoolId: axiosResponse.data.school_id,
            attendance: axiosResponse.data.present ? 'Present' : 'Absent',
            date: axiosResponse.data.date
          };
          return this.student;
        })
      );
  }
}
Clone this wiki locally