replace early returns with NotFoundError

test /api/webhook/incoming-message
This commit is contained in:
m5r
2021-08-02 21:43:27 +08:00
parent 827ed9f1c0
commit 2cf53533a3
11 changed files with 223 additions and 28 deletions

View File

@ -1,4 +1,4 @@
import { resolver } from "blitz";
import { NotFoundError, resolver } from "blitz";
import { z } from "zod";
import db, { Prisma } from "../../../db";
@ -12,7 +12,7 @@ const GetConversations = z.object({
export default resolver.pipe(resolver.zod(GetConversations), resolver.authorize(), async ({ recipient }, context) => {
const customer = await getCurrentCustomer(null, context);
if (!customer) {
return;
throw new NotFoundError();
}
const conversation = await db.message.findMany({

View File

@ -1,4 +1,4 @@
import { resolver } from "blitz";
import { resolver, NotFoundError } from "blitz";
import db, { Direction, Message, Prisma } from "../../../db";
import getCurrentCustomer from "../../customers/queries/get-current-customer";
@ -7,7 +7,7 @@ import { decrypt } from "../../../db/_encryption";
export default resolver.pipe(resolver.authorize(), async (_ = null, context) => {
const customer = await getCurrentCustomer(null, context);
if (!customer) {
return;
throw new NotFoundError();
}
const messages = await db.message.findMany({