Skip to content

Commit

Permalink
Merge pull request #94 from openbankingnigeria/fix/onboarding
Browse files Browse the repository at this point in the history
fetch-apis-assigned-to-company
  • Loading branch information
dami-laare authored Jan 19, 2024
2 parents 4b85ac8 + 07e6a06 commit 775342f
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 6 deletions.
28 changes: 27 additions & 1 deletion apps/server/src/apis/apis.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ import {
} from '@common/utils/pipes/query/pagination.pipe';
import { FilterPipe } from '@common/utils/pipes/query/filter.pipe';
import { APIFilters } from './apis.filter';
import { Ctx, RequireTwoFA } from '@common/utils/authentication/auth.decorator';
import {
Ctx,
RequireTwoFA,
RequiredPermission,
} from '@common/utils/authentication/auth.decorator';
import { RequestContext } from '@common/utils/request/request-context';
import { PERMISSIONS } from '@permissions/types';

@Controller('apis/:environment')
export class APIController {
Expand Down Expand Up @@ -88,6 +93,27 @@ export class APIController {
);
}

@Get('company')
@UsePipes(IValidationPipe)
viewMyCompanyApis(@Ctx() ctx: RequestContext, @Param() params: APIParam) {
return this.apiService.getApisAssignedToCompany(ctx, params.environment);
}

@Get('company/:companyId')
@UsePipes(IValidationPipe)
@RequiredPermission(PERMISSIONS.VIEW_COMPANY_APIS_BY_ID)
viewCompanyApis(
@Ctx() ctx: RequestContext,
@Param() params: APIParam,
@Param('companyId') companyId: string,
) {
return this.apiService.getApisAssignedToCompany(
ctx,
params.environment,
companyId,
);
}

@Get('logs')
@UsePipes(IValidationPipe)
getAPILogs(
Expand Down
74 changes: 74 additions & 0 deletions apps/server/src/apis/apis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,4 +775,78 @@ export class APIService {
new APILogStatsResponseDTO(stats.aggregations),
);
}

async getApisAssignedToCompany(
ctx: RequestContext,
environment: KONG_ENVIRONMENT,
companyId?: string,
) {
const company = await this.companyRepository.findOneOrFail({
where: { id: companyId ?? ctx.activeCompany.id },
relations: {
acls: {
route: true,
},
},
});

if (!company) {
throw new IBadRequestException({
message: companyErrors.companyNotFound(
companyId ?? ctx.activeCompany.id,
),
});
}

const acls = company.acls.map((acl) => ({
id: acl.id,
route: acl.route,
}));

const routes = acls.map(({ route }) => {
const { routeId, serviceId, name, id, enabled } = route;
return { routeId, serviceId, name, id, enabled };
});

const populatedRoutes: any[] = [];

for (const route of routes) {
let gatewayService = null;
let gatewayRoutes = null;
if (route.serviceId) {
gatewayService = await this.kongService.getService(
environment,
route.serviceId,
);
gatewayRoutes = await this.kongService.getServiceRoutes(
environment,
route.serviceId,
);
}

populatedRoutes.push(
new GetAPIResponseDTO({
id: route.id,
name: route.name,
enabled: route.enabled,
host: gatewayService?.host || null,
protocol: gatewayService?.protocol || null,
port: gatewayService?.port || null,
path: gatewayService?.path || null,
url: gatewayService
? `${gatewayService.protocol}://${gatewayService.host}:${gatewayService.port}${gatewayService.path}`
: null,
route: new GETAPIRouteResponseDTO({
paths: gatewayRoutes?.data[0]?.paths || [],
methods: gatewayRoutes?.data[0]?.methods || [],
}),
}),
);
}

return ResponseFormatter.success(
apiSuccessMessages.fetchedAPIs,
populatedRoutes,
);
}
}
4 changes: 0 additions & 4 deletions apps/server/src/auth/dto/index.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ export class TwoFADto extends ForgotPasswordDto {
message: ({ property }) => authValidationErrors.dto.isRequired(property),
})
@IsString()
@IsStrongPassword(passwordConfig, {
message: ({ property }) =>
authValidationErrors.dto.passwordStrengthMismatch(property),
})
password: string;

@IsNotEmpty({
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/company/company.errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const companyErrors = {
companyAlreadyVerified:
'Your business has already been verified. You cannot update this information',
noKybDetailsFound: 'No KYB details were found for this company',
companyNotFound: (companyId: string) =>
companyNotFound: (companyId?: string) =>
`No company found with ID - ${companyId}`,
businessNotFoundOnRegistry: (rcNumber: string) =>
`No business with RC number - ${rcNumber} found in registry.`,
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/permissions/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export enum PERMISSIONS {

UPDATE_KYB_REQUIREMENT_SETTINGS = 'update-kyb-requirement-setting',
UPDATE_KYB_REQUIREMENTS = 'update-kyb-requirements',

VIEW_COMPANY_APIS_BY_ID = 'view-company-apis-by-id',
}

export enum PROVIDER_PERMISSIONS {
Expand Down

0 comments on commit 775342f

Please sign in to comment.