| 463 | } |
| 464 | |
| 465 | class UserClass extends mongoose.Model { |
| 466 | // review if you need this method at private-api |
| 467 | public static publicFields(): string[] { |
| 468 | return [ |
| 469 | '_id', |
| 470 | 'id', |
| 471 | 'email', |
| 472 | 'accountCreationDate', |
| 473 | 'userName', |
| 474 | 'userAvatarUrl', |
| 475 | 'showDarkTheme', |
| 476 | |
| 477 | 'onlineStatusByTeam', |
| 478 | |
| 479 | 'teamsForTeamLeader', |
| 480 | 'teamsForTeamMember', |
| 481 | 'defaultTeamId', |
| 482 | |
| 483 | 'stripeCard', |
| 484 | 'stripeCustomer', |
| 485 | |
| 486 | 'pinnedDiscussionIds', |
| 487 | 'pinnedChatIds', |
| 488 | |
| 489 | 'unreadCommentIds', |
| 490 | 'unreadByUserMessageIds', |
| 491 | 'unreadBySomeoneMessageIds', |
| 492 | |
| 493 | 'trialPeriodStartDate', |
| 494 | 'isSubscriptionActiveForAccount', |
| 495 | 'isPaymentFailedForAccount', |
| 496 | 'stripeSubscription', |
| 497 | 'stripeListOfInvoices', |
| 498 | 'numberOfUniqueActiveTeamMembers', |
| 499 | ]; |
| 500 | } |
| 501 | |
| 502 | public static async registerOrLogIn({ uid, email, isLoginEvent, teamId }) { |
| 503 | const user = await this.findOne({ email }).setOptions({ lean: true }); |
| 504 | |
| 505 | let template; |
| 506 | |
| 507 | if (user && isLoginEvent) { |
| 508 | if (!teamId) { |
| 509 | return user; |
| 510 | } |
| 511 | |
| 512 | // teamId is truthy means this is an invitation event |
| 513 | // teamId is truthy means user has teamsForTeamMember |
| 514 | |
| 515 | const team = user.teamsForTeamMember.find((team) => { |
| 516 | return team.teamId === teamId; |
| 517 | }); |
| 518 | |
| 519 | let updatedUser = user; |
| 520 | |
| 521 | if (team && team.status === 'invited') { |
| 522 | // tested |
nothing calls this directly
no outgoing calls
no test coverage detected