Skip to content

Commit

Permalink
Merge pull request #166 from hypersign-protocol/fix-status
Browse files Browse the repository at this point in the history
Fix status
  • Loading branch information
Pratap2018 authored Dec 27, 2024
2 parents c772cab + 3f8b8fb commit 0e9f5e4
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SchemaModule } from './schema/schema.module';
import { CredentialModule } from './credential/credential.module';
import { PresentationModule } from './presentation/presentation.module';
import { TxSendModuleModule } from './tx-send-module/tx-send-module.module';
import { StatusModule } from './status/status.module';
@Module({
imports: [
ConfigModule.forRoot({
Expand All @@ -20,6 +21,7 @@ import { TxSendModuleModule } from './tx-send-module/tx-send-module.module';
CredentialModule,
PresentationModule,
TxSendModuleModule,
StatusModule,
],
controllers: [],
providers: [{ provide: APP_FILTER, useClass: AllExceptionsFilter }],
Expand Down
9 changes: 8 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { DidModule } from './did/did.module';
import { SchemaModule } from './schema/schema.module';
import { PresentationModule } from './presentation/presentation.module';
import { CredentialModule } from './credential/credential.module';
import { StatusModule } from './status/status.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule, { cors: true });
app.use(json({ limit: '10mb' }));
Expand Down Expand Up @@ -124,7 +125,13 @@ async function bootstrap() {
.build();

const tenantDocuments = SwaggerModule.createDocument(app, tenantDocConfig, {
include: [DidModule, SchemaModule, CredentialModule, PresentationModule], // don't include, say, BearsModule
include: [
DidModule,
SchemaModule,
CredentialModule,
PresentationModule,
StatusModule,
], // don't include, say, BearsModule
});

const tenantOptions = {
Expand Down
11 changes: 11 additions & 0 deletions src/status/providers/registration-status.provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Connection } from 'mongoose';
import { RegistrationStatusSchema } from '../schema/status.schema';

export const statusProviders = [
{
provide: 'STATUS_MODEL',
useFactory: (connection: Connection) =>
connection.model('RegistrationStatus', RegistrationStatusSchema),
inject: ['APPDATABASECONNECTIONS'],
},
];
24 changes: 24 additions & 0 deletions src/status/repository/status.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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(
@Inject('STATUS_MODEL')
private readonly registatiationStatusModel: Model<RegistrationStatusDocument>,
) {}

async find(
registrationStatus: FilterQuery<RegistrationStatusDocument>,
projection?: ProjectionType<RegistrationStatusDocument>,
option?: QueryOptions<RegistrationStatusDocument>,
) {
return this.registatiationStatusModel.find(
registrationStatus,
projection,
option,
);
}
}
36 changes: 36 additions & 0 deletions src/status/schema/status.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Document } from 'mongoose';
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';

export type RegistrationStatusDocument = RegistrationStatus & Document;

@Schema({
timestamps: true,
})
export class RegistrationStatus {
@Prop()
txnHash: string;

@Prop({ required: false })
status?: number;

@Prop()
id: string;

@Prop()
type: string;

@Prop({ required: false, type: Object })
message?: object;
}

const RegistrationStatusSchema =
SchemaFactory.createForClass(RegistrationStatus);
RegistrationStatusSchema.index(
{
txnHash: 1,
id: 1,
},
{ unique: true },
);

export { RegistrationStatusSchema };
63 changes: 63 additions & 0 deletions src/status/status.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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')
@Controller('status')
@UseGuards(AuthGuard('jwt'))
export class StatusController {
constructor(private readonly statusService: StatusService) {}

@Get('ssi/:id')
@ApiQuery({
name: 'page',
description: 'Page value',
required: false,
})
@ApiQuery({
name: 'limit',
description: 'Fetch limited list of data',
required: false,
})
@ApiParam({
name: 'id',
description: 'Enter didId or vcId or schemaId',
})
getStatus(@Param('id') id: string, @Query() pagination: PaginationDto) {
return this.statusService.findBySsiId(id, pagination);
}

@Get('transaction/:transactionHash')
@ApiQuery({
name: 'page',
description: 'Page value',
required: false,
})
@ApiQuery({
name: 'limit',
description: 'Fetch limited list of data',
required: false,
})
@ApiParam({
name: 'transactionHash',
description: 'Enter transactionHash',
})
getStatusByTransactionHash(
@Param('transactionHash') transactionHash: string,
@Query() pagination: PaginationDto,
) {
return this.statusService.findByTxnId(transactionHash, pagination);
}
}
26 changes: 26 additions & 0 deletions src/status/status.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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/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,
],
exports: [],
})
export class StatusModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer.apply(WhitelistSSICorsMiddleware).forRoutes(StatusController);
consumer.apply(TrimMiddleware).forRoutes(StatusController);
}
}
29 changes: 29 additions & 0 deletions src/status/status.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Injectable } from '@nestjs/common';
import { TxnStatusRepository } from './repository/status.repository';

@Injectable()
export class StatusService {
constructor(private readonly txnStatusRepository: TxnStatusRepository) {}
findBySsiId(id: string, option) {
const skip = (option.page - 1) * option.limit;
option['skip'] = skip;
return this.txnStatusRepository.find({
id,
});
}

findByTxnId(id: string, option) {
const skip = (option.page - 1) * option.limit;
option['skip'] = skip;
return this.txnStatusRepository.find(
{
txnHash: id,
},
{},
{
skip: option.skip,
limit: option.limit,
},
);
}
}

0 comments on commit 0e9f5e4

Please sign in to comment.