I want to write an appwrite function that will update my isDue and isOverdue when repaymentDate is the current date and overdue when repayment date is overdue. export default async ({ req, res, log, error }) => {
if (req.method === 'PUT') { const updateDueInAppwrite = async (loanId) => { try{ const response = await db.updateDocument(FASTDB, LOANDATA, loanId, { isDue: true, });
console.log('Document updated successfully', response);
} catch (error) {
console.error('Error updating document:', error);
}
};
const updateDaysOverdueInAppwrite = async (loanId, days) => {
try {
const response = await db.updateDocument(
FASTDB, LOANDATA,
loanId,
{
isOverdue: true,
daysOverdue: days,
}
);
console.log('Document updated successfully', response);
log();
} catch (error) {
console.error('Error updating document:', error);
error()
}
};
const checkLoanStatus = async () => {
response.documents.forEach(async (loan) => {
const currentDate = new Date();
const repaymentDate = new Date(loan.repaymentDate)
if (repaymentDate < currentDate) {
const differenceInTime =
currentDate.getTime() - repaymentDate.getTime();
const differenceInDays = Math.ceil(
differenceInTime / (1000 * 3600 * 24)
) updateDaysOverdueInAppwrite(
loan.$id.toString(),
differenceInDays
);
} else if (repaymentDate.getTime() === currentDate.getTime()) {
// If repayment date is equal to current date
console.log(`Loan ID: ${loan.$id} is due today`);
log(Loan ID: ${loan.$id} is due today);
await updateDueInAppwrite(loan.$id.toString());
}
});
};
checkLoanStatus();
} return res.empty(); };
But this function is not updating my isDue and isOverdue in my appwrite
Recommended threads
- Go 1.25 runtime
So I'm trying to use go 1.25 for my functions and I can only find go-1.23 as a function runtime. So I did some searching and found https://github.com/appwrite/a...
- Python TablesDB Rework
Hi, i starting to rework some older functions to TablesDB list_rows Method. I used list_documents with a resultset with worked fine. Now i tried to get all rows...
- HUGE OUTRAGE IN APPWRITE, I CANNOT ACCES...
I have 2k users trying to access, sending me messages. What am I supposed to do? Please solve this asap.