Skip to content

Commit

Permalink
[@dhealthdapps/backend] fix(routes): add assets field to response in …
Browse files Browse the repository at this point in the history
…activities route
  • Loading branch information
kravchenkodhealth authored and evias committed Jan 11, 2023
1 parent 5290980 commit 471c3d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions runtime/backend/src/users/models/ActivityDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <br /><br />
* 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;
}
11 changes: 11 additions & 0 deletions runtime/backend/src/users/models/ActivitySchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand Down Expand Up @@ -318,6 +326,9 @@ export class Activity extends Transferable<ActivityDTO> {
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;
Expand Down

0 comments on commit 471c3d8

Please sign in to comment.