-
Notifications
You must be signed in to change notification settings - Fork 7
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
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
- Fetch data from their data source (could API, DB or any other source)
- Transform the data to the specific interface's properties, and return the transformed data
@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;
})
);
}
}