Skip to content

Commit

Permalink
Octicons, express: major type updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwilcox committed Jun 14, 2023
1 parent 4ca3b70 commit d5a28ed
Show file tree
Hide file tree
Showing 47 changed files with 602 additions and 424 deletions.
9 changes: 5 additions & 4 deletions api/client/context/administration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ router.use(

router.get(
'/',
asyncHandler(async (req: IRequestWithAdministration, res: Response, next: NextFunction) => {
asyncHandler(async (req: IRequestWithAdministration, res: Response) => {
const { operations } = getProviders(req);
const isAdministrator = req.isSystemAdministrator;
if (!isAdministrator) {
return res.json({
isAdministrator,
});
}) as unknown as void;
}
const organizations = operations.getOrganizations().map((org) => org.asClientJson());
return res.json({
isAdministrator,
organizations,
});
}) as unknown as void;
})
);

Expand All @@ -62,7 +62,8 @@ router.use(
} catch (noOrgError) {
if (ErrorHelper.IsNotFound(noOrgError)) {
res.status(404);
return res.end();
res.end();
return;
}
return next(jsonError(noOrgError, 500));
}
Expand Down
2 changes: 1 addition & 1 deletion api/client/context/administration/organization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ router.get(
const { organization } = req;
return res.json({
organization: organization.asClientJson(),
});
}) as unknown as void;
})
);

Expand Down
18 changes: 9 additions & 9 deletions api/client/context/administration/organization/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ router.get(
const { dynamicSettings } = req;
return res.json({
dynamicSettings,
});
}) as unknown as void;
})
);

Expand All @@ -53,7 +53,7 @@ router.get(
return res.json({
features,
organizationName: organization.name,
});
}) as unknown as void;
})
);

Expand All @@ -66,7 +66,7 @@ router.get(
flag,
value: dynamicSettings.features.includes(flag) ? flag : null,
organizationName: organization.name,
});
}) as unknown as void;
})
);

Expand Down Expand Up @@ -98,7 +98,7 @@ router.put(
flag,
value: dynamicSettings.features.includes(flag) ? flag : null,
organizationName: organization.name,
});
}) as unknown as void;
})
);

Expand Down Expand Up @@ -130,7 +130,7 @@ router.delete(
flag,
value: dynamicSettings.features.includes(flag) ? flag : null,
organizationName: organization.name,
});
}) as unknown as void;
})
);

Expand All @@ -144,7 +144,7 @@ router.get(
return res.json({
properties,
organizationName: organization.name,
});
}) as unknown as void;
})
);

Expand All @@ -158,7 +158,7 @@ router.get(
property: propertyName,
value: properties[propertyName] || null,
organizationName: organization.name,
});
}) as unknown as void;
})
);

Expand Down Expand Up @@ -204,7 +204,7 @@ router.put(
organizationName: organization.name,
dynamicSettings,
updateDescription,
});
}) as unknown as void;
})
);

Expand Down Expand Up @@ -240,7 +240,7 @@ router.delete(
property: propertyName,
value: properties[propertyName] || null,
organizationName: organization.name,
});
}) as unknown as void;
})
);

Expand Down
4 changes: 2 additions & 2 deletions api/client/context/approvals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ router.get(
teamResponsibilities: [],
usersRequests: [],
isLinked: false,
});
}) as unknown as void;
}
try {
// const username = activeContext.getGitHubIdentity().username;
Expand All @@ -54,7 +54,7 @@ router.get(
teamResponsibilities: teamResponsibilities.map(approvalPairToJson),
usersRequests: usersRequests.map(approvalPairToJson),
};
return res.json(state);
return res.json(state) as unknown as void;
} catch (error) {
return next(jsonError(error));
}
Expand Down
8 changes: 5 additions & 3 deletions api/client/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ router.get(
response.deletedOrChangedUsernames.push(username);
}
}
return res.json(response);
return res.json(response) as unknown as void;
})
);

Expand Down Expand Up @@ -125,10 +125,12 @@ router.use(
if (ErrorHelper.IsNotFound(noOrgError)) {
if (await isUnmanagedOrganization(providers, orgName)) {
res.status(204);
return res.end();
res.end();
return;
}
res.status(404);
return res.end();
res.end();
return;
}
return next(jsonError(noOrgError, 500));
}
Expand Down
40 changes: 21 additions & 19 deletions api/client/context/organization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import { jsonError } from '../../../../middleware';
import getCompanySpecificDeployment from '../../../../middleware/companySpecificDeployment';
import { IndividualContext } from '../../../../business/user';

import RouteRepos from './repos';
import RouteTeams from './teams';
import routeRepos from './repos';
import routeTeams from './teams';
import { CreateError } from '../../../../transitional';

const router: Router = Router();

Expand All @@ -28,20 +29,20 @@ router.get(
const { organization } = req;
const activeContext = (req.individualContext || req.apiContext) as IndividualContext;
if (!activeContext.link) {
return res.json(false);
return res.json(false) as unknown as void;
}
const membership = await organization.getOperationalMembership(
activeContext.getGitHubIdentity().username
);
if (!membership) {
return res.json(false);
return res.json(false) as unknown as void;
}
return res.json({
user: toSanitizedUser(membership.user),
organization: toSanitizedOrg(membership.organization),
role: membership.role,
state: membership.state,
});
}) as unknown as void;
})
);

Expand All @@ -51,11 +52,11 @@ router.get(
const { organization } = req;
const activeContext = (req.individualContext || req.apiContext) as IndividualContext;
if (!activeContext.link) {
return res.json({ isSudoer: false });
return res.json({ isSudoer: false }) as unknown as void;
}
return res.json({
isSudoer: await organization.isSudoer(activeContext.getGitHubIdentity().username, activeContext.link),
});
}) as unknown as void;
})
);

Expand All @@ -65,17 +66,17 @@ router.get(
const { organization } = req;
const activeContext = (req.individualContext || req.apiContext) as IndividualContext;
if (!activeContext.link) {
return res.json({ isOrganizationOwner: false });
return res.json({ isOrganizationOwner: false }) as unknown as void;
}
try {
const username = activeContext.getGitHubIdentity().username;
const membership = await organization.getOperationalMembership(username);
const isOrganizationOwner = membership?.role === OrganizationMembershipRole.Admin;
return res.json({
isOrganizationOwner,
});
}) as unknown as void;
} catch (error) {
return jsonError(error, 400);
return next(CreateError.InvalidParameters(error));
}
})
);
Expand All @@ -87,18 +88,18 @@ router.delete(
const { organization } = req;
const activeContext = (req.individualContext || req.apiContext) as IndividualContext;
if (!activeContext.link) {
return next(jsonError('You are not linked', 400));
return next(CreateError.InvalidParameters('You are not linked'));
}
const login = activeContext.getGitHubIdentity().username;
const id = activeContext.getGitHubIdentity().id;
try {
await organization.removeMember(login, id);
return res.json({
message: `Your ${login} account has been removed from ${organization.name}.`,
});
}) as unknown as void;
} catch (error) {
console.warn(error);
return next(jsonError(error, 400));
return next(CreateError.InvalidParameters(error));
}
})
);
Expand All @@ -110,7 +111,7 @@ router.get(
const organization = req.organization as Organization;
const activeContext = (req.individualContext || req.apiContext) as IndividualContext;
if (!activeContext.link) {
return res.json({ personalizedTeams: [] });
return res.json({ personalizedTeams: [] }) as unknown as void;
}
const userAggregateContext = activeContext.aggregations;
const maintainedTeams = new Set<string>();
Expand All @@ -132,21 +133,21 @@ router.get(
});
return res.json({
personalizedTeams,
});
}) as unknown as void;
} catch (error) {
return next(jsonError(error, 400));
return next(CreateError.InvalidParameters(error));
}
})
);

router.use('/repos', RouteRepos);
router.use('/teams', RouteTeams);
router.use('/repos', routeRepos);
router.use('/teams', routeTeams);

const deployment = getCompanySpecificDeployment();
deployment?.routes?.api?.context?.organization?.index &&
deployment?.routes?.api?.context?.organization?.index(router);

router.use('*', (req, res: Response, next: NextFunction) => {
router.use('*', (req: ReposAppRequest, res: Response, next: NextFunction) => {
return next(jsonError('no API or function available: client>organization', 404));
});

Expand All @@ -160,6 +161,7 @@ const toSanitizedUser = (user) => {
avatar_url: user.avatar_url,
};
};

const toSanitizedOrg = (org) => {
if (!org || !org.login) {
return undefined;
Expand Down
2 changes: 1 addition & 1 deletion api/client/context/organization/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ router.get(
AddRepositoryPermissionsToRequest,
asyncHandler(async (req: ReposAppRequest, res: Response, next: NextFunction) => {
const permissions = getContextualRepositoryPermissions(req);
return res.json(permissions);
return res.json(permissions) as unknown as void;
})
);

Expand Down
7 changes: 2 additions & 5 deletions api/client/context/organization/repoForkUnlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import asyncHandler from 'express-async-handler';
import { jsonError } from '../../../../middleware';
import { getRepositoryMetadataProvider, ReposAppRequest } from '../../../../interfaces';
import { Organization } from '../../../../business';
import {
getContextualRepository,
getContextualRepositoryPermissions,
} from '../../../../middleware/github/repoPermissions';
import { getContextualRepository } from '../../../../middleware/github/repoPermissions';
import { IndividualContext } from '../../../../business/user';
import { ErrorHelper, getProviders } from '../../../../transitional';
import NewRepositoryLockdownSystem from '../../../../features/newRepositories/newRepositoryLockdown';
Expand Down Expand Up @@ -58,7 +55,7 @@ router.post(
return res.json({
message: `Unlocked the ${repository.name} repo in the ${organization.name} org`,
unlocked: true,
});
}) as unknown as void;
} catch (error) {
return next(
jsonError(
Expand Down
12 changes: 8 additions & 4 deletions api/client/context/organization/repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { Repository } from '../../../../business';
import { jsonError } from '../../../../middleware';
import { setContextualRepository } from '../../../../middleware/github/repoPermissions';

import { OrganizationMembershipState, ReposAppRequest } from '../../../../interfaces';
import { OrganizationMembershipState, ReposAppRequest, VoidedExpressRoute } from '../../../../interfaces';
import { IndividualContext } from '../../../../business/user';
import { createRepositoryFromClient } from '../../newOrgRepo';

import RouteContextualRepo from './repo';
import routeContextualRepo from './repo';

const router: Router = Router();

Expand All @@ -34,7 +34,11 @@ async function validateActiveMembership(req: ReposAppRequest, res: Response, nex
return next();
}

router.post('/', asyncHandler(validateActiveMembership), asyncHandler(createRepositoryFromClient));
router.post(
'/',
asyncHandler(validateActiveMembership),
asyncHandler(createRepositoryFromClient as VoidedExpressRoute)
);

router.use(
'/:repoName',
Expand All @@ -48,7 +52,7 @@ router.use(
})
);

router.use('/:repoName', RouteContextualRepo);
router.use('/:repoName', routeContextualRepo);

router.use('*', (req, res: Response, next: NextFunction) => {
return next(jsonError('no API or function available for repos', 404));
Expand Down
Loading

0 comments on commit d5a28ed

Please sign in to comment.