mirror of
https://github.com/docmost/docmost.git
synced 2025-11-17 10:01:11 +10:00
add full page width preference
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { OmitType, PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateUserDto } from '../../auth/dto/create-user.dto';
|
||||
import { IsOptional, IsString } from 'class-validator';
|
||||
import { IsBoolean, IsOptional, IsString } from 'class-validator';
|
||||
|
||||
export class UpdateUserDto extends PartialType(
|
||||
OmitType(CreateUserDto, ['password'] as const),
|
||||
@ -8,4 +8,8 @@ export class UpdateUserDto extends PartialType(
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
avatarUrl: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
fullPageWidth: boolean;
|
||||
}
|
||||
|
||||
@ -20,10 +20,19 @@ export class UserService {
|
||||
workspaceId: string,
|
||||
) {
|
||||
const user = await this.userRepo.findById(userId, workspaceId);
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundException('User not found');
|
||||
}
|
||||
|
||||
// preference update
|
||||
if (typeof updateUserDto.fullPageWidth !== 'undefined') {
|
||||
return this.updateUserPageWidthPreference(
|
||||
userId,
|
||||
updateUserDto.fullPageWidth,
|
||||
);
|
||||
}
|
||||
|
||||
if (updateUserDto.name) {
|
||||
user.name = updateUserDto.name;
|
||||
}
|
||||
@ -42,4 +51,12 @@ export class UserService {
|
||||
await this.userRepo.updateUser(updateUserDto, userId, workspaceId);
|
||||
return user;
|
||||
}
|
||||
|
||||
async updateUserPageWidthPreference(userId: string, fullPageWidth: boolean) {
|
||||
return this.userRepo.updatePreference(
|
||||
userId,
|
||||
'fullPageWidth',
|
||||
fullPageWidth,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ import {
|
||||
executeWithPagination,
|
||||
PaginationResult,
|
||||
} from '@docmost/db/pagination/pagination';
|
||||
import { sql } from 'kysely';
|
||||
|
||||
@Injectable()
|
||||
export class UserRepo {
|
||||
@ -157,6 +158,24 @@ export class UserRepo {
|
||||
return result;
|
||||
}
|
||||
|
||||
async updatePreference(
|
||||
userId: string,
|
||||
prefKey: string,
|
||||
prefValue: string | boolean,
|
||||
) {
|
||||
return await this.db
|
||||
.updateTable('users')
|
||||
.set({
|
||||
settings: sql`COALESCE(settings, '{}'::jsonb)
|
||||
|| jsonb_build_object('preferences', COALESCE(settings->'preferences', '{}'::jsonb)
|
||||
|| jsonb_build_object('${sql.raw(prefKey)}', ${sql.lit(prefValue)}))`,
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where('id', '=', userId)
|
||||
.returning(this.baseFields)
|
||||
.executeTakeFirst();
|
||||
}
|
||||
|
||||
/*
|
||||
async getSpaceIds(
|
||||
workspaceId: string,
|
||||
|
||||
Reference in New Issue
Block a user