Skip to content

Commit 6197732

Browse files
committed
add org access request creation
1 parent 6218ca9 commit 6197732

File tree

9 files changed

+522
-162
lines changed

9 files changed

+522
-162
lines changed

src/controllers/v3/OrgAccessRequestsController.ts

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
Body,
1010
Get,
1111
Tags,
12+
FieldErrors,
13+
ValidateError,
1214
} from 'tsoa';
1315
import { KeystoneService } from '../ioc/keystoneInjector';
1416
import { inject, injectable } from 'tsyringe';
@@ -19,6 +21,11 @@ import { getOrgNamespaces } from '../../services/workflow/get-namespaces';
1921
import { getAccessRequestsByNamespace } from '../../services/keystone';
2022
import { OrgAccessRequest, OrgAccessRequestCreateInput } from './types-extra';
2123
import { OrgAccessRequestCreate } from '../../services/workflow/org-access-request';
24+
import { Logger } from '../../logger';
25+
import { gql } from 'graphql-request';
26+
import { data } from 'msw/lib/types/context';
27+
28+
const logger = Logger('controllers.OrgAccessReq');
2229

2330
@injectable()
2431
@Route('/organizations')
@@ -76,17 +83,34 @@ export class OrgAccessRequestsController extends Controller {
7683
@Path() org: string,
7784
@Body() body: OrgAccessRequestCreateInput,
7885
@Request() request: any
79-
): Promise<OrgAccessRequest> {
80-
const ctx = this.keystone.createContext(request, true);
81-
82-
83-
const userId = body.userId;
84-
85-
//const userId = ctx.authedItem.userId
86+
): Promise<{id: string}> {
8687

87-
const result = await OrgAccessRequestCreate(ctx, org, body.orgMemberId, userId,
88-
body.consumerProductEnvAppId, body.providerProductEnvAppId, body.businessProcess, body.accessPointDN, body.optionalClientScopes);
88+
const result = await this.keystone.executeGraphQL({
89+
context: this.keystone.createContext(request),
90+
query: createAccessRequest,
91+
variables: { data: body },
92+
});
93+
logger.debug('Result %j', result);
94+
if (result.errors) {
95+
const errors: FieldErrors = {};
96+
result.errors.forEach((err: any, ind: number) => {
97+
errors[`d${ind}`] = { message: err.message };
98+
});
99+
logger.error('%j', result);
100+
throw new ValidateError(errors, 'Unable to create Gateway');
101+
}
102+
return {
103+
id: result.data.orgAccessRequest.id,
104+
};
89105

90-
return result.accessRequest as any
91106
}
92107
}
108+
109+
const createAccessRequest = gql`
110+
mutation OrgAccessRequestCreate($data: OrgAccessRequestCreateInput!) {
111+
orgAccessRequest(data: $data) {
112+
id
113+
}
114+
}
115+
`;
116+

0 commit comments

Comments
 (0)