Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ coverage
# Misc
*.bak
*.tmp

#push token test
index.html
OneSignalSDK.sw.js
OneSignalSDKWorker.js
3 changes: 0 additions & 3 deletions api-gateway/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ async function fetchWithRetry(url: string, retries = 5, delay = 2000) {
const response = await axios.get(url, { timeout: 5000 });
return response.data;
} catch (error) {
console.log(`Attempt ${i + 1} failed for ${url}. Retrying...`);
if (i === retries - 1) throw error;
await new Promise((resolve) => setTimeout(resolve, delay));
}
Expand Down Expand Up @@ -48,10 +47,8 @@ async function bootstrap() {

for (const service of services) {
try {
console.log(`Fetching ${service.name}...`);
const doc = await fetchWithRetry(service.url);
SwaggerModule.setup(service.path, app, doc);
console.log(`✓ ${service.name} docs available at /${service.path}`);
} catch (error) {
console.error(`✗ Failed to fetch ${service.name}:`, error.message);
}
Expand Down
31 changes: 0 additions & 31 deletions api-gateway/src/notification/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,10 @@ export class NotificationService {
user: any,
): Promise<ApiResponse<any>> {
try {
console.log('=== NOTIFICATION REQUEST START ===');
console.log('User:', user);
console.log('DTO:', dto);

// Check for duplicate
console.log('Checking duplicate for request_id:', dto.request_id);
const isDuplicate = await this.redisService.checkDuplicate(
dto.request_id,
);
if (isDuplicate) {
console.log('Duplicate detected!');
const existingNotificationId =
await this.redisService.getRequestMapping(dto.request_id);
return {
Expand All @@ -55,15 +48,12 @@ export class NotificationService {
// Validate user
const userServiceUrl =
process.env.USER_SERVICE_URL || 'http://localhost:3001';
console.log('USER_SERVICE_URL:', userServiceUrl);
console.log('Fetching user:', dto.user_id);

let userResponse;
try {
userResponse = await firstValueFrom(
this.httpService.get(`${userServiceUrl}/api/v1/users/${dto.user_id}`),
);
console.log('User fetched successfully:', userResponse.data);
} catch (error: any) {
console.error('❌ USER SERVICE ERROR:', error.message);
console.error('Error details:', error.response?.data || error);
Expand All @@ -76,24 +66,18 @@ export class NotificationService {
}

const targetUser = userResponse.data.data;
console.log('Target user:', targetUser);

// Check authorization
console.log('Checking authorization:', user.userId, 'vs', dto.user_id);
if (user.userId !== dto.user_id) {
console.error('Authorization failed!');
throw new ForbiddenException(
'You can only send notifications to yourself',
);
}

// Check preferences
console.log('Checking user preferences:', targetUser.preferences);
if (
dto.notification_type === NotificationType.EMAIL &&
!targetUser.preferences.email
) {
console.log('User has disabled email notifications');
return {
success: false,
message: 'User has disabled email notifications',
Expand All @@ -103,8 +87,6 @@ export class NotificationService {
// Get template
const templateServiceUrl =
process.env.TEMPLATE_SERVICE_URL || 'http://localhost:3004';
console.log('TEMPLATE_SERVICE_URL:', templateServiceUrl);
console.log('Fetching template:', dto.template_code);

let templateResponse;
try {
Expand All @@ -113,7 +95,6 @@ export class NotificationService {
`${templateServiceUrl}/api/v1/templates/${dto.template_code}`,
),
);
console.log('Template fetched successfully:', templateResponse.data);
} catch (error: any) {
console.error('❌ TEMPLATE SERVICE ERROR:', error.message);
console.error('Error details:', error.response?.data || error);
Expand All @@ -127,7 +108,6 @@ export class NotificationService {

// Generate notification ID
const notificationId = uuidv4();
console.log('Generated notification_id:', notificationId);

// Prepare message
const message = {
Expand All @@ -141,39 +121,28 @@ export class NotificationService {
metadata: dto.metadata,
timestamp: new Date().toISOString(),
};
console.log('Message prepared:', message);

// Route to queue
const queue =
dto.notification_type === NotificationType.EMAIL
? 'email.queue'
: 'push.queue';
console.log('Publishing to queue:', queue);

try {
await this.circuitBreaker.execute(async () => {
await this.rabbitMQService.publishToQueue(queue, message);
}, 'rabbitmq');
console.log('✅ Message published to queue successfully');
} catch (error: any) {
console.error('❌ RABBITMQ ERROR:', error.message);
throw new Error(`Failed to publish to queue: ${error.message}`);
}

// Mark as processed
console.log('Marking request as processed');
await this.redisService.markProcessed(dto.request_id, notificationId);

// Store status
console.log('Storing initial status');
await this.redisService.setStatus(notificationId, {
status: NotificationStatus.PENDING,
created_at: new Date().toISOString(),
notification_type: dto.notification_type,
user_id: dto.user_id,
});

console.log('=== NOTIFICATION REQUEST SUCCESS ===');
return {
success: true,
message: 'Notification queued successfully',
Expand Down
1 change: 0 additions & 1 deletion api-gateway/src/notification/rabbitmq.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class RabbitMQService implements OnModuleInit, OnModuleDestroy {
});

await this.channelWrapper.waitForConnect();
console.log('RabbitMQ connected');
}

async publishToQueue(
Expand Down
2 changes: 1 addition & 1 deletion email_service/src/email/email.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import { EmailService } from './email.service';
imports: [HttpModule],
providers: [EmailService],
})
export class EmailModule {}
export class EmailModule {}
Loading