mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-28 00:17:12 +01:00
wip: start messing around
This commit is contained in:
parent
2a5b8e3806
commit
488078223b
@ -7,6 +7,12 @@ import type {
|
|||||||
export class FakePersonalDashboardReadModel
|
export class FakePersonalDashboardReadModel
|
||||||
implements IPersonalDashboardReadModel
|
implements IPersonalDashboardReadModel
|
||||||
{
|
{
|
||||||
|
enrichProjectIds(
|
||||||
|
userId: number,
|
||||||
|
projectIds: string[],
|
||||||
|
): Promise<PersonalProject[]> {
|
||||||
|
throw new Error('Method not implemented.');
|
||||||
|
}
|
||||||
async getPersonalFeatures(userId: number): Promise<PersonalFeature[]> {
|
async getPersonalFeatures(userId: number): Promise<PersonalFeature[]> {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -17,4 +17,9 @@ export type PersonalProjectWithOwners = PersonalProject & {
|
|||||||
export interface IPersonalDashboardReadModel {
|
export interface IPersonalDashboardReadModel {
|
||||||
getPersonalFeatures(userId: number): Promise<PersonalFeature[]>;
|
getPersonalFeatures(userId: number): Promise<PersonalFeature[]>;
|
||||||
getPersonalProjects(userId: number): Promise<PersonalProject[]>;
|
getPersonalProjects(userId: number): Promise<PersonalProject[]>;
|
||||||
|
|
||||||
|
enrichProjectIds(
|
||||||
|
userId: number,
|
||||||
|
projectIds: string[],
|
||||||
|
): Promise<PersonalProject[]>;
|
||||||
}
|
}
|
||||||
|
@ -116,4 +116,55 @@ export class PersonalDashboardReadModel implements IPersonalDashboardReadModel {
|
|||||||
project: row.project,
|
project: row.project,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async enrichProjectIds(
|
||||||
|
userId: number,
|
||||||
|
projectIds: string[],
|
||||||
|
): Promise<PersonalProject[]> {
|
||||||
|
const T = {
|
||||||
|
ROLE_USER: 'role_user',
|
||||||
|
ROLES: 'roles',
|
||||||
|
GROUPS: 'groups',
|
||||||
|
GROUP_ROLE: 'group_role',
|
||||||
|
GROUP_USER: 'group_user',
|
||||||
|
ROLE_PERMISSION: 'role_permission',
|
||||||
|
PERMISSIONS: 'permissions',
|
||||||
|
PERMISSION_TYPES: 'permission_types',
|
||||||
|
CHANGE_REQUEST_SETTINGS: 'change_request_settings',
|
||||||
|
PERSONAL_ACCESS_TOKENS: 'personal_access_tokens',
|
||||||
|
PUBLIC_SIGNUP_TOKENS_USER: 'public_signup_tokens_user',
|
||||||
|
};
|
||||||
|
|
||||||
|
const roles = await this.db
|
||||||
|
.select(['id', 'name', 'type', 'project', 'description'])
|
||||||
|
.from(T.ROLES)
|
||||||
|
.innerJoin(`${T.ROLE_USER} as ru`, 'ru.role_id', 'id')
|
||||||
|
.where('ru.user_id', '=', userId)
|
||||||
|
.andWhere((builder) => {
|
||||||
|
builder
|
||||||
|
.whereIn('ru.project', projectIds)
|
||||||
|
.orWhere('type', '=', 'root');
|
||||||
|
})
|
||||||
|
.union([
|
||||||
|
this.db
|
||||||
|
.select(['id', 'name', 'type', 'project', 'description'])
|
||||||
|
.from(T.ROLES)
|
||||||
|
.innerJoin(`${T.GROUP_ROLE} as gr`, 'gr.role_id', 'id')
|
||||||
|
.innerJoin(
|
||||||
|
`${T.GROUP_USER} as gu`,
|
||||||
|
'gu.group_id',
|
||||||
|
'gr.group_id',
|
||||||
|
)
|
||||||
|
.where('gu.user_id', '=', userId)
|
||||||
|
.andWhere((builder) => {
|
||||||
|
builder
|
||||||
|
.whereIn('gr.project', projectIds)
|
||||||
|
.orWhere('type', '=', 'root');
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
console.log(roles);
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import type { IProjectOwnersReadModel } from '../project/project-owners-read-model.type';
|
import type { IProjectOwnersReadModel } from '../project/project-owners-read-model.type';
|
||||||
|
import type { IProjectReadModel } from '../project/project-read-model-type';
|
||||||
import type {
|
import type {
|
||||||
IPersonalDashboardReadModel,
|
IPersonalDashboardReadModel,
|
||||||
PersonalFeature,
|
PersonalFeature,
|
||||||
@ -10,12 +11,16 @@ export class PersonalDashboardService {
|
|||||||
|
|
||||||
private projectOwnersReadModel: IProjectOwnersReadModel;
|
private projectOwnersReadModel: IProjectOwnersReadModel;
|
||||||
|
|
||||||
|
private projectReadModel: IProjectReadModel;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
personalDashboardReadModel: IPersonalDashboardReadModel,
|
personalDashboardReadModel: IPersonalDashboardReadModel,
|
||||||
projectOwnersReadModel: IProjectOwnersReadModel,
|
projectOwnersReadModel: IProjectOwnersReadModel,
|
||||||
|
projectReadModel: IProjectReadModel,
|
||||||
) {
|
) {
|
||||||
this.personalDashboardReadModel = personalDashboardReadModel;
|
this.personalDashboardReadModel = personalDashboardReadModel;
|
||||||
this.projectOwnersReadModel = projectOwnersReadModel;
|
this.projectOwnersReadModel = projectOwnersReadModel;
|
||||||
|
this.projectReadModel = projectReadModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
getPersonalFeatures(userId: number): Promise<PersonalFeature[]> {
|
getPersonalFeatures(userId: number): Promise<PersonalFeature[]> {
|
||||||
@ -25,6 +30,15 @@ export class PersonalDashboardService {
|
|||||||
async getPersonalProjects(
|
async getPersonalProjects(
|
||||||
userId: number,
|
userId: number,
|
||||||
): Promise<PersonalProjectWithOwners[]> {
|
): Promise<PersonalProjectWithOwners[]> {
|
||||||
|
const projectIds =
|
||||||
|
await this.projectReadModel.getProjectsByUser(userId);
|
||||||
|
|
||||||
|
console.log('got these', projectIds.length, 'projects', projectIds);
|
||||||
|
const enriched = await this.personalDashboardReadModel.enrichProjectIds(
|
||||||
|
userId,
|
||||||
|
projectIds,
|
||||||
|
);
|
||||||
|
// console.log('got these', enriched.length, 'projects', projectIds);
|
||||||
const projects =
|
const projects =
|
||||||
await this.personalDashboardReadModel.getPersonalProjects(userId);
|
await this.personalDashboardReadModel.getPersonalProjects(userId);
|
||||||
|
|
||||||
|
@ -151,6 +151,8 @@ import { PersonalDashboardReadModel } from '../features/personal-dashboard/perso
|
|||||||
import { FakePersonalDashboardReadModel } from '../features/personal-dashboard/fake-personal-dashboard-read-model';
|
import { FakePersonalDashboardReadModel } from '../features/personal-dashboard/fake-personal-dashboard-read-model';
|
||||||
import { ProjectOwnersReadModel } from '../features/project/project-owners-read-model';
|
import { ProjectOwnersReadModel } from '../features/project/project-owners-read-model';
|
||||||
import { FakeProjectOwnersReadModel } from '../features/project/fake-project-owners-read-model';
|
import { FakeProjectOwnersReadModel } from '../features/project/fake-project-owners-read-model';
|
||||||
|
import { ProjectReadModel } from '../features/project/project-read-model';
|
||||||
|
import { FakeProjectReadModel } from '../features/project/fake-project-read-model';
|
||||||
|
|
||||||
export const createServices = (
|
export const createServices = (
|
||||||
stores: IUnleashStores,
|
stores: IUnleashStores,
|
||||||
@ -412,6 +414,9 @@ export const createServices = (
|
|||||||
: new FakePersonalDashboardReadModel(),
|
: new FakePersonalDashboardReadModel(),
|
||||||
|
|
||||||
db ? new ProjectOwnersReadModel(db) : new FakeProjectOwnersReadModel(),
|
db ? new ProjectOwnersReadModel(db) : new FakeProjectOwnersReadModel(),
|
||||||
|
db
|
||||||
|
? new ProjectReadModel(db, config.eventBus, config.flagResolver)
|
||||||
|
: new FakeProjectReadModel(),
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user