Files
cal.diy/packages/app-store/slackmessaging/lib/showTodayMessage.ts
T
c03ff0a543 Fixes slack verification and timeout errors (#2972)
* Fixing slack create event

* Fixes verify working 90% of the time :S

* Verify V2

* Fixing verify - not needed on interaction payload

* Fixing verifcation + response

* Fix verifcation

* DM user error/success

* Remove random 200

* Timeout return

* Adding Zod schema verification

* Added validations, cleanup

* Type fixes

* Update event.ts

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-06-11 22:30:52 +01:00

56 lines
1.4 KiB
TypeScript

import { BookingStatus } from "@prisma/client";
import dayjs from "dayjs";
import { NextApiRequest, NextApiResponse } from "next";
import prisma from "@calcom/prisma";
import { WhereCredsEqualsId } from "./WhereCredsEqualsID";
import slackVerify from "./slackVerify";
import { NoUserMessage, TodayMessage } from "./views";
export default async function showCreateEventMessage(req: NextApiRequest, res: NextApiResponse) {
const body = req.body;
await slackVerify(req, res);
const foundUser = await prisma.credential.findFirst({
...WhereCredsEqualsId(body.user_id),
include: {
user: {
select: {
id: true,
email: true,
},
},
},
});
if (!foundUser) res.status(200).json(NoUserMessage);
const bookings = await prisma.booking.findMany({
where: {
OR: [
{
userId: foundUser?.userId,
},
{
attendees: {
some: {
email: foundUser?.user?.email,
},
},
},
],
AND: [
{
endTime: { gte: dayjs().startOf("day").toDate(), lte: dayjs().endOf("day").toDate() },
AND: [
{ NOT: { status: { equals: BookingStatus.CANCELLED } } },
{ NOT: { status: { equals: BookingStatus.REJECTED } } },
],
},
],
},
});
return res.status(200).json(TodayMessage(bookings));
}