refactor: API POST /teams (#13211)
Co-authored-by: Omar López <[email protected]>
This commit is contained in:
1 parent
f52f2f32fa
commit
312a3f2543
7 files changed
+298
-53
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import type { DefaultArgs, InternalArgs } from "@prisma/client/runtime/library";
|
||||
|
||||
export function excludePendingPaymentsExtension() {
|
||||
return Prisma.defineExtension({
|
||||
query: {
|
||||
team: {
|
||||
async findUnique({ args, query }) {
|
||||
return excludePendingPayments(args, query);
|
||||
},
|
||||
async findFirst({ args, query }) {
|
||||
return excludePendingPayments(args, query);
|
||||
},
|
||||
async findMany({ args, query }) {
|
||||
return excludePendingPayments(args, query);
|
||||
},
|
||||
async findUniqueOrThrow({ args, query }) {
|
||||
return excludePendingPayments(args, query);
|
||||
},
|
||||
async findFirstOrThrow({ args, query }) {
|
||||
return excludePendingPayments(args, query);
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function excludePendingPayments(
|
||||
args:
|
||||
| Prisma.TeamFindUniqueArgs<InternalArgs & DefaultArgs>
|
||||
| Prisma.TeamFindFirstArgs<InternalArgs & DefaultArgs>
|
||||
| Prisma.TeamFindManyArgs<InternalArgs & DefaultArgs>
|
||||
| Prisma.TeamFindUniqueOrThrowArgs<InternalArgs & DefaultArgs>
|
||||
| Prisma.TeamFindFirstOrThrowArgs<InternalArgs & DefaultArgs>,
|
||||
query: <T>(args: T) => Promise<unknown>
|
||||
) {
|
||||
args.where = args.where || {};
|
||||
if (args.where.pendingPayment === undefined) {
|
||||
args.where.pendingPayment = false;
|
||||
}
|
||||
return query(args);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import type { Prisma } from "@prisma/client";
|
||||
import { PrismaClient as PrismaClientWithoutExtension } from "@prisma/client";
|
||||
import { withAccelerate } from "@prisma/extension-accelerate";
|
||||
|
||||
import { excludePendingPaymentsExtension } from "./extensions/exclude-pending-payment-teams";
|
||||
import { bookingReferenceMiddleware } from "./middleware";
|
||||
|
||||
const prismaOptions: Prisma.PrismaClientOptions = {};
|
||||
@@ -18,7 +19,9 @@ const prismaWithoutClientExtensions =
|
||||
globalForPrisma.prismaWithoutClientExtensions || new PrismaClientWithoutExtension(prismaOptions);
|
||||
|
||||
export const customPrisma = (options?: Prisma.PrismaClientOptions) =>
|
||||
new PrismaClientWithoutExtension({ ...prismaOptions, ...options }).$extends(withAccelerate());
|
||||
new PrismaClientWithoutExtension({ ...prismaOptions, ...options })
|
||||
.$extends(excludePendingPaymentsExtension())
|
||||
.$extends(withAccelerate());
|
||||
|
||||
// If any changed on middleware server restart is required
|
||||
// TODO: Migrate it to $extends
|
||||
@@ -27,35 +30,8 @@ bookingReferenceMiddleware(prismaWithoutClientExtensions);
|
||||
// FIXME: Due to some reason, there are types failing in certain places due to the $extends. Fix it and then enable it
|
||||
// Specifically we get errors like `Type 'string | Date | null | undefined' is not assignable to type 'Exact<string | Date | null | undefined, string | Date | null | undefined>'`
|
||||
const prismaWithClientExtensions = prismaWithoutClientExtensions
|
||||
//
|
||||
.$extends(excludePendingPaymentsExtension())
|
||||
.$extends(withAccelerate());
|
||||
// .$extends({
|
||||
// query: {
|
||||
// $allModels: {
|
||||
// async $allOperations({ model, operation, args, query }) {
|
||||
// const start = performance.now();
|
||||
// /* your custom logic here */
|
||||
// const res = await query(args);
|
||||
// const end = performance.now();
|
||||
// logger.debug("Query Perf: ", `${model}.${operation} took ${(end - start).toFixed(2)}ms\n`);
|
||||
// return res;
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
// .$extends({
|
||||
// name: "teamUpdateWithMetadata",
|
||||
// query: {
|
||||
// team: {
|
||||
// async update({ model, operation, args, query }) {
|
||||
// if (args.data.metadata) {
|
||||
// // Prepare args.data with merged metadata
|
||||
// }
|
||||
// return query(args);
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
|
||||
export const prisma = globalForPrisma.prismaWithClientExtensions || prismaWithClientExtensions;
|
||||
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Team" ADD COLUMN "pendingPayment" BOOLEAN NOT NULL DEFAULT false;
|
||||
@@ -318,6 +318,7 @@ model Team {
|
||||
isOrganization Boolean @default(false)
|
||||
organizationSettings OrganizationSettings?
|
||||
instantMeetingTokens InstantMeetingToken[]
|
||||
pendingPayment Boolean @default(false)
|
||||
|
||||
@@unique([slug, parentId])
|
||||
@@unique([slug, isOrganization])
|
||||
|
||||
Reference in new issue
Block a user