fix: v2 allow creating team events without hosts (#20520)

* fix: v2 allow creating team events without hosts

* chore: remove log
This commit is contained in:
Lauris Skraucis
2025-04-03 07:53:58 +00:00
committed by GitHub
parent 8ae5d32fe5
commit feff588603
3 changed files with 12 additions and 38 deletions
@@ -264,7 +264,7 @@ describe("Assign all team members", () => {
});
describe("should setup event types using assignAllTeamMembers true", () => {
it("should not be able to setup team event type if no hosts nor assignAllTeamMembers provided", async () => {
it("should be able to setup team event type if no hosts nor assignAllTeamMembers provided", async () => {
const body: CreateTeamEventTypeInput_2024_06_14 = {
title: "Coding consultation round robin",
slug: `organizations-event-types-round-robin-${randomString()}`,
@@ -279,7 +279,17 @@ describe("Assign all team members", () => {
.send(body)
.set(X_CAL_SECRET_KEY, oAuthClient.secret)
.set(X_CAL_CLIENT_ID, oAuthClient.id)
.expect(400);
.expect(201);
const responseBody: ApiSuccessResponse<TeamEventTypeOutput_2024_06_14> = response.body;
expect(responseBody.status).toEqual(SUCCESS_STATUS);
const data = responseBody.data;
expect(data.title).toEqual(body.title);
expect(data.hosts).toEqual([]);
expect(data.schedulingType).toEqual("collective");
const eventTypeHosts = await hostsRepositoryFixture.getEventTypeHosts(data.id);
expect(eventTypeHosts.length).toEqual(0);
});
it("should setup collective event type assignAllTeamMembers true", async () => {
@@ -108,13 +108,6 @@ export class InputOrganizationsEventTypesService {
teamId: number,
inputEventType: CreateTeamEventTypeInput_2024_06_14
) {
const hasHosts = !!inputEventType.hosts && !!inputEventType.hosts.length;
const hasAssignAllTeamMembers = inputEventType.assignAllTeamMembers === true;
if (!hasHosts && !hasAssignAllTeamMembers) {
throw new BadRequestException("Either hosts must be provided or assignAllTeamMembers must be true");
}
const { hosts, assignAllTeamMembers, locations, ...rest } = inputEventType;
const eventType = this.inputEventTypesService.transformInputCreateEventType(rest);
@@ -5,7 +5,6 @@ import {
ApiExtraModels,
} from "@nestjs/swagger";
import { Type, Transform, Expose } from "class-transformer";
import type { ValidationOptions, ValidationArguments } from "class-validator";
import {
IsString,
IsInt,
@@ -18,7 +17,6 @@ import {
ValidateNested,
ArrayNotEmpty,
ArrayUnique,
registerDecorator,
} from "class-validator";
import { SchedulingType } from "@calcom/platform-enums";
@@ -447,33 +445,6 @@ export class Host {
@DocsPropertyOptional({ enum: HostPriority })
priority?: keyof typeof HostPriority = "medium";
}
function RequireHostsOrAssignAllMembers(validationOptions?: ValidationOptions) {
return function (object: any) {
registerDecorator({
name: "requireHostsOrAssignAllMembers",
target: object,
propertyName: "hosts OR assignAllTeamMembers",
options: validationOptions,
constraints: [],
validator: {
validate(_value: any, args: ValidationArguments) {
const obj = args.object as CreateTeamEventTypeInput_2024_06_14;
const hasHosts = !!obj.hosts && !!obj.hosts.length;
const hasAssignAllTeamMembers = obj.assignAllTeamMembers === true;
return hasHosts || hasAssignAllTeamMembers;
},
defaultMessage(): string {
return "Either hosts OR assignAllTeamMembers set to true is required";
},
},
});
};
}
@RequireHostsOrAssignAllMembers()
export class CreateTeamEventTypeInput_2024_06_14 extends BaseCreateEventTypeInput {
@Transform(({ value }) => {
if (value === "collective") {