Browse Source

update: getUser service

- reorder alphabetically
- select all attribute
pull/5910/head
alfaarghya 2 months ago
parent
commit
55cf174b1e
  1. 82
      apps/api/src/app/admin/admin.service.ts

82
apps/api/src/app/admin/admin.service.ts

@ -509,38 +509,9 @@ export class AdminService {
}; };
} }
public async getUsers({
skip,
take = Number.MAX_SAFE_INTEGER
}: {
skip?: number;
take?: number;
}): Promise<AdminUsersResponse> {
const [count, users] = await Promise.all([
this.countUsersWithAnalytics(),
this.getUsersWithAnalytics({ skip, take })
]);
return { count, users };
}
public async getUser(id: string): Promise<AdminUserResponse> { public async getUser(id: string): Promise<AdminUserResponse> {
const user = await this.prismaService.user.findUnique({ const user = await this.prismaService.user.findUnique({
where: { id },
select: { select: {
id: true,
role: true,
provider: true,
createdAt: true,
updatedAt: true,
analytics: {
select: {
activityCount: true,
country: true,
dataProviderGhostfolioDailyRequests: true,
updatedAt: true
}
},
_count: { _count: {
select: { select: {
accounts: true, accounts: true,
@ -548,49 +519,58 @@ export class AdminService {
watchlist: true watchlist: true
} }
}, },
subscriptions: { analytics: true,
orderBy: { expiresAt: 'desc' }, createdAt: true,
take: 3,
select: {
id: true, id: true,
expiresAt: true, provider: true,
createdAt: true role: true,
} subscriptions: true,
tags: true,
updatedAt: true
}, },
tags: { where: { id }
select: {
id: true,
name: true
}
}
}
}); });
if (!user) { if (!user) {
throw new NotFoundException(`User with ID ${id} not found`); throw new NotFoundException(`User with ID ${id} not found`);
} }
const { _count, analytics, createdAt, id: userId, role, provider } = user; const { _count, analytics, createdAt, provider, role, updatedAt } = user;
return { return {
id: userId,
role,
provider,
createdAt,
updatedAt: user.updatedAt,
accountCount: _count.accounts || 0, accountCount: _count.accounts || 0,
activityCount: _count.activities || 0, activityCount: _count.activities || 0,
watchlistCount: _count.watchlist || 0,
analytics: { analytics: {
country: analytics?.country, country: analytics?.country,
dailyApiRequests: analytics?.dataProviderGhostfolioDailyRequests || 0, dailyApiRequests: analytics?.dataProviderGhostfolioDailyRequests || 0,
lastActivity: analytics?.updatedAt lastActivity: analytics?.updatedAt
}, },
createdAt,
id,
provider,
role,
subscriptions: user.subscriptions, subscriptions: user.subscriptions,
tags: user.tags tags: user.tags,
updatedAt,
watchlistCount: _count.watchlist || 0
}; };
} }
public async getUsers({
skip,
take = Number.MAX_SAFE_INTEGER
}: {
skip?: number;
take?: number;
}): Promise<AdminUsersResponse> {
const [count, users] = await Promise.all([
this.countUsersWithAnalytics(),
this.getUsersWithAnalytics({ skip, take })
]);
return { count, users };
}
public async patchAssetProfileData( public async patchAssetProfileData(
{ dataSource, symbol }: AssetProfileIdentifier, { dataSource, symbol }: AssetProfileIdentifier,
{ {

Loading…
Cancel
Save