Browse Source

Extend accounts endpoint by accounts, assetClasses and tags filters

pull/7748/head
Thomas Kaul 14 hours ago
parent
commit
bb3ae9be1d
  1. 14
      apps/api/src/app/portfolio/portfolio.service.spec.ts
  2. 50
      apps/api/src/app/portfolio/portfolio.service.ts

14
apps/api/src/app/portfolio/portfolio.service.spec.ts

@ -118,10 +118,12 @@ describe('PortfolioService', () => {
describe('getAccounts', () => {
const tagId = 'd6bf8b4a-8ef9-4b3f-9e2c-0a1b2c3d4e5f';
const whereTagsOfActivity = { some: { OR: [{ id: tagId }] } };
const whereActivityOfTag = {
OR: [
{ tags: { some: { OR: [{ id: tagId }] } } },
{ account: { tags: { some: { OR: [{ tagId }] } } } }
{ account: { tags: { some: { OR: [{ tagId }] } } } },
{ tags: whereTagsOfActivity }
]
};
@ -184,8 +186,8 @@ describe('PortfolioService', () => {
expect(where.AND).toEqual([
{
OR: [
{ tags: { some: { OR: [{ tagId }] } } },
{ activities: { some: whereActivityOfTag } }
{ activities: { some: { tags: whereTagsOfActivity } } },
{ tags: { some: { OR: [{ tagId }] } } }
]
}
]);
@ -234,8 +236,8 @@ describe('PortfolioService', () => {
{ activities: { some: whereActivityOfAssetClass } },
{
OR: [
{ tags: { some: { OR: [{ tagId }] } } },
{ activities: { some: whereActivityOfTag } }
{ activities: { some: { tags: whereTagsOfActivity } } },
{ tags: { some: { OR: [{ tagId }] } } }
]
}
]);

50
apps/api/src/app/portfolio/portfolio.service.ts

@ -143,7 +143,7 @@ export class PortfolioService {
const where: Prisma.AccountWhereInput = { userId };
const {
ACCOUNT: [filterByAccount] = [],
ACCOUNT: filtersByAccount = [],
ASSET_CLASS: filtersByAssetClass = [],
DATA_SOURCE: [filterByDataSource] = [],
SYMBOL: [filterBySymbol] = [],
@ -152,24 +152,28 @@ export class PortfolioService {
return type;
});
if (filterByAccount) {
where.id = filterByAccount.id;
if (filtersByAccount.length > 0) {
where.id = {
in: filtersByAccount.map(({ id }) => {
return id;
})
};
}
const whereAccountConditions: Prisma.AccountWhereInput[] = [];
const whereActivityConditions: Prisma.OrderWhereInput[] = [];
if (filtersByAssetClass.length > 0) {
const whereAssetClassConditions = filtersByAssetClass.map(({ id }) => {
return { assetClass: AssetClass[id] };
});
const whereActivityOfAssetClass: Prisma.OrderWhereInput = {
SymbolProfile: {
OR: [
{
AND: [
{
OR: filtersByAssetClass.map(({ id }) => {
return { assetClass: AssetClass[id] };
})
},
{ OR: whereAssetClassConditions },
{
OR: [
{ assetProfileOverrides: { is: null } },
@ -179,11 +183,7 @@ export class PortfolioService {
]
},
{
assetProfileOverrides: {
OR: filtersByAssetClass.map(({ id }) => {
return { assetClass: AssetClass[id] };
})
}
assetProfileOverrides: { OR: whereAssetClassConditions }
}
]
}
@ -222,25 +222,25 @@ export class PortfolioService {
}
};
const whereTagsOfActivity: Prisma.TagListRelationFilter = {
some: {
OR: filtersByTag.map(({ id }) => {
return { id };
})
}
};
const whereActivityOfTag: Prisma.OrderWhereInput = {
OR: [
{
tags: {
some: {
OR: filtersByTag.map(({ id }) => {
return { id };
})
}
}
},
{ account: { tags: whereTagsOfAccount } }
{ account: { tags: whereTagsOfAccount } },
{ tags: whereTagsOfActivity }
]
};
whereAccountConditions.push({
OR: [
{ tags: whereTagsOfAccount },
{ activities: { some: whereActivityOfTag } }
{ activities: { some: { tags: whereTagsOfActivity } } },
{ tags: whereTagsOfAccount }
]
});

Loading…
Cancel
Save