From 16e54f8f7c4045e3f39cac7028146718edb2a902 Mon Sep 17 00:00:00 2001 From: lucia <51058748+lucia-gomez@users.noreply.github.com> Date: Fri, 11 Oct 2024 17:45:05 -0400 Subject: [PATCH] usersLiaisons --> usersApprovers --- booking-app/app/api/db/route.ts | 26 +++++++++++++++++++ .../routes/admin/components/SyncCalendars.tsx | 14 ++++++++++ booking-app/components/src/policy.ts | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 booking-app/app/api/db/route.ts diff --git a/booking-app/app/api/db/route.ts b/booking-app/app/api/db/route.ts new file mode 100644 index 00000000..8df87a75 --- /dev/null +++ b/booking-app/app/api/db/route.ts @@ -0,0 +1,26 @@ +import { NextRequest, NextResponse } from "next/server"; +import { + serverFetchAllDataFromCollection, + serverSaveDataToFirestore, +} from "@/lib/firebase/server/adminDb"; + +import { TableNames } from "@/components/src/policy"; + +export async function POST(request: NextRequest) { + const { newCollection } = await request.json(); + console.log(newCollection); + + try { + const rows = await serverFetchAllDataFromCollection(TableNames.APPROVERS); + await Promise.all( + rows.map(row => serverSaveDataToFirestore(newCollection, row)), + ); + return NextResponse.json({ duplicatedRows: rows.length }, { status: 200 }); + } catch (err) { + console.error(err); + return NextResponse.json( + { error: "Failed to duplicate events to new collection" }, + { status: 500 }, + ); + } +} diff --git a/booking-app/components/src/client/routes/admin/components/SyncCalendars.tsx b/booking-app/components/src/client/routes/admin/components/SyncCalendars.tsx index 6f8d6def..f44040f1 100644 --- a/booking-app/components/src/client/routes/admin/components/SyncCalendars.tsx +++ b/booking-app/components/src/client/routes/admin/components/SyncCalendars.tsx @@ -1,5 +1,6 @@ import { Box, Button, Typography } from "@mui/material"; import React, { useState } from "react"; + import AlertToast from "../../components/AlertToast"; const SyncCalendars = () => { @@ -32,6 +33,18 @@ const SyncCalendars = () => { } }; + const duplicate = async () => { + await fetch("/api/db", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + newCollection: "usersApprovers", + }), + }); + }; + return ( @@ -47,6 +60,7 @@ const SyncCalendars = () => { Sync Calendar Events +