Я создал функцию в сервисе, используя nodejs для установки логической переменной в true при нажатии кнопки. Но это не работает.
Я использую метод get в сервисе, чтобы сделать выше.
// в html
<tr *ngFor="let status of bookstatus">
<td>{{status.bookname}}</td>
<td>{{status.issuedate | date:'dd/MM/yyyy'}}</td>
<td>{{status.returndate}}</td>
<td>{{status.membername}}</td>
<td>{{status.fine}}</td>
<td>{{status.status}}</td>
<td><button type="button" (click)="returnbook(status._id)">BookReturn</button></td>
</tr>
// в тс
returnbook(id: number) {
this.bookissueservice.returnbook(id).subscribe(response => {window.alert('book returned'); });
if (this.bookstatus.isreturned === true) {
this.bookstatus.status = 'returned';
var date1 = new Date(this.bookreturn);
var date2 = new Date(this.bookstatus.returndate);
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
if (diffDays !== 0) {
const res = 50;
this.fine = res + diffDays;
}
else {this.fine = 0; }
}
}
// в обслуживании
returnbook(id:number){
return this.http.get(`http://localhost:4000/api/memberdetails/${id}`).
pipe(map(response=>response));
}
// в API
router.get('/return/:id?',(req,res)=>{
var body=req.params.id;
var id=body.id;
bookissue.findById(id,(error,bookissue)=>{if(error){
console.log(error);}
/*bookissue.isreturned is the boolean variable which I'm trying to set to true on button click */
bookissue.isreturned = 1;
bookissue.save(function(error,returned){
if(error){
console.log(error);
return next(error);
}
res.json({status:true,message:'saved',data:returned});
});
});
});