diff --git a/apps/api/src/app/export/export.controller.ts b/apps/api/src/app/export/export.controller.ts index ce02d9835..51b7bf632 100644 --- a/apps/api/src/app/export/export.controller.ts +++ b/apps/api/src/app/export/export.controller.ts @@ -20,6 +20,7 @@ export class ExportController { ): Promise { return this.exportService.export({ activityIds, + userCurrency: this.request.user.Settings.settings.baseCurrency, userId: this.request.user.id }); } diff --git a/apps/api/src/app/export/export.service.ts b/apps/api/src/app/export/export.service.ts index 2134a6520..031111d7f 100644 --- a/apps/api/src/app/export/export.service.ts +++ b/apps/api/src/app/export/export.service.ts @@ -13,9 +13,11 @@ export class ExportService { public async export({ activityIds, + userCurrency, userId }: { activityIds?: string[]; + userCurrency: string; userId: string; }): Promise { const accounts = ( @@ -39,10 +41,13 @@ export class ExportService { } ); - let activities = await this.orderService.orders({ - include: { SymbolProfile: true }, - orderBy: { date: 'desc' }, - where: { userId } + let { activities } = await this.orderService.getOrders({ + userCurrency, + userId, + includeDrafts: true, + sortColumn: 'date', + sortDirection: 'asc', + withExcludedAccounts: true }); if (activityIds) { diff --git a/apps/api/src/app/import/import.service.ts b/apps/api/src/app/import/import.service.ts index f89c57770..d15e8d437 100644 --- a/apps/api/src/app/import/import.service.ts +++ b/apps/api/src/app/import/import.service.ts @@ -236,6 +236,7 @@ export class ImportService { const activitiesExtendedWithErrors = await this.extendActivitiesWithErrors({ activitiesDto, + userCurrency, userId }); @@ -459,15 +460,18 @@ export class ImportService { private async extendActivitiesWithErrors({ activitiesDto, + userCurrency, userId }: { activitiesDto: Partial[]; + userCurrency: string; userId: string; }): Promise[]> { - const existingActivities = await this.orderService.orders({ - include: { SymbolProfile: true }, - orderBy: { date: 'desc' }, - where: { userId } + let { activities: existingActivities } = await this.orderService.getOrders({ + userCurrency, + userId, + includeDrafts: true, + withExcludedAccounts: true }); return activitiesDto.map( diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index 574bfdcd2..096aba6f5 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/apps/api/src/app/order/order.service.ts @@ -25,7 +25,7 @@ import { endOfToday, isAfter } from 'date-fns'; import { groupBy } from 'lodash'; import { v4 as uuidv4 } from 'uuid'; -import { Activities, Activity } from './interfaces/activities.interface'; +import { Activities } from './interfaces/activities.interface'; @Injectable() export class OrderService { @@ -37,34 +37,6 @@ export class OrderService { private readonly symbolProfileService: SymbolProfileService ) {} - public async order( - orderWhereUniqueInput: Prisma.OrderWhereUniqueInput - ): Promise { - return this.prismaService.order.findUnique({ - where: orderWhereUniqueInput - }); - } - - public async orders(params: { - include?: Prisma.OrderInclude; - skip?: number; - take?: number; - cursor?: Prisma.OrderWhereUniqueInput; - where?: Prisma.OrderWhereInput; - orderBy?: Prisma.Enumerable; - }): Promise { - const { include, skip, take, cursor, where, orderBy } = params; - - return this.prismaService.order.findMany({ - cursor, - include, - orderBy, - skip, - take, - where - }); - } - public async createOrder( data: Prisma.OrderCreateInput & { accountId?: string; @@ -379,6 +351,14 @@ export class OrderService { return { activities, count }; } + public async order( + orderWhereUniqueInput: Prisma.OrderWhereUniqueInput + ): Promise { + return this.prismaService.order.findUnique({ + where: orderWhereUniqueInput + }); + } + public async updateOrder({ data, where @@ -455,4 +435,24 @@ export class OrderService { where }); } + + private async orders(params: { + include?: Prisma.OrderInclude; + skip?: number; + take?: number; + cursor?: Prisma.OrderWhereUniqueInput; + where?: Prisma.OrderWhereInput; + orderBy?: Prisma.Enumerable; + }): Promise { + const { include, skip, take, cursor, where, orderBy } = params; + + return this.prismaService.order.findMany({ + cursor, + include, + orderBy, + skip, + take, + where + }); + } }