feat: v2 get slots using teamSlug + eventTypeSlug + optional organizationSlug (#20554)
* feat: allow teamSlug + eventTypeSlug + optional organizationSlug as input * feat: return team event slots * test: get slots using teamSlug + eventTypeSlug + optional organizationalSlug * docs: how to get team event slots
This commit is contained in:
1 parent
7b8bbaaa86
commit
7ef1050946
13 files changed
+302
-49
No files matched your search
@@ -4,10 +4,18 @@ import { plainToClass } from "class-transformer";
|
||||
import type { ValidationError } from "class-validator";
|
||||
import { validateSync } from "class-validator";
|
||||
|
||||
import { ById_2024_09_04, BySlug_2024_09_04 } from "./get-slots.input";
|
||||
import {
|
||||
ById_2024_09_04,
|
||||
ByTeamSlugAndEventTypeSlug_2024_09_04,
|
||||
ByUsernameAndEventTypeSlug_2024_09_04,
|
||||
} from "./get-slots.input";
|
||||
import { ByUsernames_2024_09_04 } from "./get-slots.input";
|
||||
|
||||
export type GetSlotsInput_2024_09_04 = ById_2024_09_04 | BySlug_2024_09_04 | ByUsernames_2024_09_04;
|
||||
export type GetSlotsInput_2024_09_04 =
|
||||
| ById_2024_09_04
|
||||
| ByUsernameAndEventTypeSlug_2024_09_04
|
||||
| ByTeamSlugAndEventTypeSlug_2024_09_04
|
||||
| ByUsernames_2024_09_04;
|
||||
|
||||
@Injectable()
|
||||
export class GetSlotsInputPipe implements PipeTransform {
|
||||
@@ -29,8 +37,12 @@ export class GetSlotsInputPipe implements PipeTransform {
|
||||
return this.validateById(value);
|
||||
}
|
||||
|
||||
if (this.isBySlug(value)) {
|
||||
return this.validateBySlug(value);
|
||||
if (this.isByUsernameAndEventTypeSlug(value)) {
|
||||
return this.validateByUsernameAndEventTypeSlug(value);
|
||||
}
|
||||
|
||||
if (this.isByTeamSlugAndEventTypeSlug(value)) {
|
||||
return this.validateByTeamSlugAndEventTypeSlug(value);
|
||||
}
|
||||
|
||||
return this.validateByUsernames(value);
|
||||
@@ -52,8 +64,24 @@ export class GetSlotsInputPipe implements PipeTransform {
|
||||
return object;
|
||||
}
|
||||
|
||||
validateBySlug(value: BySlug_2024_09_04) {
|
||||
const object = plainToClass(BySlug_2024_09_04, value);
|
||||
validateByUsernameAndEventTypeSlug(value: ByUsernameAndEventTypeSlug_2024_09_04) {
|
||||
const object = plainToClass(ByUsernameAndEventTypeSlug_2024_09_04, value);
|
||||
|
||||
const errors = validateSync(object, {
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
skipMissingProperties: false,
|
||||
});
|
||||
|
||||
if (errors.length > 0) {
|
||||
throw new BadRequestException(this.formatErrors(errors));
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
validateByTeamSlugAndEventTypeSlug(value: ByTeamSlugAndEventTypeSlug_2024_09_04) {
|
||||
const object = plainToClass(ByTeamSlugAndEventTypeSlug_2024_09_04, value);
|
||||
|
||||
const errors = validateSync(object, {
|
||||
whitelist: true,
|
||||
@@ -99,7 +127,15 @@ export class GetSlotsInputPipe implements PipeTransform {
|
||||
return value.hasOwnProperty("eventTypeId");
|
||||
}
|
||||
|
||||
private isBySlug(value: GetSlotsInput_2024_09_04): value is BySlug_2024_09_04 {
|
||||
return value.hasOwnProperty("eventTypeSlug");
|
||||
private isByUsernameAndEventTypeSlug(
|
||||
value: GetSlotsInput_2024_09_04
|
||||
): value is ByUsernameAndEventTypeSlug_2024_09_04 {
|
||||
return value.hasOwnProperty("username") && value.hasOwnProperty("eventTypeSlug");
|
||||
}
|
||||
|
||||
private isByTeamSlugAndEventTypeSlug(
|
||||
value: GetSlotsInput_2024_09_04
|
||||
): value is ByTeamSlugAndEventTypeSlug_2024_09_04 {
|
||||
return value.hasOwnProperty("teamSlug") && value.hasOwnProperty("eventTypeSlug");
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,11 @@ export class GetAvailableSlotsInput_2024_09_04 {
|
||||
format?: SlotFormat;
|
||||
}
|
||||
|
||||
export const ById_2024_09_04_type = "byEventTypeId";
|
||||
export class ById_2024_09_04 extends GetAvailableSlotsInput_2024_09_04 {
|
||||
@IsString()
|
||||
type: typeof ById_2024_09_04_type = ById_2024_09_04_type;
|
||||
|
||||
@Transform(({ value }: { value: string }) => value && parseInt(value))
|
||||
@IsNumber()
|
||||
@ApiProperty({
|
||||
@@ -91,7 +95,11 @@ export class ById_2024_09_04 extends GetAvailableSlotsInput_2024_09_04 {
|
||||
eventTypeId!: number;
|
||||
}
|
||||
|
||||
export class BySlug_2024_09_04 extends GetAvailableSlotsInput_2024_09_04 {
|
||||
export const ByUsernameAndEventTypeSlug_2024_09_04_type = "byUsernameAndEventTypeSlug";
|
||||
export class ByUsernameAndEventTypeSlug_2024_09_04 extends GetAvailableSlotsInput_2024_09_04 {
|
||||
@IsString()
|
||||
type: typeof ByUsernameAndEventTypeSlug_2024_09_04_type = ByUsernameAndEventTypeSlug_2024_09_04_type;
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
@@ -120,7 +128,44 @@ export class BySlug_2024_09_04 extends GetAvailableSlotsInput_2024_09_04 {
|
||||
organizationSlug?: string;
|
||||
}
|
||||
|
||||
export const ByTeamSlugAndEventTypeSlug_2024_09_04_type = "byTeamSlugAndEventTypeSlug";
|
||||
export class ByTeamSlugAndEventTypeSlug_2024_09_04 extends GetAvailableSlotsInput_2024_09_04 {
|
||||
@IsString()
|
||||
type: typeof ByTeamSlugAndEventTypeSlug_2024_09_04_type = ByTeamSlugAndEventTypeSlug_2024_09_04_type;
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
description: "The slug of the event type for which available slots should be checked.",
|
||||
example: "event-type-slug",
|
||||
})
|
||||
eventTypeSlug!: string;
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
description:
|
||||
"When searching by eventTypeSlug a teamSlug must be provided too aka team who owns the the event type.",
|
||||
example: "bob",
|
||||
})
|
||||
teamSlug!: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
description:
|
||||
"Organzation slug in which the slots of event type belonging to the specified teamSlug should be checked.",
|
||||
example: "org-slug",
|
||||
})
|
||||
organizationSlug?: string;
|
||||
}
|
||||
|
||||
export const ByUsernames_2024_09_04_type = "byUsernames";
|
||||
export class ByUsernames_2024_09_04 extends GetAvailableSlotsInput_2024_09_04 {
|
||||
@IsString()
|
||||
type: typeof ByUsernames_2024_09_04_type = ByUsernames_2024_09_04_type;
|
||||
|
||||
@Transform(({ value }) => {
|
||||
if (typeof value === "string") {
|
||||
return value.split(",").map((username: string) => username.trim());
|
||||
|
||||
Reference in new issue
Block a user