Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PS-2901 Added TypeOrm service and test cases #16

Open
wants to merge 4 commits into
base: unit_test
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/modules/notification-queue/notificationQueue.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import { NotificationActionTemplates } from '../notification_events/entity/notif
import { NotificationActions } from '../notification_events/entity/notificationActions.entity';
import { NotificationLog } from '../notification/entity/notificationLogs.entity';
import { RabbitmqModule } from '../rabbitmq/rabbitmq.module';
import { TypeormService } from '../typeorm/typeorm.service';

@Module({
imports: [
TypeOrmModule.forFeature([NotificationQueue, NotificationActionTemplates, NotificationActions, NotificationLog]),
RabbitmqModule
],
providers: [NotificationQueueService, NotificationService, NotificationAdapterFactory, EmailAdapter, SmsAdapter, PushAdapter],
providers: [NotificationQueueService, NotificationService, NotificationAdapterFactory, EmailAdapter, SmsAdapter, PushAdapter, TypeormService],
controllers: [NotificationQueueController],
exports: [NotificationQueueService]
})
Expand Down
19 changes: 11 additions & 8 deletions src/modules/notification-queue/notificationQueue.service.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import { BadRequestException, HttpStatus, Injectable, NotFoundException } from '@nestjs/common';
import { Response } from 'express';
import APIResponse from 'src/common/utils/response';
import APIResponse from '../../common/utils/response';
import { NotificationQueueDTO } from './dto/notificationQueue.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { NotificationQueue } from './entities/notificationQueue.entity';
import { Repository } from 'typeorm';
import { SearchQueueDTO } from './dto/searchQueue.dto';
import { UpdateQueueDTO } from './dto/updateQueue.dto';
import { APIID } from 'src/common/utils/api-id.config';
import { ERROR_MESSAGES, SUCCESS_MESSAGES } from 'src/common/utils/constant.util';
import { APIID } from '../../common/utils/api-id.config';
import { ERROR_MESSAGES, SUCCESS_MESSAGES } from '../../common/utils/constant.util';
import { TypeormService } from '../typeorm/typeorm.service';


@Injectable()
export class NotificationQueueService {
constructor(
@InjectRepository(NotificationQueue)
private readonly notificationQueueRepo: Repository<NotificationQueue>
private readonly notificationQueueRepo: Repository<NotificationQueue>,
private readonly typeormService: TypeormService
) { }

async create(notificationQueueDTO: NotificationQueueDTO, response) {
const apiId = APIID.QUEUE_CREATE;
const result = await this.notificationQueueRepo.save(notificationQueueDTO);
const result = await this.typeormService.save(NotificationQueue, notificationQueueDTO);
return response
.status(HttpStatus.CREATED)
.json(APIResponse.success(apiId, result, SUCCESS_MESSAGES.CREATED));
Expand All @@ -28,7 +31,7 @@ export class NotificationQueueService {
async getList(searchQueueDTO: SearchQueueDTO, response: Response) {
const apiId = APIID.QUEUE_LIST;
const { channel, context, status } = searchQueueDTO;
const result = await this.notificationQueueRepo.find({
const result = await this.typeormService.find(NotificationQueue, {
where: { channel: channel, context: context, status: status }
})
if (result.length === 0) {
Expand All @@ -41,12 +44,12 @@ export class NotificationQueueService {

async updateQueue(id: string, updateQueueDTO: UpdateQueueDTO) {
const apiId = APIID.QUEUE_UPDATE
const queue = await this.notificationQueueRepo.findOne({ where: { id } });
const queue = await this.typeormService.findOne(NotificationQueue, { where: { id } });
if (!queue) {
throw new BadRequestException(ERROR_MESSAGES.QUEUE_UPDATE(id))
}
Object.assign(queue, updateQueueDTO);
const updateResult = await this.notificationQueueRepo.save(queue);
const updateResult = await this.typeormService.save(NotificationQueue, queue);
if (!updateResult) {
throw new BadRequestException(ERROR_MESSAGES.EVENT_UPDATE_FAILED);
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/notification/adapters/emailService.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { NotificationActionTemplates } from "src/modules/notification_events/ent
import NotifmeSdk from 'notifme-sdk';
import { NotificationLog } from "../entity/notificationLogs.entity";
import { NotificationService } from "../notification.service";
import { LoggerUtil } from "src/common/logger/LoggerUtil";
import { ERROR_MESSAGES, SUCCESS_MESSAGES } from "src/common/utils/constant.util";
import { LoggerUtil } from "../../../common/logger/LoggerUtil";
import { ERROR_MESSAGES, SUCCESS_MESSAGES } from "../../../common/utils/constant.util";


@Injectable()
Expand Down
4 changes: 2 additions & 2 deletions src/modules/notification/adapters/pushService.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import * as admin from "firebase-admin";
import { ConfigService } from "@nestjs/config";
import { NotificationLog } from "../entity/notificationLogs.entity";
import { NotificationService } from "../notification.service";
import { ERROR_MESSAGES, SUCCESS_MESSAGES } from "src/common/utils/constant.util";
import { LoggerUtil } from "src/common/logger/LoggerUtil";
import { ERROR_MESSAGES, SUCCESS_MESSAGES } from "../../../common/utils/constant.util";
import { LoggerUtil } from "../../../common/logger/LoggerUtil";
@Injectable()
export class PushAdapter implements NotificationServiceInterface {
private readonly fcmurl: string;
Expand Down
8 changes: 4 additions & 4 deletions src/modules/notification/adapters/smsService.adapter.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { BadRequestException, Inject, Injectable, forwardRef } from "@nestjs/common";
import { NotificationServiceInterface } from "../interface/notificationService";
import { NotificationDto } from "../dto/notificationDto.dto";
import { NotificationActions } from "src/modules/notification_events/entity/notificationActions.entity";
import { NotificationActions } from "../../notification_events/entity/notificationActions.entity";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";
import { NotificationActionTemplates } from "src/modules/notification_events/entity/notificationActionTemplates.entity"
import { NotificationActionTemplates } from "../../notification_events/entity/notificationActionTemplates.entity"
import { ConfigService } from "@nestjs/config";
import { NotificationLog } from "../entity/notificationLogs.entity";
import { NotificationService } from "../notification.service";
import { LoggerUtil } from "src/common/logger/LoggerUtil";
import { ERROR_MESSAGES, SUCCESS_MESSAGES } from "src/common/utils/constant.util";
import { LoggerUtil } from "../../../common/logger/LoggerUtil";
import { ERROR_MESSAGES, SUCCESS_MESSAGES } from "../../../common/utils/constant.util";
@Injectable()
export class SmsAdapter implements NotificationServiceInterface {

Expand Down
4 changes: 3 additions & 1 deletion src/modules/notification/notification.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ import { NotificationService } from './notification.service';
import { NotificationQueue } from '../notification-queue/entities/notificationQueue.entity';
import { RabbitmqModule } from '../rabbitmq/rabbitmq.module';
import { NotificationQueueService } from '../notification-queue/notificationQueue.service';
import { TypeormService } from '../typeorm/typeorm.service';


@Module({
imports: [
TypeOrmModule.forFeature([NotificationActions, NotificationActionTemplates, NotificationLog, NotificationQueue]), // import entity here
NotificationEventsModule, RabbitmqModule
],
providers: [NotificationAdapterFactory, PushAdapter, SmsAdapter, EmailAdapter, NotificationService, NotificationQueueService],

providers: [NotificationAdapterFactory, PushAdapter, SmsAdapter, EmailAdapter, NotificationService, NotificationQueueService, TypeormService],
controllers: [NotificationController],
exports: [NotificationService]
})
Expand Down
Loading