Feature/clean up user database schema (#1242)
* Clean up user database schema * Update changelog
This commit is contained in:
parent
980ad1028c
commit
4f8fe83a16
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Changed
|
||||
|
||||
- Removed the `currency` and `viewMode` from the `User` database schema
|
||||
|
||||
### Fixed
|
||||
|
||||
- Allowed the date range change for the demo user
|
||||
|
@ -103,7 +103,7 @@ export class OrderController {
|
||||
impersonationId,
|
||||
this.request.user.id
|
||||
);
|
||||
const userCurrency = this.request.user.Settings.currency;
|
||||
const userCurrency = this.request.user.Settings.settings.baseCurrency;
|
||||
|
||||
let activities = await this.orderService.getOrders({
|
||||
filters,
|
||||
|
@ -40,7 +40,6 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { REQUEST } from '@nestjs/core';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { ViewMode } from '@prisma/client';
|
||||
import { StatusCodes, getReasonPhrase } from 'http-status-codes';
|
||||
|
||||
import { PortfolioPositionDetail } from './interfaces/portfolio-position-detail.interface';
|
||||
@ -196,7 +195,7 @@ export class PortfolioController {
|
||||
return this.exchangeRateDataService.toCurrency(
|
||||
portfolioPosition.quantity * portfolioPosition.marketPrice,
|
||||
portfolioPosition.currency,
|
||||
this.request.user.Settings.currency
|
||||
this.request.user.Settings.settings.baseCurrency
|
||||
);
|
||||
})
|
||||
.reduce((a, b) => a + b, 0);
|
||||
@ -299,7 +298,7 @@ export class PortfolioController {
|
||||
|
||||
if (
|
||||
impersonationId ||
|
||||
this.request.user.Settings.viewMode === ViewMode.ZEN ||
|
||||
this.request.user.Settings.settings.viewMode === 'ZEN' ||
|
||||
this.userService.isRestrictedView(this.request.user)
|
||||
) {
|
||||
performanceInformation.performance = nullifyValuesInObject(
|
||||
@ -379,7 +378,8 @@ export class PortfolioController {
|
||||
return this.exchangeRateDataService.toCurrency(
|
||||
portfolioPosition.quantity * portfolioPosition.marketPrice,
|
||||
portfolioPosition.currency,
|
||||
this.request.user?.Settings?.currency ?? this.baseCurrency
|
||||
this.request.user?.Settings?.settings.baseCurrency ??
|
||||
this.baseCurrency
|
||||
);
|
||||
})
|
||||
.reduce((a, b) => a + b, 0);
|
||||
|
@ -124,7 +124,7 @@ export class PortfolioService {
|
||||
this.getDetails(aUserId, aUserId, undefined, aFilters)
|
||||
]);
|
||||
|
||||
const userCurrency = this.request.user.Settings.currency;
|
||||
const userCurrency = this.request.user.Settings.settings.baseCurrency;
|
||||
|
||||
return accounts.map((account) => {
|
||||
let transactionCount = 0;
|
||||
@ -199,7 +199,7 @@ export class PortfolioService {
|
||||
});
|
||||
|
||||
const portfolioCalculator = new PortfolioCalculator({
|
||||
currency: this.request.user.Settings.currency,
|
||||
currency: this.request.user.Settings.settings.baseCurrency,
|
||||
currentRateService: this.currentRateService,
|
||||
orders: portfolioOrders
|
||||
});
|
||||
@ -279,7 +279,7 @@ export class PortfolioService {
|
||||
});
|
||||
|
||||
const portfolioCalculator = new PortfolioCalculator({
|
||||
currency: this.request.user.Settings.currency,
|
||||
currency: this.request.user.Settings.settings.baseCurrency,
|
||||
currentRateService: this.currentRateService,
|
||||
orders: portfolioOrders
|
||||
});
|
||||
@ -368,7 +368,7 @@ export class PortfolioService {
|
||||
});
|
||||
|
||||
const portfolioCalculator = new PortfolioCalculator({
|
||||
currency: this.request.user.Settings.currency,
|
||||
currency: this.request.user.Settings.settings.baseCurrency,
|
||||
currentRateService: this.currentRateService,
|
||||
orders: portfolioOrders
|
||||
});
|
||||
@ -441,8 +441,8 @@ export class PortfolioService {
|
||||
(user.Settings?.settings as UserSettings)?.emergencyFund ?? 0
|
||||
);
|
||||
const userCurrency =
|
||||
user.Settings?.currency ??
|
||||
this.request.user?.Settings?.currency ??
|
||||
user.Settings?.settings.baseCurrency ??
|
||||
this.request.user?.Settings?.settings.baseCurrency ??
|
||||
this.baseCurrency;
|
||||
|
||||
const { orders, portfolioOrders, transactionPoints } =
|
||||
@ -602,7 +602,7 @@ export class PortfolioService {
|
||||
aImpersonationId: string,
|
||||
aSymbol: string
|
||||
): Promise<PortfolioPositionDetail> {
|
||||
const userCurrency = this.request.user.Settings.currency;
|
||||
const userCurrency = this.request.user.Settings.settings.baseCurrency;
|
||||
const userId = await this.getUserId(aImpersonationId, this.request.user.id);
|
||||
|
||||
const orders = (
|
||||
@ -855,7 +855,7 @@ export class PortfolioService {
|
||||
});
|
||||
|
||||
const portfolioCalculator = new PortfolioCalculator({
|
||||
currency: this.request.user.Settings.currency,
|
||||
currency: this.request.user.Settings.settings.baseCurrency,
|
||||
currentRateService: this.currentRateService,
|
||||
orders: portfolioOrders
|
||||
});
|
||||
@ -931,7 +931,7 @@ export class PortfolioService {
|
||||
});
|
||||
|
||||
const portfolioCalculator = new PortfolioCalculator({
|
||||
currency: this.request.user.Settings.currency,
|
||||
currency: this.request.user.Settings.settings.baseCurrency,
|
||||
currentRateService: this.currentRateService,
|
||||
orders: portfolioOrders
|
||||
});
|
||||
@ -991,7 +991,7 @@ export class PortfolioService {
|
||||
}
|
||||
|
||||
public async getReport(impersonationId: string): Promise<PortfolioReport> {
|
||||
const currency = this.request.user.Settings.currency;
|
||||
const currency = this.request.user.Settings.settings.baseCurrency;
|
||||
const userId = await this.getUserId(impersonationId, this.request.user.id);
|
||||
|
||||
const { orders, portfolioOrders, transactionPoints } =
|
||||
@ -1083,7 +1083,7 @@ export class PortfolioService {
|
||||
}
|
||||
|
||||
public async getSummary(aImpersonationId: string): Promise<PortfolioSummary> {
|
||||
const userCurrency = this.request.user.Settings.currency;
|
||||
const userCurrency = this.request.user.Settings.settings.baseCurrency;
|
||||
const userId = await this.getUserId(aImpersonationId, this.request.user.id);
|
||||
const user = await this.userService.user({ id: userId });
|
||||
|
||||
@ -1257,7 +1257,7 @@ export class PortfolioService {
|
||||
return this.exchangeRateDataService.toCurrency(
|
||||
new Big(order.quantity).mul(order.unitPrice).toNumber(),
|
||||
order.SymbolProfile.currency,
|
||||
this.request.user.Settings.currency
|
||||
this.request.user.Settings.settings.baseCurrency
|
||||
);
|
||||
})
|
||||
.reduce(
|
||||
@ -1276,7 +1276,7 @@ export class PortfolioService {
|
||||
return this.exchangeRateDataService.toCurrency(
|
||||
order.fee,
|
||||
order.SymbolProfile.currency,
|
||||
this.request.user.Settings.currency
|
||||
this.request.user.Settings.settings.baseCurrency
|
||||
);
|
||||
})
|
||||
.reduce(
|
||||
@ -1298,7 +1298,7 @@ export class PortfolioService {
|
||||
return this.exchangeRateDataService.toCurrency(
|
||||
new Big(order.quantity).mul(order.unitPrice).toNumber(),
|
||||
order.SymbolProfile.currency,
|
||||
this.request.user.Settings.currency
|
||||
this.request.user.Settings.settings.baseCurrency
|
||||
);
|
||||
})
|
||||
.reduce(
|
||||
@ -1339,7 +1339,7 @@ export class PortfolioService {
|
||||
portfolioOrders: PortfolioOrder[];
|
||||
}> {
|
||||
const userCurrency =
|
||||
this.request.user?.Settings?.currency ?? this.baseCurrency;
|
||||
this.request.user?.Settings?.settings.baseCurrency ?? this.baseCurrency;
|
||||
|
||||
const orders = await this.orderService.getOrders({
|
||||
filters,
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { UniqueAsset } from '@ghostfolio/common/interfaces';
|
||||
import type { DateRange } from '@ghostfolio/common/types';
|
||||
import { ViewMode } from '@prisma/client';
|
||||
import type { DateRange, ViewMode } from '@ghostfolio/common/types';
|
||||
import {
|
||||
IsBoolean,
|
||||
IsIn,
|
||||
|
@ -69,8 +69,8 @@ export class UserService {
|
||||
}),
|
||||
accounts: Account,
|
||||
settings: {
|
||||
...(<UserSettings>(<unknown>Settings.settings)),
|
||||
locale: (<UserSettings>(<unknown>Settings.settings))?.locale ?? aLocale
|
||||
...(<UserSettings>Settings.settings),
|
||||
locale: (<UserSettings>Settings.settings)?.locale ?? aLocale
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -88,10 +88,7 @@ export class UserService {
|
||||
}
|
||||
|
||||
public isRestrictedView(aUser: UserWithSettings) {
|
||||
return (
|
||||
(aUser.Settings.settings as unknown as UserSettings)?.isRestrictedView ??
|
||||
false
|
||||
);
|
||||
return aUser.Settings.settings.isRestrictedView ?? false;
|
||||
}
|
||||
|
||||
public async user(
|
||||
@ -134,11 +131,9 @@ export class UserService {
|
||||
} else if (user) {
|
||||
// Set default settings if needed
|
||||
user.Settings = {
|
||||
currency: null,
|
||||
settings: {},
|
||||
updatedAt: new Date(),
|
||||
userId: user?.id,
|
||||
viewMode: 'DEFAULT'
|
||||
userId: user?.id
|
||||
};
|
||||
}
|
||||
|
||||
@ -239,10 +234,12 @@ export class UserService {
|
||||
},
|
||||
Settings: {
|
||||
create: {
|
||||
settings: {
|
||||
currency: this.baseCurrency
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (data.provider === 'ANONYMOUS') {
|
||||
|
@ -166,21 +166,6 @@ export class ExchangeRateDataService {
|
||||
currencies.push(account.currency);
|
||||
});
|
||||
|
||||
(
|
||||
await this.prismaService.settings.findMany({
|
||||
distinct: ['currency'],
|
||||
orderBy: [{ currency: 'asc' }],
|
||||
select: { currency: true },
|
||||
where: {
|
||||
currency: {
|
||||
not: null
|
||||
}
|
||||
}
|
||||
})
|
||||
).forEach((userSettings) => {
|
||||
currencies.push(userSettings.currency);
|
||||
});
|
||||
|
||||
(
|
||||
await this.prismaService.symbolProfile.findMany({
|
||||
distinct: ['currency'],
|
||||
|
@ -7,7 +7,6 @@ import {
|
||||
} from '@angular/router';
|
||||
import { SettingsStorageService } from '@ghostfolio/client/services/settings-storage.service';
|
||||
import { UserService } from '@ghostfolio/client/services/user/user.service';
|
||||
import { ViewMode } from '@prisma/client';
|
||||
import { EMPTY } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
|
||||
@ -80,13 +79,13 @@ export class AuthGuard implements CanActivate {
|
||||
return;
|
||||
} else if (
|
||||
state.url.startsWith('/home') &&
|
||||
user.settings.viewMode === ViewMode.ZEN
|
||||
user.settings.viewMode === 'ZEN'
|
||||
) {
|
||||
this.router.navigate(['/zen']);
|
||||
resolve(false);
|
||||
return;
|
||||
} else if (state.url.startsWith('/start')) {
|
||||
if (user.settings.viewMode === ViewMode.ZEN) {
|
||||
if (user.settings.viewMode === 'ZEN') {
|
||||
this.router.navigate(['/zen']);
|
||||
} else {
|
||||
this.router.navigate(['/home']);
|
||||
@ -96,7 +95,7 @@ export class AuthGuard implements CanActivate {
|
||||
return;
|
||||
} else if (
|
||||
state.url.startsWith('/zen') &&
|
||||
user.settings.viewMode === ViewMode.DEFAULT
|
||||
user.settings.viewMode === 'DEFAULT'
|
||||
) {
|
||||
this.router.navigate(['/home']);
|
||||
resolve(false);
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { DateRange } from '@ghostfolio/common/types';
|
||||
import { ViewMode } from '@prisma/client';
|
||||
import { DateRange, ViewMode } from '@ghostfolio/common/types';
|
||||
|
||||
import { UniqueAsset } from './unique-asset.interface';
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
import { SubscriptionType } from '@ghostfolio/common/types/subscription.type';
|
||||
import { Account, Settings, User } from '@prisma/client';
|
||||
import { UserSettings } from './user-settings.interface';
|
||||
|
||||
export type UserWithSettings = User & {
|
||||
Account: Account[];
|
||||
permissions?: string[];
|
||||
Settings: Settings;
|
||||
Settings: Settings & { settings: UserSettings };
|
||||
subscription?: {
|
||||
expiresAt?: Date;
|
||||
type: SubscriptionType;
|
||||
|
@ -8,6 +8,7 @@ import { Market } from './market.type';
|
||||
import type { OrderWithAccount } from './order-with-account.type';
|
||||
import type { RequestWithUser } from './request-with-user.type';
|
||||
import { ToggleOption } from './toggle-option.type';
|
||||
import type { ViewMode } from './view-mode.type';
|
||||
|
||||
export type {
|
||||
AccessWithGranteeUser,
|
||||
@ -19,5 +20,6 @@ export type {
|
||||
MarketState,
|
||||
OrderWithAccount,
|
||||
RequestWithUser,
|
||||
ToggleOption
|
||||
ToggleOption,
|
||||
ViewMode
|
||||
};
|
||||
|
1
libs/common/src/lib/types/view-mode.type.ts
Normal file
1
libs/common/src/lib/types/view-mode.type.ts
Normal file
@ -0,0 +1 @@
|
||||
export type ViewMode = 'DEFAULT' | 'ZEN';
|
@ -0,0 +1,3 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Settings" DROP COLUMN "currency",
|
||||
DROP COLUMN "viewMode";
|
@ -102,10 +102,8 @@ model Property {
|
||||
}
|
||||
|
||||
model Settings {
|
||||
currency String? /// @deprecated
|
||||
settings Json?
|
||||
updatedAt DateTime @updatedAt
|
||||
viewMode ViewMode? /// @deprecated
|
||||
userId String @id
|
||||
User User @relation(fields: [userId], references: [id])
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user