Skip to content

Commit

Permalink
Include unlisted Params and Fix Base network stream (#1891)
Browse files Browse the repository at this point in the history
* add includeUnlisted to FilterProjectQueryInputParams

* return proper projects

* add recipient address to streams when nonexistent (#1890)

---------

Co-authored-by: Cherik <[email protected]>
  • Loading branch information
CarlosQ96 and MohammadPCh authored Dec 10, 2024
1 parent 14bc5ac commit 9ac7a62
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/repositories/projectRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export type FilterProjectQueryInputParams = {
qfRoundId?: number;
activeQfRoundId?: number;
qfRoundSlug?: string;
includeUnlisted?: boolean;
};
export const filterProjectsQuery = (params: FilterProjectQueryInputParams) => {
const {
Expand All @@ -97,6 +98,7 @@ export const filterProjectsQuery = (params: FilterProjectQueryInputParams) => {
qfRoundId,
qfRoundSlug,
activeQfRoundId,
includeUnlisted,
} = params;

let query = Project.createQueryBuilder('project')
Expand All @@ -122,11 +124,16 @@ export const filterProjectsQuery = (params: FilterProjectQueryInputParams) => {
'projectPower.totalPower',
'projectPower.powerRank',
'projectPower.round',
])
.where(
]);

if (includeUnlisted) {
query = query.where(`project.statusId = ${ProjStatus.active}`);
} else {
query = query.where(
`project.statusId = ${ProjStatus.active} AND project.reviewStatus = :reviewStatus`,
{ reviewStatus: ReviewStatus.Listed },
);
}

const isFilterByQF =
!!filters?.find(f => f === FilterField.ActiveQfRound) && activeQfRoundId;
Expand Down Expand Up @@ -255,7 +262,6 @@ export const filterProjectsQuery = (params: FilterProjectQueryInputParams) => {
break;
case SortingField.BestMatch:
break;

default:
query
.addOrderBy('projectInstantPower.totalPower', OrderDirection.DESC)
Expand Down
32 changes: 27 additions & 5 deletions src/resolvers/anchorContractAddressResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { ApolloContext } from '../types/ApolloContext';
import { findUserById } from '../repositories/userRepository';
import { getProvider } from '../provider';
import { logger } from '../utils/logger';
import { ChainType } from '../types/network';
import { addBulkNewProjectAddress } from '../repositories/projectAddressRepository';
import { validateProjectRelatedAddresses } from '../utils/validators/projectValidator';

@Resolver(_of => AnchorContractAddress)
export class AnchorContractAddressResolver {
Expand All @@ -24,6 +27,7 @@ export class AnchorContractAddressResolver {
@Arg('networkId', () => Int) networkId: number,
@Arg('address', () => String) address: string,
@Arg('txHash', () => String) txHash: string,
@Arg('recipientAddress', { nullable: true }) recipientAddress?: string,
): Promise<AnchorContractAddress> {
const userId = ctx?.req?.user?.userId;
const creatorUser = await findUserById(userId);
Expand Down Expand Up @@ -53,11 +57,29 @@ export class AnchorContractAddressResolver {
projectAddress.isRecipient === true,
)
) {
throw new Error(
i18n.__(
translationErrorMessagesKeys.PROJECT_DOESNT_HAVE_RECIPIENT_ADDRESS_ON_THIS_NETWORK,
),
);
if (recipientAddress) {
const recipientAddressInput = {
project,
user: creatorUser,
address: recipientAddress!,
chainType: ChainType.EVM,
networkId: networkId,
isRecipient: true,
};

await validateProjectRelatedAddresses(
[recipientAddressInput],
projectId,
);

await addBulkNewProjectAddress([recipientAddressInput]);
} else {
throw new Error(
i18n.__(
translationErrorMessagesKeys.PROJECT_DOESNT_HAVE_RECIPIENT_ADDRESS_ON_THIS_NETWORK,
),
);
}
}

const web3Provider = getProvider(networkId);
Expand Down
5 changes: 5 additions & 0 deletions src/resolvers/projectResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ class GetProjectsArgs {

@Field(_type => String, { nullable: true })
qfRoundSlug?: string;

@Field({ nullable: true })
includeUnlisted?: boolean;
}

@ObjectType()
Expand Down Expand Up @@ -740,6 +743,7 @@ export class ProjectResolver {
campaignSlug,
qfRoundId,
qfRoundSlug,
includeUnlisted,
}: GetProjectsArgs,
@Ctx() { req: { user }, projectsFiltersThreadPool }: ApolloContext,
): Promise<AllProjects> {
Expand All @@ -766,6 +770,7 @@ export class ProjectResolver {
qfRoundId,
qfRoundSlug,
activeQfRoundId,
includeUnlisted,
};
let campaign;
if (campaignSlug) {
Expand Down

0 comments on commit 9ac7a62

Please sign in to comment.