2
0

♻️ (results) Introduce tRPC and use it for the results

This commit is contained in:
Baptiste Arnaud
2022-11-18 18:21:40 +01:00
parent c9cc82cc08
commit d58f9bd3a1
58 changed files with 750 additions and 421 deletions

View File

@ -34,7 +34,11 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const { resultValues, variables } = (
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
) as {
resultValues: ResultValues | undefined
resultValues:
| (Omit<ResultValues, 'createdAt'> & {
createdAt: string
})
| undefined
variables: Variable[]
}
const typebot = (await prisma.typebot.findUnique({
@ -83,7 +87,9 @@ export const executeWebhook =
webhook: Webhook,
variables: Variable[],
groupId: string,
resultValues?: ResultValues,
resultValues?: Omit<ResultValues, 'createdAt'> & {
createdAt: string
},
resultId?: string
): Promise<WebhookResponse> => {
if (!webhook.url || !webhook.method)
@ -193,7 +199,9 @@ const getBodyContent =
groupId,
}: {
body?: string | null
resultValues?: ResultValues
resultValues?: Omit<ResultValues, 'createdAt'> & {
createdAt: string
}
groupId: string
}): Promise<string | undefined> => {
if (!body) return

View File

@ -26,7 +26,11 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const { resultValues, variables } = (
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
) as {
resultValues: ResultValues | undefined
resultValues:
| (Omit<ResultValues, 'createdAt'> & {
createdAt: string
})
| undefined
variables: Variable[]
}
const typebot = (await prisma.typebot.findUnique({

View File

@ -54,7 +54,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
} = (
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
) as SendEmailOptions & {
resultValues: ResultValues
resultValues: Omit<ResultValues, 'createdAt'> & {
createdAt: string
}
fileUrls?: string
}
const { name: replyToName } = parseEmailRecipient(replyTo)
@ -162,10 +164,14 @@ const getEmailBody = async ({
isBodyCode,
typebotId,
resultValues,
}: { typebotId: string; resultValues: ResultValues } & Pick<
SendEmailOptions,
'isCustomBody' | 'isBodyCode' | 'body'
>): Promise<{ html?: string; text?: string } | undefined> => {
}: {
typebotId: string
resultValues: Omit<ResultValues, 'createdAt'> & {
createdAt: string
}
} & Pick<SendEmailOptions, 'isCustomBody' | 'isBodyCode' | 'body'>): Promise<
{ html?: string; text?: string } | undefined
> => {
if (isCustomBody || (isNotDefined(isCustomBody) && !isEmpty(body)))
return {
html: isBodyCode ? body : undefined,