Browse Source

feat(lib): resolve errors

pull/6250/head
KenTandrian 2 weeks ago
parent
commit
38bd5fe7de
  1. 26
      libs/common/src/lib/chart-helper.ts
  2. 2
      libs/common/src/lib/class-transformer.ts
  3. 8
      libs/common/src/lib/helper.ts
  4. 2
      libs/common/src/lib/interfaces/responses/public-portfolio-response.interface.ts
  5. 2
      libs/common/src/lib/routes/interfaces/internal-route.interface.ts
  6. 2
      libs/common/src/lib/types/date-range.type.ts
  7. 4
      libs/common/src/lib/utils/form.util.ts
  8. 2
      libs/common/src/lib/validators/is-currency-code.ts

26
libs/common/src/lib/chart-helper.ts

@ -1,4 +1,10 @@
import { Chart, TooltipPosition } from 'chart.js'; import type { ElementRef } from '@angular/core';
import type {
Chart,
ChartTypeRegistry,
Plugin,
TooltipPosition
} from 'chart.js';
import { format } from 'date-fns'; import { format } from 'date-fns';
import { import {
@ -34,12 +40,12 @@ export function getTooltipOptions({
locale = getLocale(), locale = getLocale(),
unit = '' unit = ''
}: { }: {
colorScheme?: ColorScheme; colorScheme: ColorScheme;
currency?: string; currency?: string;
groupBy?: GroupBy; groupBy?: GroupBy;
locale?: string; locale?: string;
unit?: string; unit?: string;
} = {}) { }) {
return { return {
backgroundColor: getBackgroundColor(colorScheme), backgroundColor: getBackgroundColor(colorScheme),
bodyColor: `rgb(${getTextColor(colorScheme)})`, bodyColor: `rgb(${getTextColor(colorScheme)})`,
@ -47,7 +53,7 @@ export function getTooltipOptions({
borderColor: `rgba(${getTextColor(colorScheme)}, 0.1)`, borderColor: `rgba(${getTextColor(colorScheme)}, 0.1)`,
callbacks: { callbacks: {
label: (context) => { label: (context) => {
let label = context.dataset.label || ''; let label = context.dataset.label ?? '';
if (label) { if (label) {
label += ': '; label += ': ';
} }
@ -98,10 +104,10 @@ export function getTooltipPositionerMapTop(
}; };
} }
export function getVerticalHoverLinePlugin( export function getVerticalHoverLinePlugin<T extends keyof ChartTypeRegistry>(
chartCanvas, chartCanvas: ElementRef,
colorScheme?: ColorScheme colorScheme: ColorScheme
) { ): Plugin<T> {
return { return {
afterDatasetsDraw: (chart, _, options) => { afterDatasetsDraw: (chart, _, options) => {
const active = chart.getActiveElements(); const active = chart.getActiveElements();
@ -110,8 +116,8 @@ export function getVerticalHoverLinePlugin(
return; return;
} }
const color = options.color || `rgb(${getTextColor(colorScheme)})`; const color = options.color ?? `rgb(${getTextColor(colorScheme)})`;
const width = options.width || 1; const width = options.width ?? 1;
const { const {
chartArea: { bottom, top } chartArea: { bottom, top }

2
libs/common/src/lib/class-transformer.ts

@ -16,7 +16,7 @@ export function transformToMapOfBig({
return mapOfBig; return mapOfBig;
} }
export function transformToBig({ value }: { value: string }): Big { export function transformToBig({ value }: { value: string }): Big | null {
if (value === null) { if (value === null) {
return null; return null;
} }

8
libs/common/src/lib/helper.ts

@ -144,7 +144,7 @@ export function extractNumberFromString({
}: { }: {
locale?: string; locale?: string;
value: string; value: string;
}): number { }): number | undefined {
try { try {
// Remove non-numeric characters (excluding international formatting characters) // Remove non-numeric characters (excluding international formatting characters)
const numericValue = value.replace(/[^\d.,'’\s]/g, ''); const numericValue = value.replace(/[^\d.,'’\s]/g, '');
@ -273,7 +273,7 @@ export function getNumberFormatDecimal(aLocale?: string) {
return formatObject.find((object) => { return formatObject.find((object) => {
return object.type === 'decimal'; return object.type === 'decimal';
}).value; })?.value;
} }
export function getNumberFormatGroup(aLocale = getLocale()) { export function getNumberFormatGroup(aLocale = getLocale()) {
@ -283,7 +283,7 @@ export function getNumberFormatGroup(aLocale = getLocale()) {
return formatObject.find((object) => { return formatObject.find((object) => {
return object.type === 'group'; return object.type === 'group';
}).value; })?.value;
} }
export function getStartOfUtcDate(aDate: Date) { export function getStartOfUtcDate(aDate: Date) {
@ -394,7 +394,7 @@ export function isRootCurrency(aCurrency: string) {
}); });
} }
export function parseDate(date: string): Date { export function parseDate(date: string): Date | undefined {
if (!date) { if (!date) {
return undefined; return undefined;
} }

2
libs/common/src/lib/interfaces/responses/public-portfolio-response.interface.ts

@ -39,7 +39,7 @@ export interface PublicPortfolioResponse extends PublicPortfolioResponseV1 {
})[]; })[];
markets: { markets: {
[key in Market]: Pick< [key in Market]: Pick<
PortfolioDetails['markets'][key], NonNullable<PortfolioDetails['markets']>[key],
'id' | 'valueInPercentage' 'id' | 'valueInPercentage'
>; >;
}; };

2
libs/common/src/lib/routes/interfaces/internal-route.interface.ts

@ -2,7 +2,7 @@ import { User } from '@ghostfolio/common/interfaces';
export interface InternalRoute { export interface InternalRoute {
excludeFromAssistant?: boolean | ((aUser: User) => boolean); excludeFromAssistant?: boolean | ((aUser: User) => boolean);
path: string; path?: string;
routerLink: string[]; routerLink: string[];
subRoutes?: Record<string, InternalRoute>; subRoutes?: Record<string, InternalRoute>;
title: string; title: string;

2
libs/common/src/lib/types/date-range.type.ts

@ -6,4 +6,4 @@ export type DateRange =
| 'mtd' | 'mtd'
| 'wtd' | 'wtd'
| 'ytd' | 'ytd'
| string; // '2024', '2023', '2022', etc. | `${number}`; // '2024', '2023', '2022', etc.

4
libs/common/src/lib/utils/form.util.ts

@ -29,7 +29,7 @@ export async function validateObjectForForm<T>({
if (formControl) { if (formControl) {
formControl.setErrors({ formControl.setErrors({
validationError: Object.values(constraints)[0] validationError: Object.values(constraints ?? {})[0]
}); });
} }
@ -37,7 +37,7 @@ export async function validateObjectForForm<T>({
if (formControlInCustomCurrency) { if (formControlInCustomCurrency) {
formControlInCustomCurrency.setErrors({ formControlInCustomCurrency.setErrors({
validationError: Object.values(constraints)[0] validationError: Object.values(constraints ?? {})[0]
}); });
} }
} }

2
libs/common/src/lib/validators/is-currency-code.ts

@ -9,7 +9,7 @@ import {
import { isISO4217CurrencyCode } from 'class-validator'; import { isISO4217CurrencyCode } from 'class-validator';
export function IsCurrencyCode(validationOptions?: ValidationOptions) { export function IsCurrencyCode(validationOptions?: ValidationOptions) {
return function (object: Object, propertyName: string) { return function (object: object, propertyName: string) {
registerDecorator({ registerDecorator({
propertyName, propertyName,
constraints: [], constraints: [],

Loading…
Cancel
Save