mirror of
https://github.com/docmost/docmost.git
synced 2025-11-25 18:51:09 +10:00
refactor layout
* ui polishing * frontend and backend fixes
This commit is contained in:
@ -11,12 +11,14 @@ import { PaginationOptions } from '../../pagination/pagination-options';
|
||||
import { MemberInfo, UserSpaceRole } from './types';
|
||||
import { executeWithPagination } from '@docmost/db/pagination/pagination';
|
||||
import { GroupRepo } from '@docmost/db/repos/group/group.repo';
|
||||
import { SpaceRepo } from '@docmost/db/repos/space/space.repo';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceMemberRepo {
|
||||
constructor(
|
||||
@InjectKysely() private readonly db: KyselyDB,
|
||||
private readonly groupRepo: GroupRepo,
|
||||
private readonly spaceRepo: SpaceRepo,
|
||||
) {}
|
||||
|
||||
async insertSpaceMember(
|
||||
@ -184,4 +186,52 @@ export class SpaceMemberRepo {
|
||||
}
|
||||
return roles;
|
||||
}
|
||||
|
||||
async getUserSpaceIds(userId: string): Promise<string[]> {
|
||||
const membership = await this.db
|
||||
.selectFrom('spaceMembers')
|
||||
.innerJoin('spaces', 'spaces.id', 'spaceMembers.spaceId')
|
||||
.select(['spaces.id'])
|
||||
.where('userId', '=', userId)
|
||||
.union(
|
||||
this.db
|
||||
.selectFrom('spaceMembers')
|
||||
.innerJoin('groupUsers', 'groupUsers.groupId', 'spaceMembers.groupId')
|
||||
.innerJoin('spaces', 'spaces.id', 'spaceMembers.spaceId')
|
||||
.select(['spaces.id'])
|
||||
.where('groupUsers.userId', '=', userId),
|
||||
)
|
||||
.execute();
|
||||
|
||||
return membership.map((space) => space.id);
|
||||
}
|
||||
|
||||
async getUserSpaces(userId: string, pagination: PaginationOptions) {
|
||||
const userSpaceIds = await this.getUserSpaceIds(userId);
|
||||
|
||||
let query = this.db
|
||||
.selectFrom('spaces')
|
||||
.selectAll('spaces')
|
||||
.select((eb) => [this.spaceRepo.withMemberCount(eb)])
|
||||
//.where('workspaceId', '=', workspaceId)
|
||||
.where('id', 'in', userSpaceIds)
|
||||
.orderBy('createdAt', 'asc');
|
||||
|
||||
if (pagination.query) {
|
||||
query = query.where((eb) =>
|
||||
eb('name', 'ilike', `%${pagination.query}%`).or(
|
||||
'description',
|
||||
'ilike',
|
||||
`%${pagination.query}%`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const result = executeWithPagination(query, {
|
||||
page: pagination.page,
|
||||
perPage: pagination.limit,
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import { ExpressionBuilder, sql } from 'kysely';
|
||||
import { PaginationOptions } from '../../pagination/pagination-options';
|
||||
import { executeWithPagination } from '@docmost/db/pagination/pagination';
|
||||
import { DB } from '@docmost/db/types/db';
|
||||
import { validate as isValidUUID } from 'uuid';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceRepo {
|
||||
@ -22,13 +23,19 @@ export class SpaceRepo {
|
||||
opts?: { includeMemberCount?: boolean; trx?: KyselyTransaction },
|
||||
): Promise<Space> {
|
||||
const db = dbOrTx(this.db, opts?.trx);
|
||||
return db
|
||||
|
||||
let query = db
|
||||
.selectFrom('spaces')
|
||||
.selectAll('spaces')
|
||||
.$if(opts?.includeMemberCount, (qb) => qb.select(this.withMemberCount))
|
||||
.where('id', '=', spaceId)
|
||||
.where('workspaceId', '=', workspaceId)
|
||||
.executeTakeFirst();
|
||||
.where('workspaceId', '=', workspaceId);
|
||||
|
||||
if (isValidUUID(spaceId)) {
|
||||
query = query.where('id', '=', spaceId);
|
||||
} else {
|
||||
query = query.where('slug', '=', spaceId);
|
||||
}
|
||||
return query.executeTakeFirst();
|
||||
}
|
||||
|
||||
async findBySlug(
|
||||
|
||||
Reference in New Issue
Block a user