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

improve projectBySlug query #1570

Merged
merged 12 commits into from
May 19, 2024
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"form-data": "^3.0.1",
"google-spreadsheet": "^3.2.0",
"graphql": "16.8.1",
"graphql-fields": "^2.0.3",
"graphql-tag": "^2.12.6",
"graphql-upload": "15.0.2",
"handlebars": "4.7.7",
Expand Down Expand Up @@ -85,13 +86,13 @@
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.21",
"@types/graphql-upload": "15.0.2",
"@types/html-to-text": "^9.0.0",
"@types/jsonwebtoken": "^8.5.0",
"@types/lodash": "^4.14.197",
"@types/marked": "^4.0.8",
"@types/mocha": "^8.2.1",
"@types/node": "^14.14.31",
"@types/node-cron": "^3.0.0",
"@types/html-to-text": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"chai": "^4.3.0",
Expand Down Expand Up @@ -202,6 +203,7 @@
"test:bootstrap": "NODE_ENV=test mocha ./test/pre-test-scripts.ts ./src/server/bootstrap.test.ts",
"test:utils": "NODE_ENV=test mocha ./src/utils/utils.test.ts",
"start": "NODE_ENV=development ts-node-dev --project ./tsconfig.json --respawn ./src/index.ts",
"start:test": "NODE_ENV=development ts-node-dev --project ./tsconfig.json --respawn ./test.ts",
"serve": "pm2 startOrRestart ecosystem.config.js --node-args='--max-old-space-size=8192'",
"db:migrate:run:test": "NODE_ENV=test npx typeorm-ts-node-commonjs migration:run -d ./src/ormconfig.ts",
"db:migrate:revert:test": "NODE_ENV=test npx typeorm-ts-node-commonjs migration:revert -d ./src/ormconfig.ts",
Expand Down
10 changes: 10 additions & 0 deletions src/repositories/projectRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,16 @@ export const findProjectBySlug = (slug: string): Promise<Project | null> => {
);
};

export const findProjectIdBySlug = (slug: string): Promise<Project | null> => {
// check current slug and previous slugs
return Project.createQueryBuilder('project')
.select('project.id')
.where(`:slug = ANY(project."slugHistory") or project.slug = :slug`, {
slug,
})
.getOne();
};

export const findProjectBySlugWithoutAnyJoin = (
slug: string,
): Promise<Project | null> => {
Expand Down
11 changes: 11 additions & 0 deletions src/repositories/projectVerificationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,17 @@ export const updateManagingFundsOfProjectVerification = async (params: {
return projectVerificationForm?.save();
};

export const getVerificationFormStatusByProjectId = async (
projectId: number,
): Promise<ProjectVerificationForm | null> => {
return ProjectVerificationForm.createQueryBuilder('project_verification_form')
.select(['project_verification_form.status'])
.where(`project_verification_form.projectId=:projectId`, {
projectId,
})
.getOne();
};

export const getVerificationFormByProjectId = async (
projectId: number,
): Promise<ProjectVerificationForm | null> => {
Expand Down
79 changes: 32 additions & 47 deletions src/resolvers/projectResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4287,7 +4287,7 @@ function getProjectUpdatesTestCases() {
}

function projectBySlugTestCases() {
it('should return projects with indicated slug and verification form if owner', async () => {
it('should return projects with indicated slug and verification form status if owner', async () => {
const project1 = await saveProjectDirectlyToDb({
...createProjectData(),
title: String(new Date().getTime()),
Expand Down Expand Up @@ -4326,68 +4326,53 @@ function projectBySlugTestCases() {

const project = result.data.data.projectBySlug;
assert.equal(Number(project.id), project1.id);
assert.isOk(project.projectVerificationForm);
assert.equal(project.projectVerificationForm.id, verificationForm.id);
assert.isOk(project.verificationFormStatus);
assert.equal(project.verificationFormStatus, verificationForm.status);
assert.isOk(project.adminUser.walletAddress);
assert.isOk(project.adminUser.firstName);
assert.isNotOk(project.adminUser.email);
assert.isOk(project.categories[0].mainCategory.title);
});
it('should return verificationFormStatus if its not owner', async () => {
const project1 = await saveProjectDirectlyToDb({
...createProjectData(),
title: String(new Date().getTime()),
slug: String(new Date().getTime()),
});

const user =
(await User.findOne({
where: {
id: project1.adminUserId,
},
})) || undefined;

const verificationForm = await ProjectVerificationForm.create({
project: project1,
user,
status: PROJECT_VERIFICATION_STATUSES.DRAFT,
}).save();

const result = await axios.post(graphqlUrl, {
query: fetchProjectBySlugQuery,
variables: {
slug: project1.slug,
connectedWalletUserId: user!.id,
},
});

const project = result.data.data.projectBySlug;
assert.equal(Number(project.id), project1.id);
assert.isNotOk(project.projectVerificationForm);
assert.equal(project.verificationFormStatus, verificationForm.status);
});

it('should return projects with indicated slug', async () => {
const walletAddress = generateRandomEtheriumAddress();
const project1 = await saveProjectDirectlyToDb({
...createProjectData(),
title: String(new Date().getTime()),
slug: String(new Date().getTime()),
walletAddress,
});

const accessToken = await generateTestAccessToken(SEED_DATA.FIRST_USER.id);
const sampleProject1 = {
title: walletAddress,
adminUserId: SEED_DATA.FIRST_USER.id,
addresses: [
{
address: walletAddress,
networkId: NETWORK_IDS.XDAI,
chainType: ChainType.EVM,
},
],
};
const res1 = await axios.post(
graphqlUrl,
{
query: createProjectQuery,
variables: {
project: sampleProject1,
},
},
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
},
);
const _project = res1.data.data.createProject;
const result = await axios.post(graphqlUrl, {
query: fetchProjectBySlugQuery,
variables: {
slug: project1.slug,
slug: _project.slug,
},
});

const project = result.data.data.projectBySlug;
assert.equal(Number(project.id), project1.id);
assert.equal(Number(project.id), Number(_project.id));
assert.isOk(project.adminUser.walletAddress);
assert.isOk(project.givbackFactor);
assert.isNull(project.projectVerificationForm);
assert.isOk(project.adminUser.firstName);
assert.isNotOk(project.adminUser.email);
assert.isNotEmpty(project.addresses);
Expand Down
Loading
Loading