Skip to content

Commit

Permalink
add-status
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratap2018 committed Dec 27, 2024
1 parent a3d4285 commit 3f8b8fb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { RegistrationStatusSchema } from '../schema/status.schema';

export const statusProviders = [
{
provide: 'REGISTRATIONSTATUS_MODEL',
provide: 'STATUS_MODEL',
useFactory: (connection: Connection) =>
connection.model('RegistrationStatus', RegistrationStatusSchema),
inject: ['APPDATABASECONNECTIONS'],
Expand Down
24 changes: 16 additions & 8 deletions src/status/repository/status.repository.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { FilterQuery, Model } from 'mongoose';
import { RegistrationStatus } from '../schema/status.schema';
import { Inject, Injectable } from '@nestjs/common';
import { FilterQuery, Model, ProjectionType, QueryOptions } from 'mongoose';
import { RegistrationStatusDocument } from '../schema/status.schema';
import { skip } from 'rxjs';

@Injectable()
export class TxnStatusRepository {
constructor(
@InjectModel('REGISTRATION_STATUS')
private registatiationStatusModel: Model<RegistrationStatus>,
@Inject('STATUS_MODEL')
private readonly registatiationStatusModel: Model<RegistrationStatusDocument>,
) {}

async createOrUpdate(registrationStatus: FilterQuery<RegistrationStatus>) {
return this.registatiationStatusModel.insertMany(registrationStatus);
async find(
registrationStatus: FilterQuery<RegistrationStatusDocument>,
projection?: ProjectionType<RegistrationStatusDocument>,
option?: QueryOptions<RegistrationStatusDocument>,
) {
return this.registatiationStatusModel.find(
registrationStatus,
projection,
option,
);
}
}
14 changes: 11 additions & 3 deletions src/status/status.controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { Controller, Get, Param, UseGuards, Query } from '@nestjs/common';
import {
Controller,
Get,
Param,
UseGuards,
Query,
UseFilters,
} from '@nestjs/common';
import { StatusService } from './status.service';

import { ApiBearerAuth, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { PaginationDto } from 'src/utils/pagination.dto';

import { AllExceptionsFilter } from 'src/utils/utils';
@UseFilters(AllExceptionsFilter)
@ApiTags('Status')
@ApiBearerAuth('Authorization')
@UseGuards(AuthGuard('jwt'))
@Controller('status')
@UseGuards(AuthGuard('jwt'))
export class StatusController {
constructor(private readonly statusService: StatusService) {}

Expand Down
15 changes: 11 additions & 4 deletions src/status/status.module.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import { Module } from '@nestjs/common';
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { StatusService } from './status.service';
import { StatusController } from './status.controller';
import { databaseProviders } from 'src/mongoose/tenant-mongoose-connections';
import { TxnStatusRepository } from './repository/status.repository';
import { statusProviders } from './providers/status.provider';
import { statusProviders } from './providers/registration-status.provider';
import { WhitelistSSICorsMiddleware } from 'src/utils/middleware/cors.middleware';
import { TrimMiddleware } from 'src/utils/middleware/trim.middleware';

@Module({
imports: [],
controllers: [StatusController],
providers: [
StatusService,
TxnStatusRepository,
...databaseProviders,
...statusProviders,
TxnStatusRepository,
],
exports: [],
})
export class StatusModule {}
export class StatusModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer.apply(WhitelistSSICorsMiddleware).forRoutes(StatusController);
consumer.apply(TrimMiddleware).forRoutes(StatusController);
}
}
15 changes: 13 additions & 2 deletions src/status/status.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@ export class StatusService {
findBySsiId(id: string, option) {
const skip = (option.page - 1) * option.limit;
option['skip'] = skip;
return `This action returns a #${id} status`;
return this.txnStatusRepository.find({
id,
});
}

findByTxnId(id: string, option) {
const skip = (option.page - 1) * option.limit;
option['skip'] = skip;
return `This action returns a #${id} status`;
return this.txnStatusRepository.find(
{
txnHash: id,
},
{},
{
skip: option.skip,
limit: option.limit,
},
);
}
}

0 comments on commit 3f8b8fb

Please sign in to comment.