* feat: web push notifications feature * Revert yarn.lock changes * added new env variables requirement in .env.example * moved useNotifications hook in packages/lib/hooks * fix: bug * use i18n * chore: move to new file * chore: add yarn.lock * Update .env.example Co-authored-by: Amit Sharma <[email protected]> * chore: add instruction for brave browser * fix: tooltip * chore: use enum * chore * small update --------- Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Amit Sharma <[email protected]> Co-authored-by: Carina Wollendorfer <[email protected]> Co-authored-by: unknown <[email protected]> Co-authored-by: Anik Dhabal Babu <[email protected]>
31 lines
861 B
TypeScript
31 lines
861 B
TypeScript
import prisma from "@calcom/prisma";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
|
|
|
import type { TAddNotificationsSubscriptionInputSchema } from "./addNotificationsSubscription.schema";
|
|
|
|
type AddSecondaryEmailOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TAddNotificationsSubscriptionInputSchema;
|
|
};
|
|
|
|
export const addNotificationsSubscriptionHandler = async ({ ctx, input }: AddSecondaryEmailOptions) => {
|
|
const { user } = ctx;
|
|
const { subscription } = input;
|
|
|
|
const existingSubscription = await prisma.notificationsSubscriptions.findFirst({
|
|
where: { userId: user.id, subscription },
|
|
});
|
|
|
|
if (!existingSubscription) {
|
|
await prisma.notificationsSubscriptions.create({
|
|
data: { userId: user.id, subscription },
|
|
});
|
|
}
|
|
|
|
return {
|
|
message: "Subscription added successfully",
|
|
};
|
|
};
|