RoundRobin Booking Error in a particular case (#2471)

* users can be array of user when roundrobin team booking is there with availablity of multiple people

* Return empty array

* Add comments

* checktype fix

* removed extra condition

Co-authored-by: Syed Ali Shahbaz <alishahbaz7@gmail.com>
This commit is contained in:
Hariom Balhara 2022-04-12 22:40:18 +05:30 committed by GitHub
parent 9d86039987
commit 75c2ccff96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 10 deletions

View file

@ -223,7 +223,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const reqBody = req.body as BookingCreateBody;
// handle dynamic user
const dynamicUserList = getUsernameList(reqBody.user as string);
const dynamicUserList = getUsernameList(reqBody?.user);
const eventTypeSlug = reqBody.eventTypeSlug;
const eventTypeId = reqBody.eventTypeId;
const tAttendees = await getTranslation(reqBody.language ?? "en", "common");

View file

@ -139,15 +139,29 @@ export const getUsernameSlugLink = ({ users, slug }: UsernameSlugLinkProps): str
return slugLink;
};
export const getUsernameList = (users: string): string[] => {
return users
?.toLowerCase()
.replace(/ /g, "+")
.replace(/%20/g, "+")
.split("+")
.filter((el) => {
return el.length != 0;
});
export const getUsernameList = (users: string | string[] | undefined): string[] => {
if (!users) {
return [];
}
if (!(users instanceof Array)) {
users = [users];
}
const allUsers: string[] = [];
// Multiple users can come in case of a team round-robin booking and in that case dynamic link won't be a user.
// So, even though this code handles even if individual user is dynamic link, that isn't a possibility right now.
users.forEach((user) => {
allUsers.push(
...user
?.toLowerCase()
.replace(/ /g, "+")
.replace(/%20/g, "+")
.split("+")
.filter((el) => {
return el.length != 0;
})
);
});
return allUsers;
};
export default defaultEvents;