Skip to content

Commit

Permalink
Merge pull request #410 from TogetherCrew/404-add-reputation-score-ap…
Browse files Browse the repository at this point in the history
…i-endpoint

404 add reputation score api endpoint
  • Loading branch information
Behzad-rabiei authored Nov 18, 2024
2 parents c9f2451 + 494c732 commit 2ef8651
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/services/community.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HydratedDocument, Types } from 'mongoose';
import { HydratedDocument, Types, FilterQuery } from 'mongoose';
import httpStatus from 'http-status';
import {
Community,
Expand Down Expand Up @@ -39,7 +39,7 @@ const queryCommunities = async (filter: object, options: object) => {
* @param {Object} filter - Mongo filter
* @returns {Promise<HydratedDocument<ICommunity> | null>}
*/
const getCommunityByFilter = async (filter: object): Promise<HydratedDocument<ICommunity> | null> => {
const getCommunityByFilter = async (filter: FilterQuery<ICommunity>): Promise<HydratedDocument<ICommunity> | null> => {
return Community.findOne(filter);
};

Expand Down
16 changes: 13 additions & 3 deletions src/services/nft.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HydratedDocument, Types } from 'mongoose';
import httpStatus from 'http-status';
import { IPlatform, IModule, PlatformNames } from '@togethercrew.dev/db';
import { IPlatform, IModule, PlatformNames, ICommunity } from '@togethercrew.dev/db';
import ApiError from '../utils/ApiError';
import * as Neo4j from '../neo4j';
import { NEO4J_PLATFORM_INFO } from '../constants/neo4j.constant';
Expand All @@ -9,6 +9,7 @@ import parentLogger from '../config/logger';
import moduleService from './module.service';
import platformService from './platform.service';
import ociService from './oci.service';
import communityService from './community.service';

const logger = parentLogger.child({ module: 'NftService' });

Expand All @@ -24,6 +25,10 @@ const getReputationScore = async (tokenId: string, address: string) => {
logger.debug(dynamicNftModule);
throwErrorIfDynamicNftModuleDoesNotExist(dynamicNftModule);

const community = await communityService.getCommunityByFilter({ _id: dynamicNftModule?.community });
logger.debug(community);
throwErrorIfCommunityDoesNotExist(community);

const profiles: Array<any> = await getProfiles(address);
logger.debug(profiles);
throwErrorIfUserHasNoOnChainProfiles(profiles);
Expand All @@ -42,8 +47,8 @@ const getReputationScore = async (tokenId: string, address: string) => {
}
}
return {
reputationScore,
communintyId: dynamicNftModule?.id,
reputationScore: reputationScore * 100,
communityName: community?.name,
};
};

Expand Down Expand Up @@ -107,6 +112,11 @@ function throwErrorIfDynamicNftModuleDoesNotExist(dynamicNftModule: HydratedDocu
}
}

function throwErrorIfCommunityDoesNotExist(community: HydratedDocument<ICommunity> | null) {
if (!community) {
throw new ApiError(400, 'There is no associated community for the dynamic NFT module.');
}
}
export default {
getReputationScore,
};

0 comments on commit 2ef8651

Please sign in to comment.