Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/project management #825

Merged
merged 422 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
422 commits
Select commit Hold shift + click to select a range
f390b6f
feat: Added invite/team-members-list in routes
Sep 18, 2024
b652fec
feat: Added onAcceptClick mutation function
Sep 18, 2024
937bac9
feat: Added Error message if tried to accept invitation which has bee…
Sep 18, 2024
e33ed19
feat: Added UserRole as enum for role and moved key outside the apiKe…
Sep 18, 2024
0319e70
feat: Logs removed
Sep 18, 2024
0df1441
feat: Added UserRoleEnum and moved the key from IApiKeyData in the IE…
Sep 18, 2024
b045587
feat: Added getUserEnvironmentProjects
Sep 18, 2024
9bec849
feat: Moved key from IApiKey to the EnvironmentEntity itself at root …
Sep 18, 2024
53e6ad9
feat: Shifted the key from the apiKeys array to the top
Sep 18, 2024
eb0aa02
feat: Added property in return statement key: environment.key
Sep 18, 2024
45e6755
refactor: Renamed key to role
Sep 18, 2024
4cb0da9
feat: Added key in EnvironmentResponseDto
Sep 18, 2024
6fac300
feat: Added key directly from environment
Sep 18, 2024
b62ebf8
feat: Added enum as Admin, Tech, Finance in role in apiKeys
Sep 18, 2024
b0be4d2
feat: Added role as string in IApiKeyData
Sep 18, 2024
23e0dc7
feat: Removed setting of cookies
Sep 18, 2024
31e4535
feat: Called method getUserEnvironmentProjects
Sep 18, 2024
8ea4188
feat: Directly getting key from environment instead of apiKeys
Sep 18, 2024
d65a1de
feat: Removed method call to getSignedToken
Sep 18, 2024
6d7baf8
feat: Directly getting key like userEnvironment.key
Sep 18, 2024
4720739
feat: Getting the key directly from environment instead of the apiKey…
Sep 18, 2024
72ca8cc
feat: Added method call getInvitationData
Sep 18, 2024
b1c505b
feat: Getting userId from the environment
Sep 18, 2024
1054807
feat: Added TrashIcon (DeleteIcon)
Sep 18, 2024
6c9c414
feat: Renamed enum members
Sep 18, 2024
5b38c16
feat: Removed the key from apiKeys array and moved it outsid ethe array
Sep 18, 2024
f18cdec
feat: Added migration to shift the key from apiKey out of the array a…
Sep 18, 2024
4bebd64
feat: Added api call to the member listing api to list the team members
Sep 18, 2024
67a74fa
feat: Optimized migration
Sep 18, 2024
d6d00f7
feat: Added key out of the apiKey
Sep 18, 2024
58af7e4
feat: Returning token
Sep 19, 2024
e35827d
feat: Added static role as UserRolesEnum.ADMIN
Sep 19, 2024
b7158c1
feat: Added enum UserRolesEnum
Sep 19, 2024
20cb308
feat: Removed log
Sep 19, 2024
bbc0f97
feat: Added property role of type UserRolesEnum
Sep 19, 2024
7d6267f
feat: Moved code snippet in the environment repository and called tha…
Sep 20, 2024
738f3f9
feat: Added api routes team-member-delete and team-member-role-update
Sep 20, 2024
eec3eea
feat: Added functionality to delete TeamMember
Sep 20, 2024
f277616
feat: Added types for Team Members list table
Sep 20, 2024
9efa9ff
feat: Added joinedOn as the new property in environment schema
Sep 20, 2024
785f97a
feat: Added DeleteTeamMemberDto
Sep 20, 2024
3a825c1
feat: Added usecase DeleteTeamMember
Sep 20, 2024
f14b45d
feat: Added new keys
Sep 20, 2024
812b859
feat: Added UserRolesEnum in case condition
Sep 20, 2024
4d8b83b
feat: Added usecases UpdateTeamMemberRole and DeleteTeamMember
Sep 20, 2024
7854e83
feat: Added methods listTeamMembersByProjectId and deleteTeamMember
Sep 20, 2024
e9a5d7f
feat: Added joinedOn?: string as a property for the corresponding _us…
Sep 20, 2024
9a5206c
feat: Added UpdateTeamMemberRoleDto
Sep 20, 2024
6e1cb45
feat: Added snippet to find the role for current user and include in …
Sep 20, 2024
fe3df51
feat: Added role
Sep 20, 2024
7f5448a
feat: Added role
Sep 20, 2024
a7a7b82
feat: Added dto and command for update team member role
Sep 20, 2024
90a3a86
feat: Added route for team member delete and update their role
Sep 20, 2024
0e9cbdf
feat: environment key migration added
Sep 20, 2024
cb8b8eb
feat: Shown data dynamically
Sep 20, 2024
8ed06c1
feat: Added usecase UpdateTeamMemberRole
Sep 20, 2024
87c3d72
feat: team members related api keys renamed
Sep 20, 2024
c7ebcc8
feat: Whenever project is changed abilities also got changed
Sep 20, 2024
ab01589
feat: Added Toast message if there is some error while removing team …
Sep 20, 2024
277744b
feat: Added NOTIFICATION_KEY ERROR_LISTING_TEAM_MEMBERS
Sep 20, 2024
db91cbf
feat: Added custom hook useListTeamMembers and added mutation functio…
Sep 20, 2024
fb0159a
feat: Added method updateTeamMemberRole in environment repository
Sep 20, 2024
6540cde
feat: Added withinPortal to set the dropdown fully visible
Sep 20, 2024
ee35d7b
feat: Renamed icon
Sep 21, 2024
eca93ee
feat: Added new route to delete an already sent invitation
Sep 21, 2024
de1b714
feat: Added usecase DeleteInvitation to delete an invitation
Sep 21, 2024
56c8b4a
feat: Added DeleteInvitation usecase
Sep 21, 2024
28f18a9
refactor: Added invitation link
Sep 21, 2024
148049b
feat: File renamed
Sep 21, 2024
af7704d
feat: Added modal to delete invitation confirmation
Sep 21, 2024
487c511
feat: Added abilites bases member deletion and role update
Sep 21, 2024
dba2107
feat: Added feature of copy invitation url and cancel invitation
Sep 21, 2024
95d5672
feat: Added sent invitation count on Badges
Sep 21, 2024
98ccf13
feat: Added features to cancel and copy invitation link
Sep 21, 2024
f04b908
feat: Added APi_KEYS CANCEL_INVITATION
Sep 21, 2024
14e405e
feat: Added Role in Subject
Sep 21, 2024
c922a13
feat: Added mutation function helpers handleCopyInvitation and handle…
Sep 21, 2024
f9d2890
feat: Added api keys CANCEL_INVITATION
Sep 21, 2024
7130afa
feat: Added new property invitationLink in interface SentProjectInvit…
Sep 21, 2024
6072157
feat: Renamed the member value for the UserRolesEnum
Sep 21, 2024
ac19a5b
feat: Added default of admin when user initially signups using github
Sep 23, 2024
b9871af
feat: Shown profile picture on team members list
Sep 23, 2024
8f71095
feat: Exported members
Sep 23, 2024
f00f9f9
feat: File renamed to TeamMembers
Sep 23, 2024
fb9d6c8
feat: File renamed to TeamMembers
Sep 23, 2024
52ff234
feat: Changed import from ./Members to ./TeamMembers and used the sam…
Sep 23, 2024
b42f4f5
feat: Added profilePicture
Sep 23, 2024
536c427
feat: Added profilePicture in TeamMember interface
Sep 23, 2024
cbc207d
feat: Extracted profilePicture with respect to use while populating u…
Sep 23, 2024
094f3ab
feat: Added ActionEnum and SubjectEnum from config
Sep 23, 2024
785891f
feat: Added ActionsEnum, SubjectsEnum based access
Sep 23, 2024
90ceb2c
feat: Added ActionsEnum, SubjectsEnum based access
Sep 23, 2024
cca1c1f
feat: Added Roles from Enum and subjcts and action as enum and access…
Sep 23, 2024
1c5754d
refactor: Removed Subjects and Actions
Sep 23, 2024
20269d0
feat: Added ActionsEnum, SubjectsEnum based access
Sep 23, 2024
9e1d224
feat: Added ActionsEnum, SubjectsEnum based access
Sep 23, 2024
c24fcca
feat: Imported AppAbility from config
Sep 23, 2024
f970f02
feat: Added AppAbility from config
Sep 23, 2024
5fbc413
refactor: Root controller changed from invite to invitation
Sep 24, 2024
2d65899
feat: Added INVIATAION in SCREENS enum
Sep 24, 2024
f752a51
feat: Refactored Auth
Sep 24, 2024
aa9e68f
feat: Added property invitationId
Sep 24, 2024
33c1af7
feat: Added property invitationId
Sep 24, 2024
28d35f5
feat: Removed unnecessary dependencies
Sep 24, 2024
92257c4
feat: Added VALID_INVITATION as a key
Sep 24, 2024
2b560c8
feat: Removed class validator from command
Sep 24, 2024
82cfb2a
feat: Sent appropriate screens
Sep 24, 2024
a4593f4
feat: Removed class transformer
Sep 24, 2024
295d7d4
feat: Handle appropriate screens
Sep 24, 2024
724cdbd
feat: Sent appropriate screen
Sep 24, 2024
65f2467
feat: Removed token
Sep 24, 2024
d673045
feat: Removed token from invitationLink
Sep 24, 2024
453c2ca
feat: Added code to handle /auth/invitation route
Sep 24, 2024
803644b
refactor: Hook useInvitation refactored
Sep 24, 2024
7323df0
feat: Added invitationId in signin route
Sep 24, 2024
20fbd32
feat: Added ivitationId in useSignup
Sep 24, 2024
e21d66e
feat: log removed
Sep 24, 2024
5e2a8c2
feat: Route changed from invite to invitation
Sep 24, 2024
c0726c5
feat: Added /auth/invitation
Sep 24, 2024
d5efbd0
feat: Added fuction formatUrl
Sep 24, 2024
c64efe9
feat: Added invitationId in ISignupData
Sep 24, 2024
24e78a9
feat: Added optional apiKey while adding role
Sep 25, 2024
ae0db69
feat: Added passthrough in accept invitation route
Sep 25, 2024
657ddf7
refactor: Removed unnecessary checks
Sep 25, 2024
b29c25a
refactor: Removed check to find already registered users
Sep 25, 2024
bcf501c
refactor: Streamlined import statements
Sep 25, 2024
72f0d69
refactor: Streamlined import statements
Sep 25, 2024
c15f088
refactor: Removed logout mutation function and made it as a sepetrate…
Sep 25, 2024
842211b
feat: Added ModesEnum
Sep 25, 2024
1603111
feat: Added seperate logout hook
Sep 25, 2024
bca9262
feat: Renamed invitation-accept to /accept
Sep 25, 2024
14ab509
feat: Added formatUrl and passes invitationId to it
Sep 25, 2024
8061bc0
feat: Added [id].tsx for invitation route handling
Sep 25, 2024
a256ed1
refactor: REmoved token and typecasted invitationId toObjectId
Sep 25, 2024
f7dea77
feat: Removed key and added role
Sep 25, 2024
904ac1f
feat: Added and exported usecase DeclineInvitation
Sep 25, 2024
4474415
refactor: Route changed from /invitation to /team
Sep 25, 2024
3b7d6aa
refactor: Removed TeamMember and added IProfileData
Sep 25, 2024
7effa0d
refactor: Route changed from /invitation to /team
Sep 25, 2024
61772c2
feat: API route changed
Sep 25, 2024
2b0fc29
feat: API route changed
Sep 25, 2024
cc9c469
feat: API route changed
Sep 25, 2024
13f60e5
feat: API route changed
Sep 25, 2024
3141272
feat: API route changed
Sep 25, 2024
61efb67
refactor: Utilized React Query Cache
Sep 25, 2024
643a313
refactor: Refactored DeleteTeamMember usecase
Sep 25, 2024
2a59d21
refactor: File names changed
Sep 25, 2024
14f91fb
refactor: Renamed project invitaton to team
Sep 25, 2024
ecff594
feat: Added Invitation Email for sender and Reciever
Sep 25, 2024
ade29ea
refactor: Changed route to team
Sep 25, 2024
bd1cf07
feat: Refactor: Usecase Names changed
Sep 25, 2024
7955608
refactor: Entities and Repositories
Sep 25, 2024
fb13151
feat: Accept and delete invitation and decline invitation Email Added
Sep 25, 2024
7b6ecf8
refactor: Added the member Id
Sep 25, 2024
aa736b5
refactor: Components and Hooks refactored
Sep 25, 2024
4884e77
refactor: Made changes related to TeamMembers and route changed
Sep 25, 2024
fed18f2
feat: Commited all changes from next into current branch
Sep 25, 2024
5d23c45
feat: File Moved or deleted
Sep 26, 2024
2b8205f
fix: Fixed closing of modal
Sep 26, 2024
0c3f728
feat: Renamed ProjectInvitationModal to TeamInvitationModal
Sep 26, 2024
30c02c6
feat: Renamed ProjectInvitationModal to TeamInvitationModal
Sep 26, 2024
a515455
feat: Added isOwner property
Sep 27, 2024
8ebce80
feat: Added isOwner
Sep 27, 2024
6c2846b
feat: Added isOwner to true when environment gets created
Sep 27, 2024
fc65a2e
feat: Fetched meta of TEAM_MEMBER
Sep 27, 2024
10c3198
feat: Added TeamMemberMeta and PaymentAPIService
Sep 27, 2024
7456deb
feat: Added counting of Invitations and throwing subsequent exception…
Sep 27, 2024
b4cf130
feat: Added TeamMemberMeta to get the counting relatd to team members…
Sep 27, 2024
ec243ac
feat: Added isOwner to true in Migration
Sep 27, 2024
7cef522
feat: Added to display the Active plan for the authorised role
Sep 27, 2024
d787632
feat: Added the ability from the context
Sep 27, 2024
c4ee33f
feat: Added useContext and the ability from that
Sep 27, 2024
09adf29
feat: Added Messages while adding more than the team member based on …
Sep 27, 2024
e11a919
feat: Added api roue to handle team-member meta
Sep 27, 2024
df8df6b
feat: Removed exception to check if the added members are 4 and handl…
Sep 27, 2024
0674a53
refactor: Usecase refactored to handle proper error mesages
Sep 27, 2024
89043a4
feat: Removed the duplicate no data available
Sep 27, 2024
e029e59
feat: Added TEAM_MEMBER_META in api key
Sep 27, 2024
7a599d2
feat: Added types to createContext
Sep 27, 2024
a835535
feat: Added TEAM_MEMBERS in meta
Sep 27, 2024
8fcac6d
refactor: Hook refactored to handle errors from backend properly
Sep 27, 2024
28cc5d4
feat: Added isOwner property
Sep 27, 2024
a01e5fc
feat: Adde isOwner in Schema and given default value to false
Sep 27, 2024
e7cf45b
feat: Added ImportsList component
Sep 27, 2024
a19e8a1
feat: Added HOC Higher Order Component
Sep 27, 2024
1e94d41
feat: Exported member HOC
Sep 27, 2024
09280e9
feat: Removed access of role based showing of the imports
Sep 27, 2024
3ce7436
feat: Used HOC based EnhancedImportsList
Sep 27, 2024
62af0c5
feat: Added ability from context
Sep 27, 2024
95ccb2c
feat: Renamed PROJECT_INVITATION_EMAIL to TEAM_INVITATION_EMAIL
Sep 27, 2024
d207cb7
feat: Renamed PROJECT_INVITATION_EMAIL to TEAM_INVITATION_EMAIL
Sep 27, 2024
bc374d1
feat: Added illustration svg if import is not accessible
Sep 27, 2024
e4b3dcb
feat: Added illustration svg if import is not accessible
Sep 27, 2024
5612a30
feat: Added usecase to switch get the owner email and show the plan a…
Sep 27, 2024
a33438a
feat: Added param projectId to get the project based user
Sep 27, 2024
b4c922d
feat: Added param projectId to get the project based user
Sep 27, 2024
330bc83
feat: Added projectId instead of email
Sep 27, 2024
ef8c2e8
fix: Changing of project
Sep 27, 2024
10305d3
feat: Added projectId instead of email
Sep 27, 2024
15ccbbe
feat: Returned undefined in case of project create and switch to it
Sep 27, 2024
2c62677
feat: Added ${projectId} as a param in fetch active subscription api
Sep 27, 2024
cc1e09f
feat: Added TEAM_MEMBERS: number in meta
Sep 27, 2024
c80754b
feat: Added method getTeamOwnerDetails to fetch the details of teamme…
Sep 27, 2024
c1fbab1
feat: Added billable metrics in meta
Sep 27, 2024
5039f58
feat: Added default import and export for build issue
Sep 27, 2024
acf1c66
feat: Removed return declaration in getProjects
Oct 4, 2024
71bcc23
feat: Reoved return defination in execute
Oct 4, 2024
f3ebb1c
feat: Added default red color to DeleteIcon
Oct 4, 2024
35f9bee
feat: Added EditImportIcon
Oct 4, 2024
5f01771
feat: Added SwapIcon
Oct 4, 2024
9ec5950
feat: Added Button from @ui/button
Oct 4, 2024
a2c031e
feat: Exported member List and corresponding List styles
Oct 4, 2024
47bffa7
feat: Added List Styles
Oct 4, 2024
1a45166
feat: Added List as the custom component for viewing Tabular data but…
Oct 4, 2024
5f58de3
feat: Added ConfirmDeleteProjectModal
Oct 4, 2024
6ef58f9
feat: Exported member ManageProjectModal and ConfirmDeleteProject
Oct 4, 2024
afc6575
feat: Added component ManageProjectModal
Oct 4, 2024
35378d5
feat: New keys added
Oct 4, 2024
fe74c64
feat: Dark blue colour added
Oct 4, 2024
e6ef07e
feat: Removed Select and used Unstylized button
Oct 4, 2024
d5407df
feat: Added PROJECT_DELETE API
Oct 4, 2024
220f9d8
feat: REnamed clip-path to clipPath
Oct 4, 2024
19a6b41
feat: Added isOwner in getApiKeyForUserId
Oct 4, 2024
58e73d8
feat: Added booleal property isOwner in IProjectPayload
Oct 4, 2024
67b0e1c
feat: Added apiKeys to extract the apiKeys array in getUserEnvironmen…
Oct 4, 2024
77434d6
feat: Added Type parameter to list
Oct 4, 2024
23d67bb
feat: Changed clip-path to clipPath
Oct 4, 2024
6cfa1f0
feat: Added profile to profileInfo
Oct 4, 2024
8028c2c
feat: Removed grid and other styling
Oct 4, 2024
27001ed
feat: Added th and related styling
Oct 4, 2024
f8c15b2
feat: Added cell width and Badges for user
Oct 4, 2024
03a355e
feat: Added profileInfo
Oct 4, 2024
e414d28
feat: Changed profile to profileInfo
Oct 4, 2024
885a246
feat: Added colors to Badges
Oct 4, 2024
f1f345d
feat: Added darkBlue color
Oct 4, 2024
87a0e05
feat: Deleted useApp
Oct 4, 2024
4dd3206
feat: Added profileInfo
Oct 4, 2024
86948d2
feat: Added Hook for project listing, deleting and creating
Oct 4, 2024
9cef672
feat: Added profileInfo from useAppState
Oct 4, 2024
332e6ed
feat: Added UnstyledButton inplace of Select
Oct 4, 2024
c99c83f
feat: Added profileInfo from useAppState
Oct 4, 2024
981406c
feat: FIxed Hydration Issue
Oct 4, 2024
1373c72
feat: Fixed issue of name was not defined
Oct 4, 2024
3c003af
feat: Added role type as UserRolesEnum
Oct 4, 2024
c7a47ed
feat: Merged next
chavda-bhavik Oct 18, 2024
d19c737
fix: Migration
chavda-bhavik Oct 18, 2024
bdf5c35
feat: Renamed delete-team-member to remove-team-member and renamed ma…
chavda-bhavik Oct 19, 2024
4c4a581
feat: Revised icons and list styling
chavda-bhavik Oct 19, 2024
aad9718
feat: Refreshed team members on project change
chavda-bhavik Oct 19, 2024
b272a69
feat: Made Imports Page protected and respected DOM elements order in…
chavda-bhavik Oct 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@
"main": ".eslintrc.js",
"keywords": [],
"description": ""
}
}
2 changes: 2 additions & 0 deletions apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { EnvironmentModule } from './app/environment/environment.module';
import { ActivityModule } from './app/activity/activity.module';
import { UserModule } from './app/user/user.module';
import { ImportJobsModule } from 'app/import-jobs/import-jobs.module';
import { TeamModule } from 'app/team/team.module';

const modules: Array<Type | DynamicModule | Promise<DynamicModule> | ForwardReference> = [
ProjectModule,
Expand All @@ -31,6 +32,7 @@ const modules: Array<Type | DynamicModule | Promise<DynamicModule> | ForwardRefe
EnvironmentModule,
ActivityModule,
ImportJobsModule,
TeamModule,
];

const providers = [Logger];
Expand Down
36 changes: 19 additions & 17 deletions apps/api/src/app/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
UseInterceptors,
} from '@nestjs/common';

import { IJwtPayload } from '@impler/shared';
import { constructQueryString, IJwtPayload, UserRolesEnum } from '@impler/shared';
import { AuthService } from './services/auth.service';
import { IStrategyResponse } from '@shared/types/auth.types';
import { CONSTANTS, COOKIE_CONFIG } from '@shared/constants';
Expand All @@ -37,8 +37,6 @@ import {
OnboardUser,
RegisterUser,
ResetPassword,
LoginUserCommand,
RegisterUserCommand,
ResetPasswordCommand,
RequestForgotPassword,
RequestForgotPasswordCommand,
Expand Down Expand Up @@ -76,7 +74,10 @@ export class AuthController {

@Get('/github/callback')
@UseGuards(AuthGuard('github'))
async githubCallback(@StrategyUser() strategyUser: IStrategyResponse, @Res() response: Response) {
async githubCallback(
@Res({ passthrough: true }) response: Response,
@StrategyUser() strategyUser: IStrategyResponse
) {
if (!strategyUser || !strategyUser.token) {
return response.redirect(`${process.env.WEB_BASE_URL}/auth/signin?error=AuthenticationError`);
}
Expand All @@ -88,11 +89,7 @@ export class AuthController {
if (strategyUser.showAddProject) {
queryObj.showAddProject = true;
}
for (const key in queryObj) {
if (queryObj.hasOwnProperty(key)) {
url += `${url.includes('?') ? '&' : '?'}${key}=${queryObj[key]}`;
}
}
url += constructQueryString(queryObj);

response.cookie(CONSTANTS.AUTH_COOKIE_NAME, strategyUser.token, {
...COOKIE_CONFIG,
Expand Down Expand Up @@ -133,7 +130,7 @@ export class AuthController {

@Post('/register')
async register(@Body() body: RegisterUserDto, @Res() response: Response) {
const registeredUser = await this.registerUser.execute(RegisterUserCommand.create(body));
const registeredUser = await this.registerUser.execute(body);

response.cookie(CONSTANTS.AUTH_COOKIE_NAME, registeredUser.token, {
...COOKIE_CONFIG,
Expand Down Expand Up @@ -170,15 +167,21 @@ export class AuthController {
},
user.email
);

const userApiKey = projectWithEnvironment.environment.apiKeys.find(
(apiKey) => apiKey._userId.toString() === user._id
);

const token = this.authService.getSignedToken(
{
_id: user._id,
firstName: user.firstName,
lastName: user.lastName,
email: user.email,
role: userApiKey.role as UserRolesEnum,
profilePicture: user.profilePicture,
isEmailVerified: user.isEmailVerified,
accessToken: projectWithEnvironment.environment.apiKeys[0].key,
accessToken: projectWithEnvironment.environment.key,
},
projectWithEnvironment.project._id
);
Expand All @@ -192,12 +195,11 @@ export class AuthController {

@Post('/login')
async login(@Body() body: LoginUserDto, @Res() response: Response) {
const loginUser = await this.loginUser.execute(
LoginUserCommand.create({
email: body.email,
password: body.password,
})
);
const loginUser = await this.loginUser.execute({
email: body.email,
password: body.password,
invitationId: body.invitationId,
});

response.cookie(CONSTANTS.AUTH_COOKIE_NAME, loginUser.token, {
...COOKIE_CONFIG,
Expand Down
9 changes: 8 additions & 1 deletion apps/api/src/app/auth/dtos/login-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsDefined, IsString, IsEmail } from 'class-validator';
import { IsDefined, IsString, IsEmail, IsOptional } from 'class-validator';

export class LoginUserDto {
@ApiProperty({
Expand All @@ -15,4 +15,11 @@ export class LoginUserDto {
@IsString()
@IsDefined()
password: string;

@ApiProperty({
description: 'InvitationId to accept invitation later on',
})
@IsString()
@IsOptional()
invitationId?: string;
}
9 changes: 8 additions & 1 deletion apps/api/src/app/auth/dtos/register-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsDefined, IsString, IsEmail } from 'class-validator';
import { IsDefined, IsString, IsEmail, IsOptional } from 'class-validator';

export class RegisterUserDto {
@ApiProperty({
Expand Down Expand Up @@ -29,4 +29,11 @@ export class RegisterUserDto {
@IsString()
@IsDefined()
password: string;

@ApiProperty({
description: 'InvitationId to accept invitation later on',
})
@IsString()
@IsOptional()
invitationId?: string;
}
27 changes: 9 additions & 18 deletions apps/api/src/app/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as bcrypt from 'bcryptjs';
import { JwtService } from '@nestjs/jwt';
import { Injectable, UnauthorizedException } from '@nestjs/common';

import { IJwtPayload } from '@impler/shared';
import { IJwtPayload, UserRolesEnum } from '@impler/shared';
import { CONSTANTS, LEAD_SIGNUP_USING } from '@shared/constants';
import { UserEntity, UserRepository, EnvironmentRepository } from '@impler/dal';
import { UserNotFoundException } from '@shared/exceptions/user-not-found.exception';
Expand Down Expand Up @@ -31,6 +31,7 @@ export class AuthService {
lastName: profile.lastName,
signupMethod: LEAD_SIGNUP_USING.GITHUB,
profilePicture: profile.avatar_url,
role: UserRolesEnum.ADMIN,
...(provider ? { tokens: [provider] } : {}),
};
user = await this.userRepository.create(userObj);
Expand All @@ -54,6 +55,7 @@ export class AuthService {
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
role: apiKey?.role as UserRolesEnum,
profilePicture: user.profilePicture,
accessToken: apiKey?.apiKey,
isEmailVerified: user.isEmailVerified,
Expand Down Expand Up @@ -89,6 +91,7 @@ export class AuthService {
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
role: apiKey.role as UserRolesEnum,
accessToken: apiKey?.apiKey,
isEmailVerified: user.isEmailVerified,
},
Expand All @@ -109,6 +112,7 @@ export class AuthService {
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
role: apiKey.role as UserRolesEnum,
accessToken: apiKey?.apiKey,
isEmailVerified: user.isEmailVerified,
},
Expand All @@ -122,6 +126,7 @@ export class AuthService {
firstName: string;
lastName: string;
email: string;
role?: UserRolesEnum;
isEmailVerified: boolean;
profilePicture?: string;
accessToken?: string;
Expand All @@ -134,6 +139,7 @@ export class AuthService {
{
_id: user._id,
_projectId,
role: user.role,
firstName: user.firstName,
lastName: user.lastName,
email: user.email,
Expand Down Expand Up @@ -173,23 +179,7 @@ export class AuthService {
const environment = await this.environmentRepository.findByApiKey(apiKey);
if (!environment) throw new UnauthorizedException('API Key not found!');

const key = environment.apiKeys.find((i) => i.key === apiKey);
if (!key) throw new UnauthorizedException('API Key not found!');

const user = await this.getUser({ _id: key._userId });
if (!user) throw new UnauthorizedException('User not found!');

return this.getSignedToken(
{
_id: user._id,
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
accessToken: apiKey,
isEmailVerified: user.isEmailVerified,
},
environment._projectId
);
if (apiKey !== environment.key) throw new UnauthorizedException('API Key not found!');
}

async generateUserToken(user: UserEntity) {
Expand All @@ -201,6 +191,7 @@ export class AuthService {
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
role: apiKey.role as UserRolesEnum,
accessToken: apiKey?.apiKey,
isEmailVerified: user.isEmailVerified,
},
Expand Down
10 changes: 1 addition & 9 deletions apps/api/src/app/auth/usecases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { RequestForgotPassword } from './request-forgot-password/request-forgot-

import { Verify } from './verify/verify.usecase';
import { ResendOTP } from './resend-otp/resend-otp.usecase';
import { LoginUserCommand } from './login-user/login-user.command';
import { OnboardUserCommand } from './onboard-user/onboard-user.command';
import { RegisterUserCommand } from './register-user/register-user.command';
import { ResetPasswordCommand } from './reset-password/reset-password.command';
import { RequestForgotPasswordCommand } from './request-forgot-password/request-forgot-pasword.command';

Expand Down Expand Up @@ -38,11 +36,5 @@ export const USE_CASES = [
//
];

export { OnboardUserCommand, ResetPasswordCommand, RequestForgotPasswordCommand };
export { Verify, RegisterUser, LoginUser, RequestForgotPassword, ResetPassword, OnboardUser, ResendOTP, UpdateUser };
export {
LoginUserCommand,
OnboardUserCommand,
RegisterUserCommand,
ResetPasswordCommand,
RequestForgotPasswordCommand,
};
11 changes: 2 additions & 9 deletions apps/api/src/app/auth/usecases/login-user/login-user.command.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { IsDefined, IsEmail, IsString } from 'class-validator';
import { BaseCommand } from '@shared/commands/base.command';

export class LoginUserCommand extends BaseCommand {
@IsEmail()
@IsDefined()
export class LoginUserCommand {
email: string;

@IsString()
@IsDefined()
password: string;
invitationId?: string;
}
10 changes: 8 additions & 2 deletions apps/api/src/app/auth/usecases/login-user/login-user.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EmailService } from '@impler/services';
import { LoginUserCommand } from './login-user.command';
import { AuthService } from '../../services/auth.service';
import { EnvironmentRepository, UserRepository } from '@impler/dal';
import { EMAIL_SUBJECT, SCREENS } from '@impler/shared';
import { EMAIL_SUBJECT, SCREENS, UserRolesEnum } from '@impler/shared';
import { generateVerificationCode } from '@shared/helpers/common.helper';

@Injectable()
Expand Down Expand Up @@ -59,14 +59,20 @@ export class LoginUser {

const apiKey = await this.environmentRepository.getApiKeyForUserId(user._id);

let screen = SCREENS.ONBOARD;
if (command.invitationId) screen = SCREENS.INVIATAION;
else if (!user.isEmailVerified) screen = SCREENS.VERIFY;
else if (apiKey) screen = SCREENS.HOME;

return {
screen: !user.isEmailVerified ? SCREENS.VERIFY : apiKey ? SCREENS.HOME : SCREENS.ONBOARD,
screen,
token: this.authService.getSignedToken(
{
_id: user._id,
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
role: apiKey?.role as UserRolesEnum,
profilePicture: user.profilePicture,
accessToken: apiKey?.apiKey,
isEmailVerified: user.isEmailVerified,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
import { IsDefined, IsEmail, IsString } from 'class-validator';
import { BaseCommand } from '@shared/commands/base.command';

export class RegisterUserCommand extends BaseCommand {
@IsString()
@IsDefined()
export class RegisterUserCommand {
firstName: string;

@IsString()
@IsDefined()
lastName: string;

@IsEmail()
@IsDefined()
email: string;

@IsString()
@IsDefined()
password: string;
invitationId?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { UserRepository } from '@impler/dal';

import { EmailService } from '@impler/services';
import { LEAD_SIGNUP_USING } from '@shared/constants';
import { SCREENS, EMAIL_SUBJECT } from '@impler/shared';
import { SCREENS, EMAIL_SUBJECT, UserRolesEnum } from '@impler/shared';
import { AuthService } from 'app/auth/services/auth.service';
import { RegisterUserCommand } from './register-user.command';
import { generateVerificationCode } from '@shared/helpers/common.helper';
Expand All @@ -29,6 +29,7 @@ export class RegisterUser {

const passwordHash = await bcrypt.hash(command.password, 10);
const verificationCode = generateVerificationCode();
const isEmailVerified = command.invitationId ? true : this.emailService.isConnected() ? false : true;

const user = await this.userRepository.create({
email: command.email,
Expand All @@ -37,17 +38,25 @@ export class RegisterUser {
password: passwordHash,
signupMethod: LEAD_SIGNUP_USING.EMAIL,
verificationCode,
isEmailVerified: this.emailService.isConnected() ? false : true,
isEmailVerified,
});

const token = this.authService.getSignedToken({
_id: user._id,
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
role: user.role as UserRolesEnum,
isEmailVerified: user.isEmailVerified,
});

if (command.invitationId) {
return {
screen: SCREENS.INVIATAION,
token,
};
}

if (this.emailService.isConnected()) {
const emailContents = this.emailService.getEmailContent({
type: 'VERIFICATION_EMAIL',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { UserRepository } from '@impler/dal';
import { EMAIL_SUBJECT } from '@impler/shared';
import { EMAIL_SUBJECT, UserRolesEnum } from '@impler/shared';
import { EmailService } from '@impler/services';
import { UpdateUserCommand } from './update-user.command';
import { AuthService } from 'app/auth/services/auth.service';
Expand Down Expand Up @@ -56,6 +56,7 @@ export class UpdateUser {
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
role: user.role as UserRolesEnum,
isEmailVerified: user.isEmailVerified,
});

Expand Down
Loading
Loading