Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logo to project #29

Merged
merged 4 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions migration/1724231548035-ProjectIcon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class ProjectIcon1724231548035 implements MigrationInterface {
name = 'ProjectIcon1724231548035';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "project" ADD "icon" character varying`,
);
await queryRunner.query(
`ALTER TABLE "project_update" ADD "icon" character varying`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "project_update" DROP COLUMN "icon"`);
await queryRunner.query(`ALTER TABLE "project" DROP COLUMN "icon"`);
}
}
8 changes: 8 additions & 0 deletions src/entities/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ export class Project extends BaseEntity {
@Field(_type => [Campaign], { nullable: true })
campaigns: Campaign[];

@Field({ nullable: true })
@Column({ nullable: true })
icon?: string;

// only projects with status active can be listed automatically
static pendingReviewSince(maximumDaysForListing: number) {
const maxDaysForListing = moment()
Expand Down Expand Up @@ -675,6 +679,10 @@ export class ProjectUpdate extends BaseEntity {
@Column('text', { nullable: true })
managingFundDescription: string;

@Field({ nullable: true })
@Column({ nullable: true })
icon?: string;

@Field(_type => FeaturedUpdate, { nullable: true })
@OneToOne(
_type => FeaturedUpdate,
Expand Down
40 changes: 39 additions & 1 deletion src/resolvers/projectResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function createProjectTestCases() {
description: 'Test Project Description',
categories: [],
image: 'https://example.com/test-project.jpg',
teaser: 'https://example.com/test-project-teaser.jpg',
teaser: 'Test Project Text Teaser',
impactLocation: 'Test Impact Location',
isDraft: false,
teamMembers,
Expand Down Expand Up @@ -82,4 +82,42 @@ function createProjectTestCases() {
await getAbcLauncherAdapter().getProjectAbcLaunchData(projectAddress);
expect(project.abc).to.deep.equal(expectedAbc);
});

it('should create project with icon successfully', async () => {
assert.isOk(user);
assert.isOk(accessToken);

const projectAddress = generateRandomEtheriumAddress();
const createProjectInput: CreateProjectInput = {
title: 'Test Project with Icon',
adminUserId: user.id,
description: 'A project to test icon field',
categories: [],
image: 'https://example.com/test-project.jpg',
teaser: 'Test Project Teaser',
impactLocation: 'Test Location',
isDraft: false,
address: projectAddress,
icon: 'https://example.com/test-icon.jpg',
};

const result = await axios.post(
graphqlUrl,
{
query: createProjectQuery,
variables: {
project: createProjectInput,
},
},
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
},
);

const project = result.data.data.createProject;
assert.isOk(project);
expect(project.icon).to.equal(createProjectInput.icon);
});
}
76 changes: 40 additions & 36 deletions src/resolvers/projectResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,10 @@ export class ProjectResolver {
// project.listed = null;
// project.reviewStatus = ReviewStatus.NotReviewed;

// if (newProjectData.icon !== undefined) {
// project.icon = newProjectData.icon;
// }

// await project.save();
// await project.reload();

Expand Down Expand Up @@ -1299,44 +1303,44 @@ export class ProjectResolver {

const qualityScore = getQualityScore(description, Boolean(image), 0);

if (!projectInput.categories) {
throw new Error(
i18n.__(
translationErrorMessagesKeys.CATEGORIES_MUST_BE_FROM_THE_FRONTEND_SUBSELECTION,
),
);
}
// if (!projectInput.categories) {
// throw new Error(
// i18n.__(
// translationErrorMessagesKeys.CATEGORIES_MUST_BE_FROM_THE_FRONTEND_SUBSELECTION,
// ),
// );
// }

// We do not create categories only use existing ones
const categories = await Promise.all(
projectInput.categories
? projectInput.categories.map(async category => {
const [c] = await this.categoryRepository.find({
where: {
name: category,
isActive: true,
canUseOnFrontend: true,
},
});
if (!c) {
throw new Error(
i18n.__(
translationErrorMessagesKeys.CATEGORIES_MUST_BE_FROM_THE_FRONTEND_SUBSELECTION,
),
);
}
return c;
})
: [],
);
// const categories = await Promise.all(
// projectInput.categories
// ? projectInput.categories.map(async category => {
// const [c] = await this.categoryRepository.find({
// where: {
// name: category,
// isActive: true,
// canUseOnFrontend: true,
// },
// });
// if (!c) {
// throw new Error(
// i18n.__(
// translationErrorMessagesKeys.CATEGORIES_MUST_BE_FROM_THE_FRONTEND_SUBSELECTION,
// ),
// );
// }
// return c;
// })
// : [],
// );

if (categories.length > 5) {
throw new Error(
i18n.__(
translationErrorMessagesKeys.CATEGORIES_LENGTH_SHOULD_NOT_BE_MORE_THAN_FIVE,
),
);
}
// if (categories.length > 5) {
// throw new Error(
// i18n.__(
// translationErrorMessagesKeys.CATEGORIES_LENGTH_SHOULD_NOT_BE_MORE_THAN_FIVE,
// ),
// );
// }

const abcLauncherAdapter = getAbcLauncherAdapter();
const abc = await abcLauncherAdapter.getProjectAbcLaunchData(
Expand Down Expand Up @@ -1391,7 +1395,7 @@ export class ProjectResolver {
const project = Project.create({
...projectInput,
abc,
categories: categories as Category[],
categories: [],
organization: organization as Organization,
image,
creationDate: now,
Expand Down
4 changes: 4 additions & 0 deletions src/resolvers/types/project-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export class ProjectInput {

@Field(() => [ProjectTeamMemberInput], { nullable: true })
teamMembers?: ProjectTeamMemberInput[];

@Field({ nullable: true })
@MaxLength(IMAGE_LINK_MAX_SIZE)
icon?: string;
}

@InputType()
Expand Down
1 change: 1 addition & 0 deletions test/graphqlQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const createProjectQuery = `
listed
reviewStatus
verified
icon
organization {
id
name
Expand Down
Loading