|
@ -28,6 +28,22 @@ export class ExportService { |
|
|
}): Promise<Export> { |
|
|
}): Promise<Export> { |
|
|
const platformsMap: { [platformId: string]: Platform } = {}; |
|
|
const platformsMap: { [platformId: string]: Platform } = {}; |
|
|
|
|
|
|
|
|
|
|
|
let { activities } = await this.orderService.getOrders({ |
|
|
|
|
|
filters, |
|
|
|
|
|
userCurrency, |
|
|
|
|
|
userId, |
|
|
|
|
|
includeDrafts: true, |
|
|
|
|
|
sortColumn: 'date', |
|
|
|
|
|
sortDirection: 'asc', |
|
|
|
|
|
withExcludedAccounts: true |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (activityIds) { |
|
|
|
|
|
activities = activities.filter((activity) => { |
|
|
|
|
|
return activityIds.includes(activity.id); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const accounts = ( |
|
|
const accounts = ( |
|
|
await this.accountService.accounts({ |
|
|
await this.accountService.accounts({ |
|
|
include: { |
|
|
include: { |
|
@ -39,57 +55,49 @@ export class ExportService { |
|
|
}, |
|
|
}, |
|
|
where: { userId } |
|
|
where: { userId } |
|
|
}) |
|
|
}) |
|
|
).map( |
|
|
) |
|
|
({ |
|
|
.filter((account) => |
|
|
balance, |
|
|
activities.some(({ accountId }) => accountId === account.id) |
|
|
balances, |
|
|
) |
|
|
comment, |
|
|
.map( |
|
|
currency, |
|
|
({ |
|
|
id, |
|
|
|
|
|
isExcluded, |
|
|
|
|
|
name, |
|
|
|
|
|
Platform: platform, |
|
|
|
|
|
platformId |
|
|
|
|
|
}) => { |
|
|
|
|
|
if (platformId) { |
|
|
|
|
|
platformsMap[platformId] = platform; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
balance, |
|
|
balance, |
|
|
balances: balances.map(({ date, value }) => { |
|
|
balances, |
|
|
return { date: date.toISOString(), value }; |
|
|
|
|
|
}), |
|
|
|
|
|
comment, |
|
|
comment, |
|
|
currency, |
|
|
currency, |
|
|
id, |
|
|
id, |
|
|
isExcluded, |
|
|
isExcluded, |
|
|
name, |
|
|
name, |
|
|
|
|
|
Platform: platform, |
|
|
platformId |
|
|
platformId |
|
|
}; |
|
|
}) => { |
|
|
} |
|
|
if (platformId) { |
|
|
); |
|
|
platformsMap[platformId] = platform; |
|
|
|
|
|
} |
|
|
let { activities } = await this.orderService.getOrders({ |
|
|
|
|
|
filters, |
|
|
|
|
|
userCurrency, |
|
|
|
|
|
userId, |
|
|
|
|
|
includeDrafts: true, |
|
|
|
|
|
sortColumn: 'date', |
|
|
|
|
|
sortDirection: 'asc', |
|
|
|
|
|
withExcludedAccounts: true |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (activityIds) { |
|
|
return { |
|
|
activities = activities.filter((activity) => { |
|
|
balance, |
|
|
return activityIds.includes(activity.id); |
|
|
balances: balances.map(({ date, value }) => { |
|
|
}); |
|
|
return { date: date.toISOString(), value }; |
|
|
} |
|
|
}), |
|
|
|
|
|
comment, |
|
|
|
|
|
currency, |
|
|
|
|
|
id, |
|
|
|
|
|
isExcluded, |
|
|
|
|
|
name, |
|
|
|
|
|
platformId |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
const tags = (await this.tagService.getTagsForUser(userId)) |
|
|
const tags = (await this.tagService.getTagsForUser(userId)) |
|
|
.filter(({ isUsed }) => { |
|
|
.filter( |
|
|
return isUsed; |
|
|
(tag) => |
|
|
}) |
|
|
tag.isUsed && |
|
|
|
|
|
activities.some((activity) => |
|
|
|
|
|
activity.tags.some(({ id: tagId }) => tagId === tag.id) |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
.map(({ id, name }) => { |
|
|
.map(({ id, name }) => { |
|
|
return { |
|
|
return { |
|
|
id, |
|
|
id, |
|
|