-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ec1158
commit e9a47f3
Showing
3 changed files
with
53 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import { DocumentData, collection, getDocs } from "firebase/firestore"; | ||
import db from "../../firebase/firestore"; | ||
|
||
type Data = { | ||
status: string; | ||
data?: SmartShareData[]; | ||
}; | ||
type SmartShareData = { | ||
url: string; | ||
time: number; | ||
name: string; | ||
}; | ||
type Error = { | ||
error: string; | ||
}; | ||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<Data | Error | Data[] | DocumentData[]> | ||
) { | ||
if (req.method === "POST") { | ||
const { uid } = req.body; | ||
const collectionRef = collection(db, `User/${uid}/Smartshare`); | ||
const SmartShareData: SmartShareData[] = []; | ||
await getDocs(collectionRef).then((querySnapshot) => { | ||
querySnapshot.forEach((doc) => { | ||
const { smartLink, time, name } = doc.data(); | ||
SmartShareData.push({ url: smartLink, time, name }); | ||
}); | ||
res.status(200).json({ status: "Done", data: SmartShareData }); | ||
}); | ||
} else { | ||
res.status(200).json({ status: "Not Done" }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters