This commit is contained in:
Philipinho
2025-04-22 15:10:05 +01:00
parent a66fb875ac
commit f74688663d
9 changed files with 116 additions and 18 deletions

View File

@ -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');

View File

@ -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');
}
}