cal.com icon indicating copy to clipboard operation
cal.com copied to clipboard

refactor: API POST /teams

Open supalarry opened this issue 1 year ago • 4 comments

Fixes https://github.com/calcom/cal.com/issues/9127

Loom: https://www.loom.com/share/c9e6c761be9b48d3847b176d458d81b1

This PR has 2 refactors:

  1. Allow admins to create teams on the behalf of other users.
  2. Create team only after receiving payment.

Allow admins to create teams on the behalf of other users

File apps/api/lib/validations/team.ts has been updated to allow passing "ownerId" in the request body to specify on behalf of who should the team be created. Notably, only admins can do this as seen by the "checkPermissions" in api/teams/_post.ts - if user is admin and "ownerId" is in the request body, then we specify "const effectiveUserId = isAdmin && ownerId ? ownerId : userId;" which is used to determine owner of the team.

Create team only after receiving payment

New Prisma model - "AwaitingPaymentTeam" has been added to schema.prisma in order to store team information submitted to api/teams/_post.ts. We need it because we can't store keys with boolean values in Stripe checkout metadata while we have "hideBookATeamMember": true / fase and "isPrivate": true / false as required properties when creating a team.

  1. After receiving request api/teams/_post.ts will store team's data in the "AwaitingPaymentTeam" table, and create a new stripe checkout session where metadata contains id of the newly created "AwaitingPaymentTeam" and "ownerId". User will receive stripe link to pay: Screenshot 2024-01-13 at 16 21 03

  2. After user pays, he / she will be re-directed to the success_url that was specified by "generateTeamCheckoutSession" when creating session in step 1, which is the api/teams/api/create.ts page. It will check stripe metadata "awaitingPaymentTeamId", fetch it and using the data create an actual team that is returned to user and the awaiting payment team is deleted.

supalarry avatar Jan 13 '24 15:01 supalarry

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 16, 2024 5:33pm
dev ❌ Failed (Inspect) Jan 16, 2024 5:33pm
5 Ignored Deployments
Name Status Preview Comments Updated (UTC)
ai ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2024 5:33pm
cal ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2024 5:33pm
cal-demo ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2024 5:33pm
qa ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2024 5:33pm
ui ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2024 5:33pm

vercel[bot] avatar Jan 13 '24 15:01 vercel[bot]

Thank you for following the naming conventions! 🙏 Feel free to join our discord and post your PR link.

github-actions[bot] avatar Jan 13 '24 15:01 github-actions[bot]

Current Playwright Test Results Summary

✅ 386 Passing - ⚠️ 12 Flaky

Run may still be in progress, this comment will be updated as current testing workflow or job completes...

(Last updated on 01/16/2024 05:46:08pm UTC)

Run Details

Running Workflow PR Update on Github Actions

Commit: aedbe4fed8185b53af4007997fa8ee7b7b5343d3

Started: 01/16/2024 05:38:50pm UTC

⚠️ Flakes

📄   apps/web/playwright/booking/longTextQuestion.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Booking With Long Text Question and Each Other Question Booking With Long Text Question and Checkbox Group Question Long Text required and Checkbox Group not required
Retry 1Initial Attempt
0.26% (1) 1 / 379 run
failed over last 7 days
2.37% (9) 9 / 379 runs
flaked over last 7 days

📄   apps/web/playwright/login.2fa.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
2FA Tests should allow a user to enable 2FA and login using 2FA
Retry 1Initial Attempt
0% (0) 0 / 281 runs
failed over last 7 days
35.23% (99) 99 / 281 runs
flaked over last 7 days

📄   apps/web/playwright/booking/checkboxGroupQuestion.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Booking With Checkbox Group Question and Each Other Question Booking With Checkbox Group Question and Address Question Booking With Checkbox Group Question and Multi email Question Checkbox Group and Multi email not required
Retry 1Initial Attempt
0.26% (1) 1 / 381 run
failed over last 7 days
2.10% (8) 8 / 381 runs
flaked over last 7 days

📄   apps/web/playwright/payment-apps.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Payment app when more than one payment app is installed the price should be updated when changing settings
Retry 1Initial Attempt
0% (0) 0 / 382 runs
failed over last 7 days
4.97% (19) 19 / 382 runs
flaked over last 7 days

📄   apps/web/playwright/organization/organization-invitation.e2e.ts • 2 Flakes

Top 1 Common Error Messages

null

2 Test Cases Affected

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Organization Email not matching orgAutoAcceptEmail Org Invitation
Retry 1Initial Attempt
2.22% (9) 9 / 406 runs
failed over last 7 days
13.30% (54) 54 / 406 runs
flaked over last 7 days
Organization Email matching orgAutoAcceptEmail and a Verified Organization Team Invitation
Retry 1Initial Attempt
4.08% (16) 16 / 392 runs
failed over last 7 days
24.74% (97) 97 / 392 runs
flaked over last 7 days

📄   apps/web/playwright/event-types.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Event Types tests user -- future Different Locations Tests Can add Organzer Phone Number location and book with it
Retry 1Initial Attempt
2.22% (9) 9 / 406 runs
failed over last 7 days
3.69% (15) 15 / 406 runs
flaked over last 7 days

📄   apps/web/playwright/oauth-provider.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
OAuth Provider should create valid access token & refresh token for team
Retry 1Initial Attempt
0% (0) 0 / 409 runs
failed over last 7 days
20.29% (83) 83 / 409 runs
flaked over last 7 days

📄   packages/embeds/embed-core/playwright/tests/action-based.e2e.ts • 4 Flakes

Top 1 Common Error Messages

null

4 Test Cases Affected

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Popup Tests should open Routing Forms embed on click
Retry 1Initial Attempt
-1.98% (-8) -8 / 404 runs
failed over last 7 days
43.07% (174) 174 / 404 runs
flaked over last 7 days
Popup Tests should open embed iframe on click - Configured with light theme
Retry 1Initial Attempt
2.17% (9) 9 / 414 runs
failed over last 7 days
54.35% (225) 225 / 414 runs
flaked over last 7 days
Popup Tests Floating Button Popup Pro User - Configured in App with default setting of system theme should open embed iframe according to system theme when no theme is configured through Embed API
Retry 1Initial Attempt
2.72% (11) 11 / 404 runs
failed over last 7 days
76.24% (308) 308 / 404 runs
flaked over last 7 days
Popup Tests should be able to reschedule
Retry 2Retry 1Initial Attempt
13.58% (55) 55 / 405 runs
failed over last 7 days
81.98% (332) 332 / 405 runs
flaked over last 7 days

View Detailed Build Results


deploysentinel[bot] avatar Jan 13 '24 15:01 deploysentinel[bot]

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

github-actions[bot] avatar Jan 16 '24 16:01 github-actions[bot]