From 545fd0c0976667c82d3155bc7129cbb58a9048ff Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Sat, 22 May 2021 09:33:51 +0200 Subject: [PATCH] Refactor DisplayMode to ViewMode --- .../src/app/user/update-user-settings.dto.ts | 4 ++-- apps/api/src/app/user/user.controller.ts | 4 ++-- apps/api/src/app/user/user.service.ts | 20 +++++++++---------- .../components/header/header.component.html | 4 ++-- apps/client/src/app/core/auth.guard.ts | 8 ++++---- .../pages/account/account-page.component.ts | 2 +- .../src/app/pages/account/account-page.html | 8 ++++---- .../lib/interfaces/user-settings.interface.ts | 4 ++-- prisma/schema.prisma | 12 +++++------ 9 files changed, 33 insertions(+), 33 deletions(-) diff --git a/apps/api/src/app/user/update-user-settings.dto.ts b/apps/api/src/app/user/update-user-settings.dto.ts index 4c3e978bb..953913bac 100644 --- a/apps/api/src/app/user/update-user-settings.dto.ts +++ b/apps/api/src/app/user/update-user-settings.dto.ts @@ -1,4 +1,4 @@ -import { Currency, DisplayMode } from '@prisma/client'; +import { Currency, ViewMode } from '@prisma/client'; import { IsString } from 'class-validator'; export class UpdateUserSettingsDto { @@ -6,5 +6,5 @@ export class UpdateUserSettingsDto { baseCurrency: Currency; @IsString() - displayMode: DisplayMode; + viewMode: ViewMode; } diff --git a/apps/api/src/app/user/user.controller.ts b/apps/api/src/app/user/user.controller.ts index 974a8195d..f7e5d275b 100644 --- a/apps/api/src/app/user/user.controller.ts +++ b/apps/api/src/app/user/user.controller.ts @@ -94,8 +94,8 @@ export class UserController { return await this.userService.updateUserSettings({ currency: data.baseCurrency, - displayMode: data.displayMode, - userId: this.request.user.id + userId: this.request.user.id, + viewMode: data.viewMode }); } } diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts index 0ed3f2e44..fc5a461c4 100644 --- a/apps/api/src/app/user/user.service.ts +++ b/apps/api/src/app/user/user.service.ts @@ -5,7 +5,7 @@ import { resetHours } from '@ghostfolio/common/helper'; import { User as IUser, UserWithSettings } from '@ghostfolio/common/interfaces'; import { getPermissions, permissions } from '@ghostfolio/common/permissions'; import { Injectable } from '@nestjs/common'; -import { Currency, DisplayMode, Prisma, Provider, User } from '@prisma/client'; +import { Currency, Prisma, Provider, User, ViewMode } from '@prisma/client'; import { add } from 'date-fns'; const crypto = require('crypto'); @@ -54,7 +54,7 @@ export class UserService { settings: { locale, baseCurrency: Settings?.currency ?? UserService.DEFAULT_CURRENCY, - displayMode: Settings.displayMode ?? DisplayMode.DEFAULT + viewMode: Settings.viewMode ?? ViewMode.DEFAULT }, subscription: { expiresAt: resetHours(add(new Date(), { days: 7 })), @@ -80,9 +80,9 @@ export class UserService { // Set default settings if needed user.Settings = { currency: UserService.DEFAULT_CURRENCY, - displayMode: DisplayMode.DEFAULT, updatedAt: new Date(), - userId: user?.id + userId: user?.id, + viewMode: ViewMode.DEFAULT }; } @@ -189,26 +189,26 @@ export class UserService { public async updateUserSettings({ currency, - displayMode, - userId + userId, + viewMode }: { currency?: Currency; - displayMode?: DisplayMode; userId: string; + viewMode?: ViewMode; }) { await this.prisma.settings.upsert({ create: { currency, - displayMode, User: { connect: { id: userId } - } + }, + viewMode }, update: { currency, - displayMode + viewMode }, where: { userId: userId diff --git a/apps/client/src/app/components/header/header.component.html b/apps/client/src/app/components/header/header.component.html index 598ca13df..627701fb6 100644 --- a/apps/client/src/app/components/header/header.component.html +++ b/apps/client/src/app/components/header/header.component.html @@ -15,7 +15,7 @@ >Overview Analysis { if ( state.url === '/home' && - user.settings.displayMode === DisplayMode.ZEN + user.settings.viewMode === ViewMode.ZEN ) { this.router.navigate(['/zen']); resolve(false); } else if (state.url === '/start') { - if (user.settings.displayMode === DisplayMode.ZEN) { + if (user.settings.viewMode === ViewMode.ZEN) { this.router.navigate(['/zen']); } else { this.router.navigate(['/home']); @@ -60,7 +60,7 @@ export class AuthGuard implements CanActivate { resolve(false); } else if ( state.url === '/zen' && - user.settings.displayMode === DisplayMode.DEFAULT + user.settings.viewMode === ViewMode.DEFAULT ) { this.router.navigate(['/home']); resolve(false); diff --git a/apps/client/src/app/pages/account/account-page.component.ts b/apps/client/src/app/pages/account/account-page.component.ts index 4d1b428e3..c57eacde7 100644 --- a/apps/client/src/app/pages/account/account-page.component.ts +++ b/apps/client/src/app/pages/account/account-page.component.ts @@ -74,7 +74,7 @@ export class AccountPageComponent implements OnDestroy, OnInit { this.dataService .putUserSettings({ baseCurrency: settings?.baseCurrency, - displayMode: settings?.displayMode + viewMode: settings?.viewMode }) .pipe(takeUntil(this.unsubscribeSubject)) .subscribe(() => { diff --git a/apps/client/src/app/pages/account/account-page.html b/apps/client/src/app/pages/account/account-page.html index ff2904782..abd1f0fa4 100644 --- a/apps/client/src/app/pages/account/account-page.html +++ b/apps/client/src/app/pages/account/account-page.html @@ -47,12 +47,12 @@ - Display Mode + View Mode Default Zen diff --git a/libs/common/src/lib/interfaces/user-settings.interface.ts b/libs/common/src/lib/interfaces/user-settings.interface.ts index 78a6ad01c..01d3aa5be 100644 --- a/libs/common/src/lib/interfaces/user-settings.interface.ts +++ b/libs/common/src/lib/interfaces/user-settings.interface.ts @@ -1,7 +1,7 @@ -import { Currency, DisplayMode } from '@prisma/client'; +import { Currency, ViewMode } from '@prisma/client'; export interface UserSettings { baseCurrency: Currency; - displayMode: DisplayMode; locale: string; + viewMode: ViewMode; } diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 7742bdd69..56f367929 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -92,11 +92,11 @@ model Property { } model Settings { - currency Currency? - displayMode DisplayMode? - updatedAt DateTime @updatedAt - User User @relation(fields: [userId], references: [id]) - userId String @id + currency Currency? + viewMode ViewMode? + updatedAt DateTime @updatedAt + User User @relation(fields: [userId], references: [id]) + userId String @id } model User { @@ -134,7 +134,7 @@ enum DataSource { YAHOO } -enum DisplayMode { +enum ViewMode { DEFAULT ZEN }