1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-09 01:17:06 +02:00

fix: type checker happy (#3306)

This commit is contained in:
Mateusz Kwasniewski 2023-03-14 10:32:00 +01:00 committed by GitHub
parent 30a753b93f
commit 3837cceafe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 12 deletions

View File

@ -7,18 +7,18 @@ import { nameType } from '../routes/util';
import { projectSchema } from './project-schema'; import { projectSchema } from './project-schema';
import NotFoundError from '../error/notfound-error'; import NotFoundError from '../error/notfound-error';
import { import {
FEATURE_ENVIRONMENT_ENABLED,
PROJECT_CREATED, PROJECT_CREATED,
PROJECT_DELETED, PROJECT_DELETED,
PROJECT_UPDATED, PROJECT_UPDATED,
ProjectUserAddedEvent,
ProjectUserRemovedEvent,
ProjectUserUpdateRoleEvent,
ProjectGroupAddedEvent, ProjectGroupAddedEvent,
ProjectGroupRemovedEvent, ProjectGroupRemovedEvent,
ProjectGroupUpdateRoleEvent, ProjectGroupUpdateRoleEvent,
FEATURE_ENVIRONMENT_ENABLED, ProjectUserAddedEvent,
ProjectUserRemovedEvent,
ProjectUserUpdateRoleEvent,
} from '../types/events'; } from '../types/events';
import { IUnleashStores, IUnleashConfig, IAccountStore } from '../types'; import { IAccountStore, IUnleashConfig, IUnleashStores } from '../types';
import { import {
FeatureToggle, FeatureToggle,
IProject, IProject,
@ -51,7 +51,7 @@ import { FavoritesService } from './favorites-service';
import { TimeToProduction } from '../read-models/time-to-production/time-to-production'; import { TimeToProduction } from '../read-models/time-to-production/time-to-production';
import { IProjectStatsStore } from 'lib/types/stores/project-stats-store-type'; import { IProjectStatsStore } from 'lib/types/stores/project-stats-store-type';
const getCreatedBy = (user: IUser) => user.email || user.username; const getCreatedBy = (user: IUser) => user.email || user.username || 'unknown';
export interface AccessWithRoles { export interface AccessWithRoles {
users: IUserWithRole[]; users: IUserWithRole[];
@ -412,6 +412,7 @@ export default class ProjectService {
const role = await this.accessService.getRole(roleId); const role = await this.accessService.getRole(roleId);
const group = await this.groupService.getGroup(groupId); const group = await this.groupService.getGroup(groupId);
const project = await this.getProject(projectId); const project = await this.getProject(projectId);
if (group.id == null) throw new TypeError('Unexpected empty group id');
await this.accessService.addGroupToRole( await this.accessService.addGroupToRole(
group.id, group.id,
@ -442,6 +443,7 @@ export default class ProjectService {
const group = await this.groupService.getGroup(groupId); const group = await this.groupService.getGroup(groupId);
const role = await this.accessService.getRole(roleId); const role = await this.accessService.getRole(roleId);
const project = await this.getProject(projectId); const project = await this.getProject(projectId);
if (group.id == null) throw new TypeError('Unexpected empty group id');
await this.accessService.removeGroupFromRole( await this.accessService.removeGroupFromRole(
group.id, group.id,
@ -530,9 +532,12 @@ export default class ProjectService {
): Promise<void> { ): Promise<void> {
const usersWithRoles = await this.getAccessToProject(projectId); const usersWithRoles = await this.getAccessToProject(projectId);
const user = usersWithRoles.users.find((u) => u.id === userId); const user = usersWithRoles.users.find((u) => u.id === userId);
if (!user) throw new TypeError('Unexpected empty user');
const currentRole = usersWithRoles.roles.find( const currentRole = usersWithRoles.roles.find(
(r) => r.id === user.roleId, (r) => r.id === user.roleId,
); );
if (!currentRole) throw new TypeError('Unexpected empty current role');
if (currentRole.id === roleId) { if (currentRole.id === roleId) {
// Nothing to do.... // Nothing to do....
@ -576,9 +581,11 @@ export default class ProjectService {
): Promise<void> { ): Promise<void> {
const usersWithRoles = await this.getAccessToProject(projectId); const usersWithRoles = await this.getAccessToProject(projectId);
const user = usersWithRoles.groups.find((u) => u.id === userId); const user = usersWithRoles.groups.find((u) => u.id === userId);
if (!user) throw new TypeError('Unexpected empty user');
const currentRole = usersWithRoles.roles.find( const currentRole = usersWithRoles.roles.find(
(r) => r.id === user.roleId, (r) => r.id === user.roleId,
); );
if (!currentRole) throw new TypeError('Unexpected empty current role');
if (currentRole.id === roleId) { if (currentRole.id === roleId) {
// Nothing to do.... // Nothing to do....
@ -805,10 +812,12 @@ export default class ProjectService {
userId, userId,
}), }),
this.store.getMembersCountByProject(projectId), this.store.getMembersCountByProject(projectId),
this.favoritesService.isFavoriteProject({ userId
? this.favoritesService.isFavoriteProject({
project: projectId, project: projectId,
userId, userId,
}), })
: Promise.resolve(false),
this.projectStatsStore.getProjectStats(projectId), this.projectStatsStore.getProjectStats(projectId),
]); ]);
@ -816,7 +825,7 @@ export default class ProjectService {
stats: projectStats, stats: projectStats,
name: project.name, name: project.name,
description: project.description, description: project.description,
health: project.health, health: project.health || 0,
favorite: favorite, favorite: favorite,
updatedAt: project.updatedAt, updatedAt: project.updatedAt,
environments, environments,

View File

@ -44,7 +44,6 @@ process.nextTick(async () => {
projectStatusApi: true, projectStatusApi: true,
showProjectApiAccess: true, showProjectApiAccess: true,
projectScopedSegments: true, projectScopedSegments: true,
bulkOperations: true,
projectScopedStickiness: true, projectScopedStickiness: true,
}, },
}, },