chore: add logs for debugging (#17111)
* chore: add logs * fix: filter in prisma query * test: add test for personal event types * chore: remove OR condition
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
import { hasFilter } from "@calcom/features/filters/lib/hasFilter";
|
||||
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { EventTypeRepository } from "@calcom/lib/server/repository/eventType";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
|
||||
// import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import type { TrpcSessionUser } from "../../../trpc";
|
||||
import type { TGetEventTypesFromGroupSchema } from "./getByViewer.schema";
|
||||
import { mapEventType } from "./util";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["getEventTypesFromGroup"] });
|
||||
|
||||
type GetByViewerOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
@@ -46,6 +50,7 @@ export const getEventTypesFromGroup = async ({ ctx, input }: GetByViewerOptions)
|
||||
{
|
||||
where: {
|
||||
teamId: null,
|
||||
schedulingType: null,
|
||||
},
|
||||
orderBy: [
|
||||
{
|
||||
@@ -99,7 +104,15 @@ export const getEventTypesFromGroup = async ({ ctx, input }: GetByViewerOptions)
|
||||
|
||||
const mappedEventTypes = await Promise.all(eventTypes.map(mapEventType));
|
||||
|
||||
let filteredEventTypes = mappedEventTypes.filter((eventType) => {
|
||||
log.info(
|
||||
"mappedEventTypes before filtering",
|
||||
safeStringify({
|
||||
input,
|
||||
mappedEventTypes,
|
||||
})
|
||||
);
|
||||
|
||||
const filteredEventTypes = mappedEventTypes.filter((eventType) => {
|
||||
const isAChildEvent = eventType.parentId;
|
||||
if (!isAChildEvent) {
|
||||
return true;
|
||||
@@ -112,11 +125,13 @@ export const getEventTypesFromGroup = async ({ ctx, input }: GetByViewerOptions)
|
||||
return true;
|
||||
});
|
||||
|
||||
if (shouldListUserEvents || !teamId) {
|
||||
filteredEventTypes = filteredEventTypes.filter(
|
||||
(evType) => evType.schedulingType !== SchedulingType.MANAGED
|
||||
);
|
||||
}
|
||||
log.info(
|
||||
"mappedEventTypes after filtering",
|
||||
safeStringify({
|
||||
input,
|
||||
filteredEventTypes,
|
||||
})
|
||||
);
|
||||
|
||||
return {
|
||||
eventTypes: filteredEventTypes || [],
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import { getEventTypesFromGroup } from "./getEventTypesFromGroup.handler";
|
||||
|
||||
describe("getEventTypesFromGroup", async () => {
|
||||
const proUser = await prisma.user.findFirstOrThrow({ where: { email: "pro@example.com" } });
|
||||
const proUserEventTypes = await prisma.eventType.findMany({ where: { userId: proUser.id } });
|
||||
|
||||
it("should return personal event types for a user", async () => {
|
||||
const ctx = {
|
||||
user: {
|
||||
id: proUser.id,
|
||||
name: proUser.name,
|
||||
profile: {
|
||||
name: proUser.name,
|
||||
organizationId: null,
|
||||
organization: null,
|
||||
username: proUser.username,
|
||||
id: null,
|
||||
upId: "usr-4",
|
||||
},
|
||||
} as NonNullable<TrpcSessionUser>,
|
||||
prisma,
|
||||
};
|
||||
|
||||
const res = await getEventTypesFromGroup({
|
||||
ctx,
|
||||
input: {
|
||||
group: {
|
||||
teamId: null,
|
||||
parentId: null,
|
||||
},
|
||||
limit: 10,
|
||||
cursor: null,
|
||||
},
|
||||
});
|
||||
|
||||
const resEventTypeIds = res.eventTypes.map((et) => et.id);
|
||||
const proUserEventTypeIds = proUserEventTypes.map((et) => et.id);
|
||||
|
||||
expect(res.eventTypes).toBeDefined();
|
||||
expect(res.eventTypes.length).toBeGreaterThan(0);
|
||||
expect(resEventTypeIds).toEqual(expect.arrayContaining(proUserEventTypeIds));
|
||||
expect(resEventTypeIds.length).toBe(proUserEventTypeIds.length);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user