From 6043df6ad1f3b0f84c2aa46d79f84aad03369ce3 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Mon, 4 Mar 2024 00:20:13 +0200 Subject: [PATCH] new fn: delete all availabilities --- pages/api/index.ts | 12 +++++------- pages/cart/publishers/index.tsx | 25 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/pages/api/index.ts b/pages/api/index.ts index db4f3fc..563bda8 100644 --- a/pages/api/index.ts +++ b/pages/api/index.ts @@ -67,8 +67,8 @@ export default async function handler(req, res) { await prisma.availability.deleteMany({ where: filter ? { OR: [ - { firstName: { contains: filter } }, - { lastName: { contains: filter } } + // { name: { contains: filter } }, + { starTime: { lte: date } } ] } : {} }); @@ -212,7 +212,9 @@ export default async function handler(req, res) { default: - res.status(200).json({ "message": "no action" }); + res.status(200).json({ + "message": "no action '" + action + "' found" + }); break; } } catch (error) { @@ -455,16 +457,12 @@ export async function filterPublishers(selectFields, searchText, filterDate, fet OR: [ // 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 }, endTime: { lte: filterDateEnd }, - // //dayofweek: dayOfWeekEnum, } , // 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 - { dayOfMonth: null, dayofweek: dayOfWeekEnum, diff --git a/pages/cart/publishers/index.tsx b/pages/cart/publishers/index.tsx index 8bc1055..40bc324 100644 --- a/pages/cart/publishers/index.tsx +++ b/pages/cart/publishers/index.tsx @@ -46,7 +46,21 @@ function PublishersPage({ publishers = [] }: IProps) { setIsDeleting(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(() => { @@ -164,6 +178,15 @@ function PublishersPage({ publishers = [] }: IProps) { onConfirm={handleDeleteAllVisible} message="Сигурни ли сте, че искате да изтриете всички показани в момента вестители?" /> + + setIsModalOpen(false)} + onConfirm={handleDeleteAllAvailabilities} + message="Сигурни ли сте, че искате да изтриете предпочитанията на ВСИЧКИ вестители?" + />
Import publishers