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

Fix: adding projectIds textArea to QF Round edit page #1505

Merged
merged 5 commits into from
May 14, 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
12 changes: 2 additions & 10 deletions migration-old-backup/1714018700116-add_archived_QFRound_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,15 @@ export class AddArchivedQFRoundFields1714018700116
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE "qf_round"
ADD COLUMN IF NOT EXISTS "bannerBgImage" character varying
`);

await queryRunner.query(`
ALTER TABLE "qf_round"
ADD COLUMN IF NOT EXISTS "bannerBgImage" character varying,
ADD COLUMN IF NOT EXISTS "sponsorsImgs" character varying[] DEFAULT '{}' NOT NULL
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE "qf_round"
DROP COLUMN IF EXISTS "bannerBgImage"
`);

await queryRunner.query(`
ALTER TABLE "qf_round"
DROP COLUMN IF EXISTS "bannerBgImage",
DROP COLUMN IF EXISTS "sponsorsImgs"
`);
}
Expand Down
26 changes: 14 additions & 12 deletions migration/1712853017092-UserNewRoleQfManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ export class UserNewRoleQfManager1712853017092 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
// add enum qfManager to user table column role
await queryRunner.query(
`
ALTER TYPE user_role_enum ADD VALUE 'qfManager';
ALTER TABLE "user" ALTER COLUMN "role" TYPE user_role_enum USING "role"::text::user_role_enum;
ALTER TABLE "user" ALTER COLUMN "role" SET DEFAULT 'restricted';
`DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_enum
WHERE pg_enum.enumtypid = 'user_role_enum'::regtype
AND pg_enum.enumlabel = 'qfManager'
) THEN
BEGIN
EXECUTE 'ALTER TYPE user_role_enum ADD VALUE ''qfManager''';
END;
END IF;
END $$;
`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
// remove enum qfManager from user table column role
await queryRunner.query(
`
ALTER TYPE user_role_enum DROP VALUE 'qfManager';
ALTER TABLE "user" ALTER COLUMN "role" TYPE user_role_enum USING "role"::text::user_role_enum;
ALTER TABLE "user" ALTER COLUMN "role" SET DEFAULT 'restricted';
`,
);
await queryRunner.query(''); // no need to remove enum value
}
}
2 changes: 1 addition & 1 deletion src/repositories/qfRoundRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export const deactivateExpiredQfRounds = async (): Promise<void> => {

export const getRelatedProjectsOfQfRound = async (
qfRoundId: number,
): Promise<{ slug: string; name: string }[]> => {
): Promise<{ slug: string; name: string; id: number }[]> => {
const query = `
SELECT "p"."slug", "p"."title" , p.id
FROM "project" "p"
Expand Down
2 changes: 1 addition & 1 deletion src/server/adminJs/tabs/components/ProjectsInQfRound.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React from 'react';
import { withTheme } from 'styled-components';
import { Section, Label, Link } from '@adminjs/design-system';

Expand Down
16 changes: 13 additions & 3 deletions src/server/adminJs/tabs/qfRoundTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,19 @@ import { pinFile } from '../../../middleware/pinataUtils';
export const refreshMaterializedViews = async (
response,
): Promise<After<ActionResponse>> => {
const projectIds = await getRelatedProjectsOfQfRound(
response.record.params.id,
);
await refreshProjectEstimatedMatchingView();
await refreshProjectDonationSummaryView();
await refreshProjectActualMatchingView();
response.record = {
...response.record,
params: {
...response.record.params,
projectIdsList: projectIds.map(project => project.id).join(','),
},
};
return response;
};

Expand Down Expand Up @@ -119,7 +129,7 @@ export const qfRoundTab = {
resource: QfRound,
options: {
properties: {
addProjectIdsList: {
projectIdsList: {
type: 'textarea',
// projectIds separated By comma
isVisible: {
Expand Down Expand Up @@ -308,10 +318,10 @@ export const qfRoundTab = {
request.payload.isActive = qfRound.isActive;
} else if (
qfRound.isActive &&
request?.payload?.addProjectIdsList?.split(',')?.length > 0
request?.payload?.projectIdsList?.split(',')?.length > 0
) {
await relateManyProjectsToQfRound({
projectIds: request.payload.addProjectIdsList.split(','),
projectIds: request.payload.projectIdsList.split(','),
qfRound,
add: true,
});
Expand Down
Loading