Skip to content

Commit

Permalink
usersLiaisons --> usersApprovers
Browse files Browse the repository at this point in the history
  • Loading branch information
lucia-gomez committed Oct 24, 2024
1 parent c184f90 commit 16e54f8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
26 changes: 26 additions & 0 deletions booking-app/app/api/db/route.ts
Original file line number Diff line number Diff line change
@@ -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 },
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Box, Button, Typography } from "@mui/material";
import React, { useState } from "react";

import AlertToast from "../../components/AlertToast";

const SyncCalendars = () => {
Expand Down Expand Up @@ -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 (
<Box>
<Typography variant="h6">
Expand All @@ -47,6 +60,7 @@ const SyncCalendars = () => {
Sync Calendar Events
</Button>
</Box>
<Button onClick={duplicate}>Duplicate</Button>
<AlertToast
message={message}
severity={alertSeverity}
Expand Down
2 changes: 1 addition & 1 deletion booking-app/components/src/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const ACTIVE_SHEET_ID = "1MnWbn6bvNyMiawddtYYx0tRW4NMgvugl0I8zBO3sy68";

export enum TableNames {
ADMINS = "usersAdmin",
APPROVERS = "usersLiaison",
APPROVERS = "usersApprovers",
BANNED = "usersBanned",
BOOKING = "bookings",
BOOKING_STATUS = "bookingStatus",
Expand Down

0 comments on commit 16e54f8

Please sign in to comment.