Browse Source

Keep symbol profile relation in create activity endpoint

pull/7984/head
Thomas Kaul 2 weeks ago
parent
commit
59b79d4bda
  1. 18
      apps/api/src/app/activities/activities.controller.ts
  2. 66
      apps/api/src/helper/object.helper.spec.ts
  3. 7
      libs/common/src/lib/config.ts

18
apps/api/src/app/activities/activities.controller.ts

@ -33,7 +33,7 @@ import {
Query, Query,
UseInterceptors UseInterceptors
} from '@nestjs/common'; } from '@nestjs/common';
import { Order, SymbolProfile } from '@prisma/client'; import { Order, Prisma } from '@prisma/client';
import { parseISO } from 'date-fns'; import { parseISO } from 'date-fns';
import { StatusCodes, getReasonPhrase } from 'http-status-codes'; import { StatusCodes, getReasonPhrase } from 'http-status-codes';
@ -217,16 +217,7 @@ export class ActivitiesController {
userId, userId,
userSubscription userSubscription
}: ImpersonationContext }: ImpersonationContext
): Promise< ): Promise<Prisma.OrderGetPayload<{ include: { SymbolProfile: true } }>> {
Order & {
assetProfile: SymbolProfile;
/**
* @deprecated Use `assetProfile` instead
*/
SymbolProfile: SymbolProfile;
}
> {
// Evaluate the more restrictive subscription of the authenticated user // Evaluate the more restrictive subscription of the authenticated user
// and the owner of the activity // and the owner of the activity
const subscription = const subscription =
@ -312,10 +303,7 @@ export class ActivitiesController {
}); });
} }
return { return activity;
...activity,
assetProfile: activity.SymbolProfile
};
} }
@HasPermission(permissions.updateActivity) @HasPermission(permissions.updateActivity)

66
apps/api/src/helper/object.helper.spec.ts

@ -3082,20 +3082,6 @@ describe('redactAttributes', () => {
feeInBaseCurrency: 18.2, feeInBaseCurrency: 18.2,
id: '8c623328-6035-4b5f-b6d5-702cc1c9c56b', id: '8c623328-6035-4b5f-b6d5-702cc1c9c56b',
quantity: 50, quantity: 50,
// The relation of the database is part of the response next to the
// asset profile
SymbolProfile: {
comment: 'Reviewed by the administrator',
name: 'Apple Inc',
scraperConfiguration: {
headers: { Authorization: 'Bearer TOKEN' },
mode: 'lazy',
selector: '.price',
url: 'https://example.org/get_price'
},
symbol: 'AAPL',
symbolMapping: { YAHOO: 'AAPL' }
},
type: 'BUY', type: 'BUY',
unitPrice: 220.79, unitPrice: 220.79,
value: 11039.5, value: 11039.5,
@ -3125,6 +3111,49 @@ describe('redactAttributes', () => {
feeInBaseCurrency: null, feeInBaseCurrency: null,
id: '8c623328-6035-4b5f-b6d5-702cc1c9c56b', id: '8c623328-6035-4b5f-b6d5-702cc1c9c56b',
quantity: null, quantity: null,
type: 'BUY',
// A price per unit stays visible, like the average price and the market
// price of a holding
unitPrice: 220.79,
value: null,
valueInBaseCurrency: null
});
});
// The endpoint POST api/v1/activities returns a row of the database with the
// relation to the symbol profile
it('should redact an activity with the relation to the symbol profile', () => {
expect(
redactPaths({
object: {
comment: 'Bought on a dip',
currency: 'USD',
fee: 19.9,
id: '8c623328-6035-4b5f-b6d5-702cc1c9c56b',
quantity: 50,
SymbolProfile: {
comment: 'Reviewed by the administrator',
name: 'Apple Inc',
scraperConfiguration: {
headers: { Authorization: 'Bearer TOKEN' },
mode: 'lazy',
selector: '.price',
url: 'https://example.org/get_price'
},
symbol: 'AAPL',
symbolMapping: { YAHOO: 'AAPL' }
},
type: 'BUY',
unitPrice: 220.79
},
paths: DEFAULT_REDACTED_PATHS
})
).toStrictEqual({
comment: null,
currency: 'USD',
fee: null,
id: '8c623328-6035-4b5f-b6d5-702cc1c9c56b',
quantity: null,
SymbolProfile: { SymbolProfile: {
comment: null, comment: null,
name: 'Apple Inc', name: 'Apple Inc',
@ -3133,15 +3162,12 @@ describe('redactAttributes', () => {
symbolMapping: null symbolMapping: null
}, },
type: 'BUY', type: 'BUY',
// A price per unit stays visible, like the average price and the market unitPrice: 220.79
// price of a holding
unitPrice: 220.79,
value: null,
valueInBaseCurrency: null
}); });
}); });
// The write endpoints return a row of the database, which has no relation // The endpoints PUT and DELETE api/v1/activities/:id return a row of the
// database without the relations
it('should redact an activity without the relations', () => { it('should redact an activity without the relations', () => {
expect( expect(
redactPaths({ redactPaths({

7
libs/common/src/lib/config.ts

@ -180,16 +180,9 @@ export const DEFAULT_REDACTED_PATHS = [
'settings.emergencyFund', 'settings.emergencyFund',
'settings.projectedTotalAmount', 'settings.projectedTotalAmount',
'settings.savingsRate', 'settings.savingsRate',
/* @deprecated */
'SymbolProfile.comment', 'SymbolProfile.comment',
/* @deprecated */
'SymbolProfile.scraperConfiguration', 'SymbolProfile.scraperConfiguration',
/* @deprecated */
'SymbolProfile.symbolMapping', 'SymbolProfile.symbolMapping',
'totalBalanceInBaseCurrency', 'totalBalanceInBaseCurrency',
'totalDividendInBaseCurrency', 'totalDividendInBaseCurrency',
'totalInterestInBaseCurrency', 'totalInterestInBaseCurrency',

Loading…
Cancel
Save