fix issues in core
This commit is contained in:
@@ -61,27 +61,27 @@ export class CreateSponsorUseCase {
|
||||
}
|
||||
}
|
||||
|
||||
private validate(command: CreateSponsorCommand): Result<void, ApplicationErrorCode<'VALIDATION_ERROR', { message: string }>> {
|
||||
this.logger.debug('Validating CreateSponsorCommand', { command });
|
||||
if (!command.name || command.name.trim().length === 0) {
|
||||
this.logger.warn('Validation failed: Sponsor name is required', { command });
|
||||
private validate(input: CreateSponsorInput): Result<void, ApplicationErrorCode<'VALIDATION_ERROR', { message: string }>> {
|
||||
this.logger.debug('Validating CreateSponsorInput', { input });
|
||||
if (!input.name || input.name.trim().length === 0) {
|
||||
this.logger.warn('Validation failed: Sponsor name is required', { input });
|
||||
return Result.err({ code: 'VALIDATION_ERROR', details: { message: 'Sponsor name is required' } });
|
||||
}
|
||||
if (!command.contactEmail || command.contactEmail.trim().length === 0) {
|
||||
this.logger.warn('Validation failed: Sponsor contact email is required', { command });
|
||||
if (!input.contactEmail || input.contactEmail.trim().length === 0) {
|
||||
this.logger.warn('Validation failed: Sponsor contact email is required', { input });
|
||||
return Result.err({ code: 'VALIDATION_ERROR', details: { message: 'Sponsor contact email is required' } });
|
||||
}
|
||||
// Basic email validation
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (!emailRegex.test(command.contactEmail)) {
|
||||
this.logger.warn('Validation failed: Invalid sponsor contact email format', { command });
|
||||
if (!emailRegex.test(input.contactEmail)) {
|
||||
this.logger.warn('Validation failed: Invalid sponsor contact email format', { input });
|
||||
return Result.err({ code: 'VALIDATION_ERROR', details: { message: 'Invalid sponsor contact email format' } });
|
||||
}
|
||||
if (command.websiteUrl && command.websiteUrl.trim().length > 0) {
|
||||
if (input.websiteUrl && input.websiteUrl.trim().length > 0) {
|
||||
try {
|
||||
new URL(command.websiteUrl);
|
||||
new URL(input.websiteUrl);
|
||||
} catch {
|
||||
this.logger.warn('Validation failed: Invalid sponsor website URL', { command });
|
||||
this.logger.warn('Validation failed: Invalid sponsor website URL', { input });
|
||||
return Result.err({ code: 'VALIDATION_ERROR', details: { message: 'Invalid sponsor website URL' } });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user