For my upcoming app, I am working on an API that will utilize Firebase FCM Admin to send messages. Below is the code snippet:
import type { NextApiRequest, NextApiResponse } from "next";
import { getMessaging } from "firebase-admin/messaging";
export default async function handler(req,res) {
try{
let { title, text, topic, condition, token } = req.body;
topic === "" ? (topic = null) : "";
condition === "" ? (condition = null) : "";
token === "" ? (token = null) : "";
const result = await getMessaging().send({
notification: {
title: title,
body: text,
},
topic: topic,
condition: condition,
token: token,
});
res.status(200).send(result);
} catch (err) {
res.status(500).send(err);
}
}
Do you have any suggestions for improving this implementation? I feel like there might be room for enhancement.
topic === "" ? (topic = null) : "";
condition === "" ? (condition = null) : "";
token === "" ? (token = null) : "";