Skip to content

Commit

Permalink
Merge pull request #11 from poojakarma/change_status_code
Browse files Browse the repository at this point in the history
resolve internal server error when isQueue true
  • Loading branch information
vaivk369 authored Sep 2, 2024
2 parents cc98420 + e3979a0 commit c8a742b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/modules/notification/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export class NotificationService {
results.forEach((result, index) => {
const channel = ['email', 'sms', 'push'][index];
if (result.status === 'fulfilled') {
result.value.forEach(notification => {
const notifications = Array.isArray(result.value) ? result.value : [result.value];
notifications.forEach(notification => {
// result.value.forEach(notification => {
if (notification.status === 200) {
serverResponses[channel].data.push(notification);
} else {
Expand All @@ -113,10 +115,15 @@ export class NotificationService {
}
});
// Filter out channels with empty data and errors arrays
// const finalResponses = Object.fromEntries(
// Object.entries(serverResponses).filter(([channel, { data, errors }]) => data.length > 0 || errors.length > 0 || errors.length > 0)
// );
// Filter out channels with empty data and errors arrays
const finalResponses = Object.fromEntries(
Object.entries(serverResponses).filter(([channel, { data, errors }]) => data.length > 0 || errors.length > 0 || errors.length > 0)
Object.entries(serverResponses).filter(([_, { data, errors }]) => data.length > 0 || errors.length > 0)
);


return APIResponse.success(
response,
apiId,
Expand Down Expand Up @@ -184,7 +191,7 @@ export class NotificationService {
if (saveQueue.length === 0) {
throw new Error('Failed to save notifications in queue');
}
return { success: true, message: 'Notification saved in queued successfully' };
return { status: 200, message: 'Notification saved in queue successfully' };
} catch (error) {
this.logger.error('Error to save notifications in queue', error);
throw new Error('Failed to save notifications in queue');
Expand Down

0 comments on commit c8a742b

Please sign in to comment.