new fn: delete all availabilities
This commit is contained in:
@ -67,8 +67,8 @@ export default async function handler(req, res) {
|
|||||||
await prisma.availability.deleteMany({
|
await prisma.availability.deleteMany({
|
||||||
where: filter ? {
|
where: filter ? {
|
||||||
OR: [
|
OR: [
|
||||||
{ firstName: { contains: filter } },
|
// { name: { contains: filter } },
|
||||||
{ lastName: { contains: filter } }
|
{ starTime: { lte: date } }
|
||||||
]
|
]
|
||||||
} : {}
|
} : {}
|
||||||
});
|
});
|
||||||
@ -212,7 +212,9 @@ export default async function handler(req, res) {
|
|||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
res.status(200).json({ "message": "no action" });
|
res.status(200).json({
|
||||||
|
"message": "no action '" + action + "' found"
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -455,16 +457,12 @@ export async function filterPublishers(selectFields, searchText, filterDate, fet
|
|||||||
OR: [
|
OR: [
|
||||||
// Check only by date without considering time ( Assignments on specific days without time)
|
// Check only by date without considering time ( Assignments on specific days without time)
|
||||||
{
|
{
|
||||||
//AND: [{ startTime: { gte: filterDate } }, { startTime: { lte: filterDateEnd } }]
|
|
||||||
//dayOfMonth: filterDate.getDate(),
|
|
||||||
startTime: { gte: filterDate },
|
startTime: { gte: filterDate },
|
||||||
endTime: { lte: filterDateEnd },
|
endTime: { lte: filterDateEnd },
|
||||||
// //dayofweek: dayOfWeekEnum,
|
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
// Check if dayOfMonth is null and match by day of week using the enum (Assigments every week)
|
// Check if dayOfMonth is null and match by day of week using the enum (Assigments every week)
|
||||||
// This includes availabilities from previous assignments but not with preference
|
// This includes availabilities from previous assignments but not with preference
|
||||||
|
|
||||||
{
|
{
|
||||||
dayOfMonth: null,
|
dayOfMonth: null,
|
||||||
dayofweek: dayOfWeekEnum,
|
dayofweek: dayOfWeekEnum,
|
||||||
|
@ -46,7 +46,21 @@ function PublishersPage({ publishers = [] }: IProps) {
|
|||||||
|
|
||||||
setIsDeleting(false);
|
setIsDeleting(false);
|
||||||
setIsModalOpen(false);
|
setIsModalOpen(false);
|
||||||
// After all publishers are deleted, you might want to refresh the list or make additional changes
|
};
|
||||||
|
|
||||||
|
const handleDeleteAllAvailabilities = async () => {
|
||||||
|
setIsDeleting(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const today = new Date();
|
||||||
|
const targetDate = new Date(today.setDate(today.getDate() - 35));
|
||||||
|
await axiosInstance.post('/api/?action=deleteAllAvailabilities', { date: targetDate });
|
||||||
|
} catch (error) {
|
||||||
|
console.error(JSON.stringify(error)); // Log the error
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsDeleting(false);
|
||||||
|
setIsModalOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -164,6 +178,15 @@ function PublishersPage({ publishers = [] }: IProps) {
|
|||||||
onConfirm={handleDeleteAllVisible}
|
onConfirm={handleDeleteAllVisible}
|
||||||
message="Сигурни ли сте, че искате да изтриете всички показани в момента вестители?"
|
message="Сигурни ли сте, че искате да изтриете всички показани в момента вестители?"
|
||||||
/>
|
/>
|
||||||
|
<button className="button m-2 btn btn-danger" onClick={() => setIsModalOpen(true)} disabled={isDeleting} >
|
||||||
|
{isDeleting ? "Изтриване..." : "Изтрий ВСИЧКИ предпочитания"}
|
||||||
|
</button>
|
||||||
|
<ConfirmationModal
|
||||||
|
isOpen={isModalOpen}
|
||||||
|
onClose={() => setIsModalOpen(false)}
|
||||||
|
onConfirm={handleDeleteAllAvailabilities}
|
||||||
|
message="Сигурни ли сте, че искате да изтриете предпочитанията на ВСИЧКИ вестители?"
|
||||||
|
/>
|
||||||
<div className="flex justify-center m-4">
|
<div className="flex justify-center m-4">
|
||||||
<a href="/cart/publishers/import" className="btn"> Import publishers </a>
|
<a href="/cart/publishers/import" className="btn"> Import publishers </a>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user