Skip to content

Commit c17f1a0

Browse files
authored
exposed authz api (#116)
* exposed authz api * added module to reviel in swagger
1 parent e2ff782 commit c17f1a0

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

src/credits/controllers/credits.controller.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import {
99
} from '@nestjs/swagger';
1010
import { AllExceptionsFilter } from 'src/utils/utils';
1111
import { AuthzCreditService } from '../services/credits.service';
12-
import { GetCreditsDto } from '../dtos/credits.dto';
12+
import { GetCreditsDto, GrantAllowanceResponseDto } from '../dtos/credits.dto';
1313

1414
@UseFilters(AllExceptionsFilter)
1515
@ApiTags('Credits')
1616
@Controller('/api/v1/credits')
1717
export class CreditsController {
1818
constructor(private readonly creditService: AuthzCreditService) {}
1919
@ApiBearerAuth('Authorization')
20+
@ApiExcludeEndpoint()
2021
@Get('/app')
2122
@ApiQuery({
2223
name: 'appId',
@@ -29,4 +30,22 @@ export class CreditsController {
2930
const appId = query.appId;
3031
return this.creditService.getCreditDetails(appId, userId);
3132
}
33+
@ApiBearerAuth('Authorization')
34+
@ApiOkResponse({
35+
description: 'Granted allowance to specific wallet successfully',
36+
type: GrantAllowanceResponseDto,
37+
})
38+
@ApiQuery({
39+
name: 'allowance',
40+
description: 'Amount to authorize for the app',
41+
required: false,
42+
type: String,
43+
})
44+
@Get('/authz/:appId')
45+
async getAllowanceGrant(
46+
@Param('appId') appId: string,
47+
@Query('allowance') allowance = '5000000',
48+
) {
49+
return this.creditService.grantSSICredit(appId, allowance);
50+
}
3251
}

src/credits/credits.module.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { JwtModule } from '@nestjs/jwt';
2222
import { HidWalletModule } from 'src/hid-wallet/hid-wallet.module';
2323
import { AppAuthModule } from 'src/app-auth/app-auth.module';
2424
import { RateLimitMiddleware } from 'src/utils/middleware/rate-limit.middleware';
25+
import { SuperAdminMiddleware } from 'src/utils/middleware/super-admin.middleware';
2526

2627
@Module({
2728
imports: [
@@ -50,6 +51,10 @@ export class CreditModule implements NestModule {
5051
configure(consumer: MiddlewareConsumer) {
5152
consumer.apply(JWTAuthorizeMiddleware).forRoutes(CreditsController);
5253
consumer.apply(JWTAccessAccountMiddleware).forRoutes(CreditsController);
54+
consumer
55+
.apply(SuperAdminMiddleware)
56+
.exclude({ path: 'api/v1/credits/app', method: RequestMethod.GET })
57+
.forRoutes(CreditsController);
5358
consumer.apply(RateLimitMiddleware).forRoutes(CreditsController);
5459
}
5560
}

src/credits/dtos/credits.dto.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,24 @@ class Credit {
2525
})
2626
denom: string;
2727
}
28+
export class GrantAllowanceResponseDto {
29+
@ApiProperty({
30+
name: 'credit',
31+
description: 'detail of credit',
32+
type: Credit,
33+
})
34+
@Type(() => Credit)
35+
@ValidateNested({ each: true })
36+
credit: Credit;
37+
@ApiProperty({
38+
name: 'creditScope',
39+
description: 'Credit scopre provided',
40+
example: [
41+
'MsgRegisterDID',
42+
'MsgDeactivateDID',
43+
'MsgRegisterCredentialSchema',
44+
'MsgUpdateDID',
45+
],
46+
})
47+
creditScope: Array<string>;
48+
}

src/main.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import * as cors from 'cors';
1818
import * as cookieParser from 'cookie-parser';
1919
import { WebpageConfigModule } from './webpage-config/webpage-config.module';
2020
import { CustomerOnboardingModule } from './customer-onboarding/customer-onboarding.module';
21+
import { CreditModule } from './credits/credits.module';
2122

2223
async function bootstrap() {
2324
const app = await NestFactory.create(AppModule);
@@ -118,7 +119,12 @@ async function bootstrap() {
118119
.build();
119120

120121
const orgDocuments = SwaggerModule.createDocument(app, orgDocConfig, {
121-
include: [AppOauthModule, WebpageConfigModule, CustomerOnboardingModule],
122+
include: [
123+
AppOauthModule,
124+
WebpageConfigModule,
125+
CustomerOnboardingModule,
126+
CreditModule,
127+
],
122128
});
123129
const tenantOptions = {
124130
swaggerOptions: {

0 commit comments

Comments
 (0)