-
Notifications
You must be signed in to change notification settings - Fork 1
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
Move validations done in the user controllers into DTO #459
Changes from 8 commits
3774592
ef47850
320a59a
02faab5
b705b69
f4e6e64
302849c
1724fd1
b694a16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ import { Permission } from '../permission/decorators/permission.decorator'; | |
import { ACLModules } from '../access-control-layer-module-service/decorator/aclModule.decorator'; | ||
import { Roles } from './decorators/roles.decorator'; | ||
import { Role } from '../../utils/enums'; | ||
import { IsEmail } from 'class-validator'; | ||
|
||
@ApiTags('user') | ||
@ApiBearerAuth('access-token') | ||
|
@@ -127,35 +128,6 @@ export class UserController { | |
@Req() request: Request, | ||
): Promise<UserDTO> { | ||
const user = request.user; | ||
if ( | ||
userRegistrationData.organizationType === '' || | ||
userRegistrationData.organizationType === null || | ||
userRegistrationData.organizationType === undefined | ||
) { | ||
throw new ConflictException({ | ||
success: false, | ||
message: `organizationType should not be empty`, | ||
}); | ||
} | ||
if ( | ||
userRegistrationData.organizationType.toLowerCase() != | ||
'Buyer'.toLowerCase() && | ||
userRegistrationData.organizationType.toLowerCase() != | ||
'Developer'.toLowerCase() && | ||
userRegistrationData.organizationType.toLowerCase() != | ||
'ApiUser'.toLowerCase() | ||
) { | ||
throw new ConflictException({ | ||
success: false, | ||
message: `organizationType value should be Developer/Buyer/ApiUser`, | ||
}); | ||
} | ||
Comment on lines
-140
to
-152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This validation is not implemented because when I send an organizationType with Example |
||
if (userRegistrationData.orgName.trim() === '') { | ||
throw new ConflictException({ | ||
success: false, | ||
message: `orgName should not be empty`, | ||
}); | ||
} | ||
Comment on lines
-153
to
-158
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This validation is not done because if I send an empty string with space inside it I don't get any error and the response becomes successful. |
||
if (!userRegistrationData.api_user_id) { | ||
userRegistrationData.api_user_id = (user as any).api_user_id; | ||
} | ||
|
@@ -233,14 +205,13 @@ export class UserController { | |
@Param('token') token: IEmailConfirmationToken['token'], | ||
@Body() body: UpdateChangePasswordDTO, | ||
): Promise<UserDTO> { | ||
const emailregex = | ||
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}))$/; | ||
let emailConfirmation: any; | ||
if (emailregex.test(token)) { | ||
emailConfirmation = await this.userService.findOne({ email: token }); | ||
if (IsEmail(token)) { | ||
const emailConfirmation = await this.userService.findOne({ | ||
email: token, | ||
}); | ||
return this.userService.changePassword(emailConfirmation, body); | ||
} else { | ||
emailConfirmation = await this.emailConfirmationService.findOne({ | ||
const emailConfirmation = await this.emailConfirmationService.findOne({ | ||
token, | ||
}); | ||
if (!emailConfirmation) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { applyDecorators } from '@nestjs/common'; | ||
import { Transform } from 'class-transformer'; | ||
|
||
export const Trim = (): PropertyDecorator => | ||
applyDecorators(Transform((value?: string) => value?.trim())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you have removed the validation to check if the organization type matches certain values and this validation wasn't added to the DTO