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

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

@ -3082,20 +3082,6 @@ describe('redactAttributes', () => {
feeInBaseCurrency: 18.2,
id: '8c623328-6035-4b5f-b6d5-702cc1c9c56b',
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',
unitPrice: 220.79,
value: 11039.5,
@ -3125,6 +3111,49 @@ describe('redactAttributes', () => {
feeInBaseCurrency: null,
id: '8c623328-6035-4b5f-b6d5-702cc1c9c56b',
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: {
comment: null,
name: 'Apple Inc',
@ -3133,15 +3162,12 @@ describe('redactAttributes', () => {
symbolMapping: 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
unitPrice: 220.79
});
});
// 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', () => {
expect(
redactPaths({

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

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

Loading…
Cancel
Save