-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from hypersign-protocol/fix-status
Fix status
- Loading branch information
Showing
8 changed files
with
199 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
); | ||
} | ||
} |