From 471c3d894cb68d68ec73b3a3bdfd26d9e39f1712 Mon Sep 17 00:00:00 2001 From: kravchenkodhealth <106426895+kravchenkodhealth@users.noreply.github.com> Date: Tue, 10 Jan 2023 13:28:34 +0200 Subject: [PATCH] [@dhealthdapps/backend] fix(routes): add assets field to response in activities route --- runtime/backend/src/users/models/ActivityDTO.ts | 16 ++++++++++++++++ .../backend/src/users/models/ActivitySchema.ts | 11 +++++++++++ 2 files changed, 27 insertions(+) diff --git a/runtime/backend/src/users/models/ActivityDTO.ts b/runtime/backend/src/users/models/ActivityDTO.ts index fcba1790..fa8644e3 100644 --- a/runtime/backend/src/users/models/ActivityDTO.ts +++ b/runtime/backend/src/users/models/ActivityDTO.ts @@ -139,4 +139,20 @@ export class ActivityDTO extends BaseDTO { description: "Elevation gain received per activity", }) public elevationGain: number; + + /** + * This property represents an amount of received assets + *

+ * This field is **not required** and *not indexed*. + * + * @example `"swim"` + * @access public + * @var {string} + */ + @ApiProperty({ + type: "number", + example: "15", + description: "Amount of tokens received per activity", + }) + public assets: number | any; } diff --git a/runtime/backend/src/users/models/ActivitySchema.ts b/runtime/backend/src/users/models/ActivitySchema.ts index 2bf8d4c7..f3060b13 100644 --- a/runtime/backend/src/users/models/ActivitySchema.ts +++ b/runtime/backend/src/users/models/ActivitySchema.ts @@ -18,6 +18,9 @@ import { Documentable } from "../../common/concerns/Documentable"; import { Transferable } from "../../common/concerns/Transferable"; import { Queryable, QueryParameters } from "../../common/concerns/Queryable"; +// common/models +import { AssetsConfig } from "../../common/models/AssetsConfig"; + // users scope import { ActivityDTO } from "./ActivityDTO"; import { ActivityData, ActivityDataSchema } from "./ActivityDataSchema"; @@ -26,6 +29,11 @@ import { ProcessingState } from "./ProcessingStatusDTO"; // payout scope import { PayoutState } from "../../payout/models/PayoutStatusDTO"; +// config +import assetsConfigLoader from "../../../config/assets"; + +const assetsConfig: AssetsConfig = assetsConfigLoader(); + /** * @class Activity * @description This class defines the **exact** fields that are @@ -318,6 +326,9 @@ export class Activity extends Transferable { dto.address = doc.address; dto.slug = doc.slug; if (doc.activityData) { + dto.assets = doc.activityAssets.filter( + (a) => a.mosaicId === assetsConfig.assets.earn.mosaicId, + ); dto.distance = doc.activityData.distance; dto.sport = doc.activityData.sport; dto.elevationGain = doc.activityData.elevation;