-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Xitija/main
PS- 1589 Validate meeting links as per provider
- Loading branch information
Showing
4 changed files
with
58 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
ValidatorConstraint, | ||
ValidatorConstraintInterface, | ||
ValidationArguments, | ||
} from 'class-validator'; | ||
|
||
function validateMeetingUrl(url, provider) { | ||
const providerPatterns = { | ||
zoom: /^https:\/\/[\w-]*\.?zoom.us\/(j|my)\/[\d\w?=-]+$/, | ||
googlemeet: /^(https:\/\/)?meet\.google\.com\/[a-zA-Z0-9-]+$/, | ||
// microsoftteams: /^(https:\/\/)?teams\.microsoft\.com\/[a-zA-Z0-9?&=]+$/, | ||
// Add other supported providers as needed | ||
}; | ||
if ( | ||
!url || | ||
typeof url !== 'string' || | ||
!provider || | ||
typeof provider !== 'string' | ||
) { | ||
return false; | ||
} | ||
|
||
const pattern = providerPatterns[provider.toLowerCase()]; | ||
if (!pattern) { | ||
return false; // Unsupported provider | ||
} | ||
|
||
return pattern.test(url); | ||
} | ||
|
||
@ValidatorConstraint({ name: 'urlWithProviderValidator', async: false }) | ||
export class UrlWithProviderValidator implements ValidatorConstraintInterface { | ||
validate(url: string, args: ValidationArguments) { | ||
const { onlineProvider } = args.object as any; | ||
return validateMeetingUrl(url, onlineProvider); | ||
} | ||
|
||
defaultMessage(args: ValidationArguments) { | ||
return 'Invalid meeting URL for the specified provider!'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters