Browse Source

Allow to create and update accounts

pull/60/head
Thomas 4 years ago
parent
commit
fa937e4632
  1. 23
      apps/api/src/app/account/account.controller.ts
  2. 29
      apps/api/src/app/account/create-account.dto.ts
  3. 3
      apps/api/src/app/account/interfaces/order-with-platform.type.ts
  4. 31
      apps/api/src/app/account/update-account.dto.ts
  5. 7
      apps/api/src/app/order/order.controller.ts
  6. 7
      apps/client/src/app/components/accounts-table/accounts-table.component.html
  7. 14
      apps/client/src/app/components/accounts-table/accounts-table.component.ts
  8. 2
      apps/client/src/app/components/header/header.component.html
  9. 4
      apps/client/src/app/components/transactions-table/transactions-table.component.ts
  10. 69
      apps/client/src/app/pages/accounts/accounts-page.component.ts
  11. 67
      apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts
  12. 136
      apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.html
  13. 8
      apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.module.ts
  14. 6
      apps/client/src/app/pages/accounts/create-or-update-account-dialog/interfaces/interfaces.ts
  15. 15
      apps/client/src/app/pages/accounts/interfaces/order.interface.ts
  16. 4
      apps/client/src/app/pages/transactions/create-or-update-transaction-dialog/interfaces/interfaces.ts
  17. 15
      apps/client/src/app/pages/transactions/interfaces/order.interface.ts
  18. 3
      apps/client/src/app/pages/transactions/transactions-page.component.ts
  19. 9
      apps/client/src/app/services/data.service.ts
  20. 6
      libs/helper/src/lib/permissions.ts

23
apps/api/src/app/account/account.controller.ts

@ -47,6 +47,20 @@ export class AccountController {
);
}
const account = await this.accountService.account({
id_userId: {
id,
userId: this.request.user.id
}
});
if (account.isDefault) {
throw new HttpException(
getReasonPhrase(StatusCodes.FORBIDDEN),
StatusCodes.FORBIDDEN
);
}
return this.accountService.deleteAccount(
{
id_userId: {
@ -70,7 +84,7 @@ export class AccountController {
let accounts = await this.accountService.accounts({
include: { Platform: true },
orderBy: { name: 'desc' },
orderBy: { name: 'asc' },
where: { userId: impersonationUserId || this.request.user.id }
});
@ -166,6 +180,13 @@ export class AccountController {
}
});
if (!originalAccount) {
throw new HttpException(
getReasonPhrase(StatusCodes.FORBIDDEN),
StatusCodes.FORBIDDEN
);
}
if (data.platformId) {
const platformId = data.platformId;
delete data.platformId;

29
apps/api/src/app/account/create-account.dto.ts

@ -1,35 +1,14 @@
import { Currency, DataSource, Type } from '@prisma/client';
import { IsISO8601, IsNumber, IsString, ValidateIf } from 'class-validator';
import { AccountType } from '@prisma/client';
import { IsString, ValidateIf } from 'class-validator';
export class CreateAccountDto {
@IsString()
accountId: string;
accountType: AccountType;
@IsString()
currency: Currency;
@IsString()
dataSource: DataSource;
@IsISO8601()
date: string;
@IsNumber()
fee: number;
name: string;
@IsString()
@ValidateIf((object, value) => value !== null)
platformId: string | null;
@IsNumber()
quantity: number;
@IsString()
symbol: string;
@IsString()
type: Type;
@IsNumber()
unitPrice: number;
}

3
apps/api/src/app/account/interfaces/order-with-platform.type.ts

@ -1,3 +0,0 @@
import { Order, Platform } from '@prisma/client';
export type OrderWithPlatform = Order & { Platform?: Platform };

31
apps/api/src/app/account/update-account.dto.ts

@ -1,38 +1,17 @@
import { Currency, DataSource, Type } from '@prisma/client';
import { IsISO8601, IsNumber, IsString, ValidateIf } from 'class-validator';
import { AccountType } from '@prisma/client';
import { IsString, ValidateIf } from 'class-validator';
export class UpdateAccountDto {
@IsString()
accountId: string;
accountType: AccountType;
@IsString()
currency: Currency;
id: string;
@IsString()
dataSource: DataSource;
@IsISO8601()
date: string;
@IsNumber()
fee: number;
name: string;
@IsString()
@ValidateIf((object, value) => value !== null)
platformId: string | null;
@IsString()
id: string;
@IsNumber()
quantity: number;
@IsString()
symbol: string;
@IsString()
type: Type;
@IsNumber()
unitPrice: number;
}

7
apps/api/src/app/order/order.controller.ts

@ -184,6 +184,13 @@ export class OrderController {
}
});
if (!originalOrder) {
throw new HttpException(
getReasonPhrase(StatusCodes.FORBIDDEN),
StatusCodes.FORBIDDEN
);
}
const date = parseISO(data.date);
const accountId = data.accountId;

7
apps/client/src/app/components/accounts-table/accounts-table.component.html

@ -64,7 +64,12 @@
<button i18n mat-menu-item (click)="onUpdateAccount(element)">
Edit
</button>
<button i18n mat-menu-item (click)="onDeleteAccount(element.id)">
<button
i18n
mat-menu-item
[disabled]="element.isDefault"
(click)="onDeleteAccount(element.id)"
>
Delete
</button>
</mat-menu>

14
apps/client/src/app/components/accounts-table/accounts-table.component.ts

@ -13,7 +13,7 @@ import { MatDialog } from '@angular/material/dialog';
import { MatSort } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table';
import { ActivatedRoute, Router } from '@angular/router';
import { Order as OrderModel } from '@prisma/client';
import { Account as AccountModel } from '@prisma/client';
import { Subject, Subscription } from 'rxjs';
@Component({
@ -23,18 +23,18 @@ import { Subject, Subscription } from 'rxjs';
styleUrls: ['./accounts-table.component.scss']
})
export class AccountsTableComponent implements OnChanges, OnDestroy, OnInit {
@Input() accounts: OrderModel[];
@Input() accounts: AccountModel[];
@Input() baseCurrency: string;
@Input() deviceType: string;
@Input() locale: string;
@Input() showActions: boolean;
@Output() accountDeleted = new EventEmitter<string>();
@Output() accountToUpdate = new EventEmitter<OrderModel>();
@Output() accountToUpdate = new EventEmitter<AccountModel>();
@ViewChild(MatSort) sort: MatSort;
public dataSource: MatTableDataSource<OrderModel> = new MatTableDataSource();
public dataSource: MatTableDataSource<AccountModel> = new MatTableDataSource();
public displayedColumns = [];
public isLoading = true;
public routeQueryParams: Subscription;
@ -52,12 +52,12 @@ export class AccountsTableComponent implements OnChanges, OnDestroy, OnInit {
public ngOnChanges() {
this.displayedColumns = ['account', 'type', 'platform'];
this.isLoading = true;
if (this.showActions) {
this.displayedColumns.push('actions');
}
this.isLoading = true;
if (this.accounts) {
this.dataSource = new MatTableDataSource(this.accounts);
this.dataSource.sort = this.sort;
@ -74,7 +74,7 @@ export class AccountsTableComponent implements OnChanges, OnDestroy, OnInit {
}
}
public onUpdateAccount(aAccount: OrderModel) {
public onUpdateAccount(aAccount: AccountModel) {
this.accountToUpdate.emit(aAccount);
}

2
apps/client/src/app/components/header/header.component.html

@ -163,7 +163,7 @@
i18n
mat-menu-item
[ngClass]="{ 'font-weight-bold': currentRoute === 'account' }"
>Account</a
>Ghostfolio Account</a
>
<a
*ngIf="hasPermissionToAccessAdminControl"

4
apps/client/src/app/components/transactions-table/transactions-table.component.ts

@ -78,12 +78,12 @@ export class TransactionsTableComponent
'fee'
];
this.isLoading = true;
if (this.showActions) {
this.displayedColumns.push('actions');
}
this.isLoading = true;
if (this.transactions) {
this.dataSource = new MatTableDataSource(this.transactions);
this.dataSource.sort = this.sort;

69
apps/client/src/app/pages/accounts/accounts-page.component.ts

@ -1,13 +1,14 @@
import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import { UpdateOrderDto } from '@ghostfolio/api/app/order/update-order.dto';
import { CreateAccountDto } from '@ghostfolio/api/app/account/create-account.dto';
import { UpdateAccountDto } from '@ghostfolio/api/app/account/update-account.dto';
import { User } from '@ghostfolio/api/app/user/interfaces/user.interface';
import { DataService } from '@ghostfolio/client/services/data.service';
import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service';
import { TokenStorageService } from '@ghostfolio/client/services/token-storage.service';
import { hasPermission, permissions } from '@ghostfolio/helper';
import { Order as OrderModel } from '@prisma/client';
import { AccountType, Account as AccountModel } from '@prisma/client';
import { DeviceDetectorService } from 'ngx-device-detector';
import { Subject, Subscription } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@ -20,7 +21,7 @@ import { CreateOrUpdateAccountDialog } from './create-or-update-account-dialog/c
styleUrls: ['./accounts-page.scss']
})
export class AccountsPageComponent implements OnInit {
public accounts: OrderModel[];
public accounts: AccountModel[];
public deviceType: string;
public hasImpersonationId: boolean;
public hasPermissionToCreateAccount: boolean;
@ -116,40 +117,25 @@ export class AccountsPageComponent implements OnInit {
});
}
public onUpdateAccount(aAccount: OrderModel) {
public onUpdateAccount(aAccount: AccountModel) {
this.router.navigate([], {
queryParams: { editDialog: true, transactionId: aAccount.id }
});
}
public openUpdateAccountDialog({
accountId,
currency,
dataSource,
date,
fee,
accountType,
id,
platformId,
quantity,
symbol,
type,
unitPrice
}: OrderModel): void {
name,
platformId
}: AccountModel): void {
const dialogRef = this.dialog.open(CreateOrUpdateAccountDialog, {
data: {
accounts: this.user.accounts,
transaction: {
accountId,
currency,
dataSource,
date,
fee,
account: {
accountType,
id,
platformId,
quantity,
symbol,
type,
unitPrice
name,
platformId
}
},
height: this.deviceType === 'mobile' ? '97.5vh' : '80vh',
@ -157,10 +143,10 @@ export class AccountsPageComponent implements OnInit {
});
dialogRef.afterClosed().subscribe((data: any) => {
const transaction: UpdateOrderDto = data?.transaction;
const account: UpdateAccountDto = data?.account;
if (transaction) {
this.dataService.putAccount(transaction).subscribe({
if (account) {
this.dataService.putAccount(account).subscribe({
next: () => {
this.fetchAccounts();
}
@ -179,19 +165,10 @@ export class AccountsPageComponent implements OnInit {
private openCreateAccountDialog(): void {
const dialogRef = this.dialog.open(CreateOrUpdateAccountDialog, {
data: {
accounts: this.user?.accounts,
transaction: {
accountId: this.user?.accounts.find((account) => {
return account.isDefault;
})?.id,
currency: null,
date: new Date(),
fee: 0,
platformId: null,
quantity: null,
symbol: null,
type: 'BUY',
unitPrice: null
account: {
accountType: AccountType.SECURITIES,
name: null,
platformId: null
}
},
height: this.deviceType === 'mobile' ? '97.5vh' : '80vh',
@ -199,10 +176,10 @@ export class AccountsPageComponent implements OnInit {
});
dialogRef.afterClosed().subscribe((data: any) => {
const transaction: UpdateOrderDto = data?.transaction;
const account: CreateAccountDto = data?.account;
if (transaction) {
this.dataService.postAccount(transaction).subscribe({
if (account) {
this.dataService.postAccount(account).subscribe({
next: () => {
this.fetchAccounts();
}

67
apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts

@ -1,47 +1,25 @@
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Inject
} from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { LookupItem } from '@ghostfolio/api/app/symbol/interfaces/lookup-item.interface';
import { Currency } from '@prisma/client';
import { Observable, Subject } from 'rxjs';
import {
debounceTime,
distinctUntilChanged,
startWith,
switchMap,
takeUntil
} from 'rxjs/operators';
import { Subject } from 'rxjs';
import { DataService } from '../../../services/data.service';
import { CreateOrUpdateAccountDialogParams } from './interfaces/interfaces';
@Component({
host: { class: 'h-100' },
selector: 'create-or-update-account-dialog',
selector: 'gf-create-or-update-account-dialog',
changeDetection: ChangeDetectionStrategy.OnPush,
styleUrls: ['./create-or-update-account-dialog.scss'],
templateUrl: 'create-or-update-account-dialog.html'
})
export class CreateOrUpdateAccountDialog {
public currencies: Currency[] = [];
public filteredLookupItems: Observable<LookupItem[]>;
public isLoading = false;
public platforms: { id: string; name: string }[];
public searchSymbolCtrl = new FormControl(
this.data.transaction.symbol,
Validators.required
);
private unsubscribeSubject = new Subject<void>();
public constructor(
private cd: ChangeDetectorRef,
private dataService: DataService,
public dialogRef: MatDialogRef<CreateOrUpdateAccountDialog>,
@Inject(MAT_DIALOG_DATA) public data: CreateOrUpdateAccountDialogParams
@ -52,51 +30,12 @@ export class CreateOrUpdateAccountDialog {
this.currencies = currencies;
this.platforms = platforms;
});
this.filteredLookupItems = this.searchSymbolCtrl.valueChanges.pipe(
startWith(''),
debounceTime(400),
distinctUntilChanged(),
switchMap((aQuery: string) => {
if (aQuery) {
return this.dataService.fetchSymbols(aQuery);
}
return [];
})
);
}
public onCancel(): void {
this.dialogRef.close();
}
public onUpdateSymbol(event: MatAutocompleteSelectedEvent) {
this.isLoading = true;
this.data.transaction.symbol = event.option.value;
this.dataService
.fetchSymbolItem(this.data.transaction.symbol)
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe(({ currency, dataSource, marketPrice }) => {
this.data.transaction.currency = currency;
this.data.transaction.dataSource = dataSource;
this.data.transaction.unitPrice = marketPrice;
this.isLoading = false;
this.cd.markForCheck();
});
}
public onUpdateSymbolByTyping(value: string) {
this.data.transaction.currency = null;
this.data.transaction.dataSource = null;
this.data.transaction.unitPrice = null;
this.data.transaction.symbol = value;
}
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();

136
apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.html

@ -1,145 +1,25 @@
<form #addAccountForm="ngForm" class="d-flex flex-column h-100">
<h1 *ngIf="data.transaction.id" mat-dialog-title i18n>Update account</h1>
<h1 *ngIf="!data.transaction.id" mat-dialog-title i18n>Add account</h1>
<h1 *ngIf="data.account.id" mat-dialog-title i18n>Update account</h1>
<h1 *ngIf="!data.account.id" mat-dialog-title i18n>Add account</h1>
<div class="flex-grow-1" mat-dialog-content>
<div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Symbol or ISIN</mat-label>
<input
autocapitalize="off"
autocomplete="off"
autocorrect="off"
matInput
required
[formControl]="searchSymbolCtrl"
[matAutocomplete]="auto"
(change)="onUpdateSymbolByTyping($event.target.value)"
/>
<mat-autocomplete
#auto="matAutocomplete"
(optionSelected)="onUpdateSymbol($event)"
>
<ng-container>
<mat-option
*ngFor="let lookupItem of filteredLookupItems | async"
class="autocomplete"
[value]="lookupItem.symbol"
>
<span class="mr-2 symbol">{{ lookupItem.symbol | gfSymbol }}</span
><span><b>{{ lookupItem.name }}</b></span>
</mat-option>
</ng-container>
</mat-autocomplete>
<mat-spinner *ngIf="isLoading" matSuffix [diameter]="20"></mat-spinner>
<mat-label i18n>Name</mat-label>
<input matInput name="name" required [(ngModel)]="data.account.name" />
</mat-form-field>
</div>
<div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Type</mat-label>
<mat-select name="type" required [(value)]="data.transaction.type">
<mat-option value="BUY" i18n> BUY </mat-option>
<mat-option value="SELL" i18n> SELL </mat-option>
</mat-select>
</mat-form-field>
</div>
<div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Currency</mat-label>
<mat-select
class="no-arrow"
disabled
name="currency"
required
[(value)]="data.transaction.currency"
>
<mat-option *ngFor="let currency of currencies" [value]="currency"
>{{ currency }}</mat-option
>
</mat-select>
</mat-form-field>
</div>
<div class="d-none">
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Data Source</mat-label>
<input
disabled
matInput
name="dataSource"
required
[(ngModel)]="data.transaction.dataSource"
/>
</mat-form-field>
</div>
<div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Date</mat-label>
<input
disabled
matInput
name="date"
required
[matDatepicker]="date"
[(ngModel)]="data.transaction.date"
/>
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
<mat-datepicker #date disabled="false"></mat-datepicker>
</mat-form-field>
</div>
<div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Fee</mat-label>
<input
matInput
name="fee"
required
type="number"
[(ngModel)]="data.transaction.fee"
/>
</mat-form-field>
</div>
<div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Quantity</mat-label>
<input
matInput
name="quantity"
required
type="number"
[(ngModel)]="data.transaction.quantity"
/>
</mat-form-field>
</div>
<div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Unit Price</mat-label>
<input
matInput
name="unitPrice"
required
type="number"
[(ngModel)]="data.transaction.unitPrice"
/>
</mat-form-field>
</div>
<div class="d-none">
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Account</mat-label>
<mat-select
disabled
name="accountId"
required
[(value)]="data.transaction.accountId"
>
<mat-option *ngFor="let account of data.accounts" [value]="account.id"
>{{ account.name }}</mat-option
>
<mat-select name="type" required [(value)]="data.account.accountType">
<mat-option value="SECURITIES" i18n> SECURITIES </mat-option>
</mat-select>
</mat-form-field>
</div>
<div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Platform</mat-label>
<mat-select name="platformId" [(value)]="data.transaction.platformId">
<mat-select name="platformId" [(value)]="data.account.platformId">
<mat-option [value]="null"></mat-option>
<mat-option *ngFor="let platform of platforms" [value]="platform.id"
>{{ platform.name }}</mat-option
@ -154,7 +34,7 @@
color="primary"
i18n
mat-flat-button
[disabled]="!(addAccountForm.form.valid && data.transaction.symbol)"
[disabled]="!addAccountForm.form.valid"
[mat-dialog-close]="data"
>
Save

8
apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.module.ts

@ -1,15 +1,11 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { MatButtonModule } from '@angular/material/button';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatDialogModule } from '@angular/material/dialog';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { MatSelectModule } from '@angular/material/select';
import { GfSymbolModule } from '@ghostfolio/client/pipes/symbol/symbol.module';
import { CreateOrUpdateAccountDialog } from './create-or-update-account-dialog.component';
@ -18,15 +14,11 @@ import { CreateOrUpdateAccountDialog } from './create-or-update-account-dialog.c
exports: [],
imports: [
CommonModule,
GfSymbolModule,
FormsModule,
MatAutocompleteModule,
MatButtonModule,
MatDatepickerModule,
MatDialogModule,
MatFormFieldModule,
MatInputModule,
MatProgressSpinnerModule,
MatSelectModule,
ReactiveFormsModule
],

6
apps/client/src/app/pages/accounts/create-or-update-account-dialog/interfaces/interfaces.ts

@ -1,9 +1,5 @@
import { Account } from '@prisma/client';
import { Order } from '../../interfaces/order.interface';
export interface CreateOrUpdateAccountDialogParams {
accountId: string;
accounts: Account[];
transaction: Order;
account: Account;
}

15
apps/client/src/app/pages/accounts/interfaces/order.interface.ts

@ -1,15 +0,0 @@
import { Currency, DataSource } from '@prisma/client';
export interface Order {
accountId: string;
currency: Currency;
dataSource: DataSource;
date: Date;
fee: number;
id: string;
quantity: number;
platformId: string;
symbol: string;
type: string;
unitPrice: number;
}

4
apps/client/src/app/pages/transactions/create-or-update-transaction-dialog/interfaces/interfaces.ts

@ -1,6 +1,4 @@
import { Account } from '@prisma/client';
import { Order } from '../../interfaces/order.interface';
import { Account, Order } from '@prisma/client';
export interface CreateOrUpdateTransactionDialogParams {
accountId: string;

15
apps/client/src/app/pages/transactions/interfaces/order.interface.ts

@ -1,15 +0,0 @@
import { Currency, DataSource } from '@prisma/client';
export interface Order {
accountId: string;
currency: Currency;
dataSource: DataSource;
date: Date;
fee: number;
id: string;
quantity: number;
platformId: string;
symbol: string;
type: string;
unitPrice: number;
}

3
apps/client/src/app/pages/transactions/transactions-page.component.ts

@ -1,6 +1,7 @@
import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto';
import { UpdateOrderDto } from '@ghostfolio/api/app/order/update-order.dto';
import { User } from '@ghostfolio/api/app/user/interfaces/user.interface';
import { DataService } from '@ghostfolio/client/services/data.service';
@ -199,7 +200,7 @@ export class TransactionsPageComponent implements OnInit {
});
dialogRef.afterClosed().subscribe((data: any) => {
const transaction: UpdateOrderDto = data?.transaction;
const transaction: CreateOrderDto = data?.transaction;
if (transaction) {
this.dataService.postOrder(transaction).subscribe({

9
apps/client/src/app/services/data.service.ts

@ -1,9 +1,11 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Access } from '@ghostfolio/api/app/access/interfaces/access.interface';
import { CreateAccountDto } from '@ghostfolio/api/app/account/create-account.dto';
import { UpdateAccountDto } from '@ghostfolio/api/app/account/update-account.dto';
import { AdminData } from '@ghostfolio/api/app/admin/interfaces/admin-data.interface';
import { InfoItem } from '@ghostfolio/api/app/info/interfaces/info-item.interface';
import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto';
import { UpdateOrderDto } from '@ghostfolio/api/app/order/update-order.dto';
import { PortfolioItem } from '@ghostfolio/api/app/portfolio/interfaces/portfolio-item.interface';
import { PortfolioOverview } from '@ghostfolio/api/app/portfolio/interfaces/portfolio-overview.interface';
@ -20,6 +22,7 @@ import { UserItem } from '@ghostfolio/api/app/user/interfaces/user-item.interfac
import { User } from '@ghostfolio/api/app/user/interfaces/user.interface';
import { UpdateUserSettingsDto } from '@ghostfolio/api/app/user/update-user-settings.dto';
import { Order as OrderModel } from '@prisma/client';
import { Account as AccountModel } from '@prisma/client';
@Injectable({
providedIn: 'root'
@ -30,7 +33,7 @@ export class DataService {
public constructor(private http: HttpClient) {}
public fetchAccounts() {
return this.http.get<OrderModel[]>('/api/account');
return this.http.get<AccountModel[]>('/api/account');
}
public fetchAdminData() {
@ -117,11 +120,11 @@ export class DataService {
return this.http.get<any>(`/api/auth/anonymous/${accessToken}`);
}
public postAccount(aAccount: UpdateAccountDto) {
public postAccount(aAccount: CreateAccountDto) {
return this.http.post<OrderModel>(`/api/account`, aAccount);
}
public postOrder(aOrder: UpdateOrderDto) {
public postOrder(aOrder: CreateOrderDto) {
return this.http.post<OrderModel>(`/api/order`, aOrder);
}

6
libs/helper/src/lib/permissions.ts

@ -32,9 +32,12 @@ export function getPermissions(aRole: Role): string[] {
case 'ADMIN':
return [
permissions.accessAdminControl,
permissions.createAccount,
permissions.createOrder,
permissions.deleteAccount,
permissions.deleteOrder,
permissions.readForeignPortfolio,
permissions.updateAccount,
permissions.updateOrder,
permissions.updateUserSettings
];
@ -44,8 +47,11 @@ export function getPermissions(aRole: Role): string[] {
case 'USER':
return [
permissions.createAccount,
permissions.createOrder,
permissions.deleteAccount,
permissions.deleteOrder,
permissions.updateAccount,
permissions.updateOrder,
permissions.updateUserSettings
];

Loading…
Cancel
Save