|
|
@ -129,8 +129,7 @@ export class UserService { |
|
|
const [ |
|
|
const [ |
|
|
access, |
|
|
access, |
|
|
accounts, |
|
|
accounts, |
|
|
activitiesCount, |
|
|
activitiesGroupedByType, |
|
|
firstActivity, |
|
|
|
|
|
impersonationUser, |
|
|
impersonationUser, |
|
|
tagsForUser |
|
|
tagsForUser |
|
|
] = await Promise.all([ |
|
|
] = await Promise.all([ |
|
|
@ -150,13 +149,10 @@ export class UserService { |
|
|
userId: impersonationUserId || user.id |
|
|
userId: impersonationUserId || user.id |
|
|
} |
|
|
} |
|
|
}), |
|
|
}), |
|
|
this.prismaService.order.count({ |
|
|
this.prismaService.order.groupBy({ |
|
|
where: { userId: impersonationUserId || user.id } |
|
|
_min: { date: true }, |
|
|
}), |
|
|
by: ['type'], |
|
|
this.prismaService.order.findFirst({ |
|
|
orderBy: { _min: { date: 'asc' } }, |
|
|
orderBy: { |
|
|
|
|
|
date: 'asc' |
|
|
|
|
|
}, |
|
|
|
|
|
where: { userId: impersonationUserId || user.id } |
|
|
where: { userId: impersonationUserId || user.id } |
|
|
}), |
|
|
}), |
|
|
impersonationUserId |
|
|
impersonationUserId |
|
|
@ -165,6 +161,19 @@ export class UserService { |
|
|
this.tagService.getTagsForUser(impersonationUserId || user.id) |
|
|
this.tagService.getTagsForUser(impersonationUserId || user.id) |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
const activitiesCount = impersonationUserId |
|
|
|
|
|
? (impersonationUser?.activitiesCount ?? 0) |
|
|
|
|
|
: (user.activitiesCount ?? 0); |
|
|
|
|
|
|
|
|
|
|
|
const activityTypes = activitiesGroupedByType.map(({ type }) => { |
|
|
|
|
|
return type; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// The groupBy is ordered by the minimum date, thus the first group
|
|
|
|
|
|
// carries the date of the first activity
|
|
|
|
|
|
const dateOfFirstActivity = |
|
|
|
|
|
activitiesGroupedByType[0]?._min.date ?? new Date(); |
|
|
|
|
|
|
|
|
const resolvedUserSettings = resolveUserSettings({ |
|
|
const resolvedUserSettings = resolveUserSettings({ |
|
|
impersonationUserSettings: impersonationUser?.settings |
|
|
impersonationUserSettings: impersonationUser?.settings |
|
|
?.settings as UserSettings, |
|
|
?.settings as UserSettings, |
|
|
@ -209,6 +218,8 @@ export class UserService { |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
activitiesCount, |
|
|
activitiesCount, |
|
|
|
|
|
activityTypes, |
|
|
|
|
|
dateOfFirstActivity, |
|
|
id, |
|
|
id, |
|
|
permissions, |
|
|
permissions, |
|
|
referralPartners, |
|
|
referralPartners, |
|
|
@ -226,7 +237,6 @@ export class UserService { |
|
|
accounts: accounts.sort((a, b) => { |
|
|
accounts: accounts.sort((a, b) => { |
|
|
return a.name.toLowerCase().localeCompare(b.name.toLowerCase()); |
|
|
return a.name.toLowerCase().localeCompare(b.name.toLowerCase()); |
|
|
}), |
|
|
}), |
|
|
dateOfFirstActivity: firstActivity?.date ?? new Date(), |
|
|
|
|
|
settings: { |
|
|
settings: { |
|
|
...resolvedUserSettings, |
|
|
...resolvedUserSettings, |
|
|
baseCurrency: resolvedUserSettings.baseCurrency ?? DEFAULT_CURRENCY, |
|
|
baseCurrency: resolvedUserSettings.baseCurrency ?? DEFAULT_CURRENCY, |
|
|
@ -324,6 +334,7 @@ export class UserService { |
|
|
const user: UserWithSettings = { |
|
|
const user: UserWithSettings = { |
|
|
accessToken, |
|
|
accessToken, |
|
|
accounts, |
|
|
accounts, |
|
|
|
|
|
activitiesCount, |
|
|
authChallenge, |
|
|
authChallenge, |
|
|
createdAt, |
|
|
createdAt, |
|
|
id, |
|
|
id, |
|
|
@ -332,7 +343,6 @@ export class UserService { |
|
|
settings: settings as UserWithSettings['settings'], |
|
|
settings: settings as UserWithSettings['settings'], |
|
|
thirdPartyId, |
|
|
thirdPartyId, |
|
|
updatedAt, |
|
|
updatedAt, |
|
|
activityCount: analytics?.activityCount, |
|
|
|
|
|
dataProviderGhostfolioDailyRequests: |
|
|
dataProviderGhostfolioDailyRequests: |
|
|
analytics?.dataProviderGhostfolioDailyRequests ?? 0 |
|
|
analytics?.dataProviderGhostfolioDailyRequests ?? 0 |
|
|
}; |
|
|
}; |
|
|
|