mirror of
https://github.com/docmost/docmost.git
synced 2025-11-18 11:51:09 +10:00
WIP
This commit is contained in:
@ -67,7 +67,9 @@ export class ShareController {
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Post('/info')
|
||||
async getShare(@Body() dto: ShareIdDto, @AuthUser() user: User) {
|
||||
const share = await this.shareRepo.findById(dto.shareId);
|
||||
const share = await this.shareRepo.findById(dto.shareId, {
|
||||
includeSharedPage: true,
|
||||
});
|
||||
|
||||
if (!share) {
|
||||
throw new NotFoundException('Share not found');
|
||||
|
||||
@ -39,6 +39,7 @@ export class ShareRepo {
|
||||
async findById(
|
||||
shareId: string,
|
||||
opts?: {
|
||||
includeSharedPage?: boolean;
|
||||
includeCreator?: boolean;
|
||||
withLock?: boolean;
|
||||
trx?: KyselyTransaction;
|
||||
@ -48,6 +49,10 @@ export class ShareRepo {
|
||||
|
||||
let query = db.selectFrom('shares').select(this.baseFields);
|
||||
|
||||
if (opts?.includeSharedPage) {
|
||||
query = query.select((eb) => this.withSharedPage(eb));
|
||||
}
|
||||
|
||||
if (opts?.includeCreator) {
|
||||
query = query.select((eb) => this.withCreator(eb));
|
||||
}
|
||||
@ -98,7 +103,11 @@ export class ShareRepo {
|
||||
return dbOrTx(this.db, trx)
|
||||
.updateTable('shares')
|
||||
.set({ ...updatableShare, updatedAt: new Date() })
|
||||
.where(isValidUUID(shareId) ? 'id' : sql`LOWER(key)`, '=', shareId.toLowerCase())
|
||||
.where(
|
||||
isValidUUID(shareId) ? 'id' : sql`LOWER(key)`,
|
||||
'=',
|
||||
shareId.toLowerCase(),
|
||||
)
|
||||
.returning(this.baseFields)
|
||||
.executeTakeFirst();
|
||||
}
|
||||
@ -215,4 +224,19 @@ export class ShareRepo {
|
||||
.whereRef('users.id', '=', 'shares.creatorId'),
|
||||
).as('creator');
|
||||
}
|
||||
|
||||
withSharedPage(eb: ExpressionBuilder<DB, 'shares'>) {
|
||||
return jsonObjectFrom(
|
||||
eb
|
||||
.selectFrom('pages')
|
||||
.select([
|
||||
'pages.id',
|
||||
'pages.slugId',
|
||||
'pages.title',
|
||||
'pages.icon',
|
||||
'pages.parentPageId',
|
||||
])
|
||||
.whereRef('pages.id', '=', 'shares.pageId'),
|
||||
).as('sharedPage');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user