Skip to content

Commit

Permalink
updated logger messges
Browse files Browse the repository at this point in the history
  • Loading branch information
poojakarma committed Nov 27, 2024
1 parent 74590c5 commit 9174ff5
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
6 changes: 2 additions & 4 deletions src/common/filters/exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export class AllExceptionsFilter implements ExceptionFilter {
let errorMessage =
exception?.message || ERROR_MESSAGES.INTERNAL_SERVER_ERROR;

LoggerUtil.error(`Error occurred on API: ${request.url} Method : ${request.method}`,
errorMessage, 'Notification Service', `requested by userId: ${userId}`,
LoggerUtil.error(errorMessage, `Error occurred on API: ${request.url} Method : ${request.method}`, 'Notification Service', `requested by userId: ${userId}`,
)

if (exception instanceof HttpException) {
Expand All @@ -51,9 +50,8 @@ export class AllExceptionsFilter implements ExceptionFilter {
statusCode.toString(),
);
LoggerUtil.error(`Database Query Failed on API: ${request.url} requested by userId: ${userId}`,
request.method,
(exception as QueryFailedError).message,
'QueryFailedError')
'Notification Service', `${userId}`)

return response.status(statusCode).json(errorResponse);
}
Expand Down
3 changes: 1 addition & 2 deletions src/modules/notification/adapters/emailService.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ export class EmailAdapter implements NotificationServiceInterface {
if (result.status === 'success') {
notificationLogs.status = true;
await this.notificationServices.saveNotificationLogs(notificationLogs);
LoggerUtil.error(SUCCESS_MESSAGES.EMAIL_NOTIFICATION_SEND_SUCCESSFULLY);
LoggerUtil.log(SUCCESS_MESSAGES.EMAIL_NOTIFICATION_SEND_SUCCESSFULLY);
return result;
}

else {
throw new Error(`Email not send ${JSON.stringify(result.errors)}`)
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/notification/adapters/pushService.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class PushAdapter implements NotificationServiceInterface {
});

if (result.status === 200 && result.data.name) {
LoggerUtil.error(SUCCESS_MESSAGES.PUSH_NOTIFICATION_SEND_SUCCESSFULLY);
LoggerUtil.log(SUCCESS_MESSAGES.PUSH_NOTIFICATION_SEND_SUCCESSFULLY);
notificationLogs.status = true;
await this.notificationServices.saveNotificationLogs(notificationLogs);
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/notification/adapters/smsService.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class SmsAdapter implements NotificationServiceInterface {
to: `+91${notificationData.recipient}`,
body: notificationData.body,
});
LoggerUtil.error(SUCCESS_MESSAGES.SMS_NOTIFICATION_SEND_SUCCESSFULLY);
LoggerUtil.log(SUCCESS_MESSAGES.SMS_NOTIFICATION_SEND_SUCCESSFULLY);
notificationLogs.status = true;
await this.notificationServices.saveNotificationLogs(notificationLogs);
return message;
Expand Down
16 changes: 10 additions & 6 deletions src/modules/notification/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class NotificationService {
// Check if notification template exists
const notification_event = await this.notificationActions.findOne({ where: { context, key } });
if (!notification_event) {
LoggerUtil.log(apiId, SUCCESS_MESSAGES.UPDATE_TEMPLATE_API, ERROR_MESSAGES.TEMPLATE_NOT_EXIST, userId);
LoggerUtil.error(`template not found with this ${context} and ${key}`, ERROR_MESSAGES.TEMPLATE_NOTFOUND, apiId, userId);
throw new BadRequestException(ERROR_MESSAGES.TEMPLATE_NOTFOUND);
}

Expand Down Expand Up @@ -137,7 +137,12 @@ export class NotificationService {
.status(HttpStatus.OK)
.json(APIResponse.success(apiId, finalResponses, 'OK'));
} catch (e) {
LoggerUtil.error(apiId, SUCCESS_MESSAGES.UPDATE_TEMPLATE_API, ERROR_MESSAGES.TEMPLATE_NOT_EXIST, userId);
LoggerUtil.error(
`Error: ${e}`,
e,
apiId,
userId
);
throw e;
}
}
Expand All @@ -146,7 +151,7 @@ export class NotificationService {
if (recipients && recipients.length > 0 && Object.keys(recipients).length > 0) {
const notification_details = await this.notificationActionTemplates.find({ where: { actionId: notification_event.actionId, type } });
if (notification_details.length === 0) {
LoggerUtil.error(`/Send ${channel} Notification`, SUCCESS_MESSAGES.UPDATE_TEMPLATE_API, ERROR_MESSAGES.TEMPLATE_NOT_EXIST, userId);
LoggerUtil.error(ERROR_MESSAGES.TEMPLATE_CONFIG_NOTFOUND, `/Send ${channel} Notification`, userId);
throw new BadRequestException(`${ERROR_MESSAGES.TEMPLATE_CONFIG_NOTFOUND} ${type}`);
}
let bodyText;
Expand Down Expand Up @@ -198,7 +203,7 @@ export class NotificationService {
}
return { status: 200, message: SUCCESS_MESSAGES.NOTIFICATION_QUEUE_SAVE_SUCCESSFULLY };
} catch (error) {
LoggerUtil.error('/send', SUCCESS_MESSAGES.UPDATE_TEMPLATE_API, ERROR_MESSAGES.TEMPLATE_NOT_EXIST, userId);
LoggerUtil.error(ERROR_MESSAGES.NOTIFICATION_QUEUE_SAVE_FAILED, error, 'Saving in Qaueue', userId);
throw new Error(ERROR_MESSAGES.NOTIFICATION_QUEUE_SAVE_FAILED);
}
} else {
Expand Down Expand Up @@ -228,7 +233,6 @@ export class NotificationService {
// Function to validate that all placeholders have corresponding replacements
validatePlaceholders(placeholders: string[], replacements: { [key: string]: string }): void {
const missingReplacements = placeholders.filter((placeholder) => !replacements.hasOwnProperty(placeholder));

if (missingReplacements.length > 0) {
throw new BadRequestException(`Missing replacements for placeholders: ${missingReplacements.join(', ')}`);
}
Expand Down Expand Up @@ -359,7 +363,7 @@ export class NotificationService {
await this.notificationLogRepository.save(notificationLogs);
}
catch (e) {
LoggerUtil.error(SUCCESS_MESSAGES.SAVE_NOTIFICATION_LOG, `error ${e}`, ERROR_MESSAGES.NOTIFICATION_LOG_SAVE_FAILED);
LoggerUtil.error(`error ${e}`, ERROR_MESSAGES.NOTIFICATION_LOG_SAVE_FAILED);
throw new Error(ERROR_MESSAGES.NOTIFICATION_LOG_SAVE_FAILED);
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/modules/notification_events/notification_events.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class NotificationEventsService {
where: { context: data.context, key: data.key },
});
if (existingTemplate) {
LoggerUtil.log(apiId, SUCCESS_MESSAGES.CREATE_TEMPLATE_API, ERROR_MESSAGES.TEMPLATE_ALREADY_EXIST, userId);
LoggerUtil.error(ERROR_MESSAGES.TEMPLATE_ALREADY_EXIST, ERROR_MESSAGES.NOT_FOUND, apiId, userId);
throw new BadRequestException(ERROR_MESSAGES.TEMPLATE_ALREADY_EXIST);
}

Expand Down Expand Up @@ -70,7 +70,7 @@ export class NotificationEventsService {
if (data.sms && Object.keys(data.sms).length > 0) {
await createConfig('sms', data.sms);
}
LoggerUtil.log(SUCCESS_MESSAGES.TEMPLATE_CREATED_SUCESSFULLY(userId), `templateId: ${notificationTemplateResult.actionId}`, '/create/template');
LoggerUtil.log(SUCCESS_MESSAGES.TEMPLATE_CREATED_SUCESSFULLY(userId), apiId, userId);
return response
.status(HttpStatus.CREATED)
.json(APIResponse.success(apiId, notificationTemplateResult, 'Created'));
Expand All @@ -89,7 +89,7 @@ export class NotificationEventsService {
where: { actionId: id },
});
if (!existingTemplate) {
LoggerUtil.log(apiId, SUCCESS_MESSAGES.UPDATE_TEMPLATE_API, ERROR_MESSAGES.TEMPLATE_NOT_EXIST, userId);
LoggerUtil.error(ERROR_MESSAGES.TEMPLATE_NOT_EXIST, ERROR_MESSAGES.NOT_FOUND, apiId, userId);
throw new BadRequestException(ERROR_MESSAGES.TEMPLATE_NOT_EXIST);
}
//check key already exist for this context
Expand All @@ -99,7 +99,7 @@ export class NotificationEventsService {
where: { context: existingTemplate.context, key: updateEventDto.key },
});
if (checkKeyAlreadyExist) {
LoggerUtil.error(apiId, ERROR_MESSAGES.ALREADY_EXIST_KEY_FOR_CONTEXT, `requested By ${userId}`);
LoggerUtil.error(ERROR_MESSAGES.ALREADY_EXIST_KEY_FOR_CONTEXT, ERROR_MESSAGES.INVALID_REQUEST, apiId, `${userId}`);
throw new BadRequestException(ERROR_MESSAGES.ALREADY_EXIST_KEY_FOR_CONTEXT_ENTER_ANOTHER);
}
}
Expand Down Expand Up @@ -160,7 +160,7 @@ export class NotificationEventsService {
}
});
}
LoggerUtil.log(`Template updated successfully by userId: ${userId}`, `Id: ${id}`, '/update/template');
LoggerUtil.log(`Template updated successfully by userId: ${userId}`, apiId, userId);
return response
.status(HttpStatus.OK)
.json(APIResponse.success(apiId, { id: id }, 'OK'));
Expand Down Expand Up @@ -192,7 +192,7 @@ export class NotificationEventsService {
}, {});
return { ...rest, templates: formattedTemplateConfig };
});
LoggerUtil.log(SUCCESS_MESSAGES.GET_TEMPLATE(userId), '/get/template');
LoggerUtil.log(SUCCESS_MESSAGES.GET_TEMPLATE(userId), apiId, userId,);
return response
.status(HttpStatus.OK)
.json(APIResponse.success(apiId, finalResult, 'OK'));
Expand All @@ -202,14 +202,14 @@ export class NotificationEventsService {
const apiId = APIID.TEMPLATE_DELETE;
const templateId = await this.notificationTemplatesRepository.findOne({ where: { actionId } });
if (!templateId) {
LoggerUtil.log(apiId, SUCCESS_MESSAGES.UPDATE_TEMPLATE_API, ERROR_MESSAGES.TEMPLATE_NOT_EXIST, userId);
LoggerUtil.error(ERROR_MESSAGES.TEMPLATE_NOT_EXIST, ERROR_MESSAGES.NOT_FOUND, apiId, userId);
throw new NotFoundException(ERROR_MESSAGES.TEMPLATE_ID_NOTFOUND(actionId))
}
const deleteTemplate = await this.notificationTemplatesRepository.delete({ actionId });
if (deleteTemplate.affected !== 1) {
throw new BadRequestException(ERROR_MESSAGES.TEMPLATE_NOT_DELETED);
}
LoggerUtil.log(SUCCESS_MESSAGES.DELETE_TEMPLATE(userId), '/delete/template');
LoggerUtil.log(SUCCESS_MESSAGES.DELETE_TEMPLATE(userId), apiId, userId);
return response
.status(HttpStatus.OK)
.json(APIResponse.success(apiId, { id: actionId }, 'OK'));
Expand Down

0 comments on commit 9174ff5

Please sign in to comment.