Skip to content

Commit

Permalink
refactor(projects): expose isVisible flag in project queries
Browse files Browse the repository at this point in the history
Implements: #38
  • Loading branch information
jtourkos committed Nov 6, 2024
1 parent 6ecfae0 commit 47cd433
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/dataLoaders/sqlQueries/projectsQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function getProjectByUrl(
url: string,
): Promise<ProjectDataValues[]> {
const baseSQL = (schema: DbSchema) => `
SELECT "id", "isValid", "name", "verificationStatus"::TEXT, "claimedAt", "forge"::TEXT, "ownerAddress", "ownerAccountId", "url", "emoji", "avatarCid", "color", "description", "createdAt", "updatedAt", '${schema}' AS chain
SELECT "id", "isValid", "isVisible", "name", "verificationStatus"::TEXT, "claimedAt", "forge"::TEXT, "ownerAddress", "ownerAccountId", "url", "emoji", "avatarCid", "color", "description", "createdAt", "updatedAt", '${schema}' AS chain
FROM "${schema}"."GitProjects"
`;

Expand Down Expand Up @@ -43,7 +43,7 @@ async function getProjectsByFilter(
): Promise<ProjectDataValues[]> {
const baseSQL = (schema: DbSchema) =>
`SELECT
"id", "isValid", "name", "verificationStatus"::TEXT, "claimedAt", "forge"::TEXT, "ownerAddress", "ownerAccountId", "url", "emoji", "avatarCid", "color", "description", "createdAt", "updatedAt", '${schema}' AS chain
"id", "isValid", "isVisible", "name", "verificationStatus"::TEXT, "claimedAt", "forge"::TEXT, "ownerAddress", "ownerAccountId", "url", "emoji", "avatarCid", "color", "description", "createdAt", "updatedAt", '${schema}' AS chain
FROM "${schema}"."GitProjects" `;

const conditions: string[] = ['"isValid" = true'];
Expand Down Expand Up @@ -91,7 +91,7 @@ async function getProjectsByIds(
projectIds: ProjectId[],
): Promise<ProjectDataValues[]> {
const baseSQL = (schema: DbSchema) => `
SELECT "id", "isValid", "name", "verificationStatus"::TEXT, "claimedAt", "forge"::TEXT, "ownerAddress", "ownerAccountId", "url", "emoji", "avatarCid", "color", "description", "createdAt", "updatedAt", '${schema}' AS chain
SELECT "id", "isValid", "isVisible", "name", "verificationStatus"::TEXT, "claimedAt", "forge"::TEXT, "ownerAddress", "ownerAccountId", "url", "emoji", "avatarCid", "color", "description", "createdAt", "updatedAt", '${schema}' AS chain
FROM "${schema}"."GitProjects"
`;

Expand Down
5 changes: 5 additions & 0 deletions src/project/ProjectModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default class ProjectModel extends Model<
public declare color: string | null;
public declare description: string | null;
public declare verificationStatus: ProjectVerificationStatus;
public declare isVisible: boolean;

public declare claimedAt: Date | null;

Expand Down Expand Up @@ -99,6 +100,10 @@ export default class ProjectModel extends Model<
type: DataTypes.TEXT,
allowNull: true,
},
isVisible: {
type: DataTypes.BOOLEAN,
allowNull: false,
},
},
{
sequelize,
Expand Down
1 change: 1 addition & 0 deletions src/project/projectResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const projectResolvers = {
source: (project: ResolverProject): Source => project.source,
account: (project: ResolverProject): RepoDriverAccount => project.account,
chainData: (project: ResolverProject): ProjectData[] => project.chainData,
isVisible: (project: ResolverProject): boolean => project.isVisible,
},
ProjectData: {
__resolveType(parent: ProjectData) {
Expand Down
1 change: 1 addition & 0 deletions src/project/projectTypeDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const projectTypeDef = gql`
source: Source!
account: RepoDriverAccount!
chainData: [ProjectData!]!
isVisible: Boolean!
}
union ProjectData = ClaimedProjectData | UnClaimedProjectData
Expand Down
9 changes: 5 additions & 4 deletions src/project/projectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { ProjectVerificationStatus } from './ProjectModel';
import assert from '../utils/assert';
import appSettings from '../common/appSettings';
import { getCrossChainRepoDriverAccountIdByAddress } from '../common/dripsContracts';
import { Driver } from '../generated/graphql';
import type { Forge as GraphQlForge, Splits } from '../generated/graphql';
import { Driver } from '../generated/graphql';
import { singleOrDefault } from '../utils/linq';
import { dbSchemaToChain } from '../utils/chainSchemaMappings';

Expand Down Expand Up @@ -97,6 +97,7 @@ export async function toProjectRepresentationFromUrl(
url,
verificationStatus: ProjectVerificationStatus.Unclaimed,
isValid: true,
isVisible: true,
} as ProjectDataValues;
}

Expand Down Expand Up @@ -253,6 +254,7 @@ export async function toResolverProjects(
.ownerName,
forge: (project.forge as GraphQlForge) || shouldNeverHappen(),
},
isVisible: project.isVisible,
chainData,
} as ResolverProject;
}),
Expand Down Expand Up @@ -304,7 +306,7 @@ export async function mergeProjects(
}),
);

const mergedProject = {
return {
account: {
accountId: projectBase.id,
driver: Driver.REPO,
Expand All @@ -317,8 +319,7 @@ export async function mergeProjects(
.ownerName,
forge: (projectBase.forge as GraphQlForge) || shouldNeverHappen(),
},
isVisible: projectBase.isVisible,
chainData,
} as ResolverProject;

return mergedProject;
}

0 comments on commit 47cd433

Please sign in to comment.