Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
73 changes: 73 additions & 0 deletions apps/backend/db_patches/0200_ChangeFapGradeToString.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
DO
$$
BEGIN
IF register_patch('ChangeFapGradeToString.sql', 'TCMeldrum', 'Make grade a string for FAPs', '2025-09-04') THEN
BEGIN

DROP VIEW review_data;

ALTER TABLE fap_reviews
ALTER COLUMN grade type varchar(30);

CREATE OR REPLACE VIEW public.review_data
AS SELECT proposal.proposal_pk,
proposal.proposal_id,
proposal.title,
proposal.instrument_name,
proposal.availability_time,
proposal.time_allocation,
proposal.fap_id,
proposal.rank_order,
proposal.call_id,
proposal.proposer_id,
proposal.instrument_id,
proposal.fap_time_allocation,
proposal.questionary_id,
grade.avg AS average_grade,
proposal.public_comment AS comment
FROM ( SELECT fp.proposal_pk,
p.proposal_id,
p.title,
i.name AS instrument_name,
chi.availability_time,
tr.time_allocation,
f.fap_id,
fmd.rank_order,
c.call_id,
p.proposer_id,
i.instrument_id,
fp.fap_time_allocation,
p.questionary_id,
tr.public_comment
FROM fap_proposals fp
JOIN faps f ON f.fap_id = fp.fap_id
JOIN call c ON c.call_id = fp.call_id
JOIN proposals p ON p.proposal_pk = fp.proposal_pk
JOIN technical_review tr ON tr.proposal_pk = p.proposal_pk AND tr.instrument_id = fp.instrument_id
LEFT JOIN fap_meeting_decisions fmd ON fmd.proposal_pk = p.proposal_pk
JOIN call_has_instruments chi ON chi.instrument_id = fp.instrument_id AND chi.call_id = c.call_id
JOIN instruments i ON i.instrument_id = chi.instrument_id
WHERE p.status_id <> 9 AND p.status_id <> 1) proposal
LEFT JOIN ( SELECT fr.proposal_pk,
avg(CASE
WHEN fr.grade ~ '^\d+(\.\d+)\?$' THEN fr.grade::double precision
ELSE NULL
END) AS avg
FROM fap_proposals fp
JOIN fap_reviews fr ON fr.proposal_pk = fp.proposal_pk
GROUP BY fr.proposal_pk) grade ON grade.proposal_pk = proposal.proposal_pk;


UPDATE questions SET default_config = jsonb_set(default_config, '{maxGrade}', '10', true) WHERE question_id = 'fap_review_basis';
UPDATE questions SET default_config = jsonb_set(default_config, '{minGrade}', '1', true) WHERE question_id = 'fap_review_basis';
UPDATE questions SET default_config = jsonb_set(default_config, '{decimalPoints}', '0', true) WHERE question_id = 'fap_review_basis';
UPDATE templates_has_questions SET config = jsonb_set(config, '{maxGrade}', '10', true) WHERE question_id = 'fap_review_basis';
UPDATE templates_has_questions SET config = jsonb_set(config, '{minGrade}', '1', true) WHERE question_id = 'fap_review_basis';
UPDATE templates_has_questions SET config = jsonb_set(config, '{decimalPoints}', '0', true) WHERE question_id = 'fap_review_basis';

DELETE FROM settings WHERE settings_id = 'GRADE_PRECISION';
END;
END IF;
END;
$$
LANGUAGE plpgsql;
6 changes: 3 additions & 3 deletions apps/backend/db_patches/db_seeds/0005_ProposalQuestions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ INSERT INTO templates_has_questions(
VALUES
(
'dynamic_multiple_choice_question',
proposal_template_id_var, proposal_topic_id_var, 6, '{"variant":"dropdown", "url":"", "jsonPath":"","isMultipleSelect":true, "apiCallRequestHeaders":[],"readPermissions":[]}'
proposal_template_id_var, proposal_topic_id_var, 10, '{"variant":"dropdown", "url":"", "jsonPath":"","isMultipleSelect":true, "apiCallRequestHeaders":[],"readPermissions":[]}'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were 4 questions with sortOrder 6 meaning the templete export tests was failing as these 6 questiond could appear in the topic array in any order. IDK what about this PR made this unstable but hopefully this should make it more stable going forward

);
INSERT INTO answers(
questionary_id, question_id, answer
Expand Down Expand Up @@ -456,7 +456,7 @@ INSERT INTO templates_has_questions(
VALUES
(
'instrument_picker_question',
proposal_template_id_var, proposal_topic_id_var, 6, '{"variant":"dropdown","options":[1, 2], "readPermissions":[]}'
proposal_template_id_var, proposal_topic_id_var, 11, '{"variant":"dropdown","options":[1, 2], "readPermissions":[]}'
);
INSERT INTO answers(
questionary_id, question_id, answer
Expand Down Expand Up @@ -491,7 +491,7 @@ INSERT INTO templates_has_questions(
VALUES
(
'technique_picker_question',
proposal_template_id_var, proposal_topic_id_var, 6, '{"variant":"dropdown","options":[1, 2], "readPermissions":[]}'
proposal_template_id_var, proposal_topic_id_var, 12, '{"variant":"dropdown","options":[1, 2], "readPermissions":[]}'
);
INSERT INTO answers(
questionary_id, question_id, answer
Expand Down
8 changes: 4 additions & 4 deletions apps/backend/package-lock.json

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

4 changes: 2 additions & 2 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@user-office-software/duo-localisation": "^1.2.0",
"@user-office-software/duo-logger": "^2.3.2",
"@user-office-software/duo-message-broker": "^1.6.0",
"@user-office-software/duo-validation": "^5.1.19",
"@user-office-software/duo-validation": "^5.1.20",
"@user-office-software/openid": "^1.4.0",
"await-to-js": "^2.1.1",
"bcryptjs": "^2.4.3",
Expand Down Expand Up @@ -129,4 +129,4 @@
"npm": ">=10.9.2",
"node": ">=22.0.0"
}
}
}
4 changes: 0 additions & 4 deletions apps/backend/src/config/eli/configureELIEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ async function enableDefaultELIFeatures() {
settingsId: SettingsId.DEFAULT_INST_SCI_STATUS_FILTER,
settingsValue: 'FEASIBILITY_REVIEW',
});
await db.updateSettings({
settingsId: SettingsId.GRADE_PRECISION,
settingsValue: '1',
});
}

async function setELIRoleNames() {
Expand Down
4 changes: 0 additions & 4 deletions apps/backend/src/config/ess/configureESSEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ async function enableDefaultEssFeatures() {
settingsId: SettingsId.DEFAULT_INST_SCI_STATUS_FILTER,
settingsValue: 'FEASIBILITY_REVIEW',
});
await db.updateSettings({
settingsId: SettingsId.GRADE_PRECISION,
settingsValue: '1',
});
await db.updateSettings({
settingsId: SettingsId.DISPLAY_FAQ_LINK,
settingsValue: 'true',
Expand Down
4 changes: 0 additions & 4 deletions apps/backend/src/config/stfc/configureSTFCEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ async function enableDefaultStfcFeatures() {
settingsId: SettingsId.IDLE_TIMEOUT,
settingsValue: '1200000',
});
await db.updateSettings({
settingsId: SettingsId.GRADE_PRECISION,
settingsValue: '0.01',
});
await db.updateSettings({
settingsId: SettingsId.TECH_REVIEW_OPTIONAL_WORKFLOW_STATUS,
settingsValue: 'FEASIBILITY',
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/datasources/mockups/FapDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const dummyFapReview = new Review(
1,
1,
'Dummy Fap review',
7,
'7',
0,
1,
1,
Expand Down
10 changes: 5 additions & 5 deletions apps/backend/src/datasources/mockups/ReviewDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const dummyReview = new Review(
1,
1,
'Good proposal',
9,
'9',
0,
1,
1,
Expand All @@ -31,7 +31,7 @@ export const dummySubmittedReview = new Review(
1,
1,
'Good proposal',
9,
'9',
1,
1,
1,
Expand Down Expand Up @@ -62,7 +62,7 @@ export const dummyReviewBad = new Review(
1,
1,
'bad proposal',
1,
'1',
0,
1,
1,
Expand Down Expand Up @@ -116,7 +116,7 @@ export class ReviewDataSourceMock implements ReviewDataSource {
proposalPk,
userID,
' ',
1,
'1',
1,
1,
1,
Expand All @@ -133,7 +133,7 @@ export class ReviewDataSourceMock implements ReviewDataSource {
1,
1,
' ',
1,
'1',
1,
1,
1,
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/datasources/postgres/records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export interface ReviewRecord {
readonly user_id: number;
readonly proposal_pk: number;
readonly comment: string;
readonly grade: number;
readonly grade: string;
readonly status: number;
readonly fap_id: number;
readonly questionary_id: number;
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/models/Review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export class Review {
public proposalPk: number,
public userID: number,
public comment: string,
public grade: number,
public grade: string,
public status: number,
public fapID: number,
public questionaryID: number,
Expand Down
1 change: 0 additions & 1 deletion apps/backend/src/models/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export enum SettingsId {
DEFAULT_INST_SCI_STATUS_FILTER = 'DEFAULT_INST_SCI_STATUS_FILTER',
DEFAULT_INST_SCI_REVIEWER_FILTER = 'DEFAULT_INST_SCI_REVIEWER_FILTER',
IDLE_TIMEOUT = 'IDLE_TIMEOUT',
GRADE_PRECISION = 'GRADE_PRECISION',
USER_OFFICE_EMAIL = 'USER_OFFICE_EMAIL',
SMTP_BCC_EMAIL = 'SMTP_BCC_EMAIL',
TECH_REVIEW_OPTIONAL_WORKFLOW_STATUS = 'TECH_REVIEW_OPTIONAL_WORKFLOW_STATUS',
Expand Down
8 changes: 7 additions & 1 deletion apps/backend/src/models/questionTypes/FapReviewBasis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { Question } from './QuestionRegistry';
export const fapReviewBasisDefinition: Question<DataType.FAP_REVIEW_BASIS> = {
dataType: DataType.FAP_REVIEW_BASIS,
createBlankConfig: (): FapReviewBasisConfig => {
return new FapReviewBasisConfig();
const config = new FapReviewBasisConfig();
config.minGrade = 1;
config.maxGrade = 10;
config.decimalPoints = 0;
config.nonNumericOptions = [];

return config;
},
getDefaultAnswer: () => null,
};
8 changes: 4 additions & 4 deletions apps/backend/src/mutations/ReviewMutations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test('A reviewer can submit a review on a proposal he is on', () => {
reviewMutations.updateReview(dummyUserWithRole, {
reviewID: 10,
comment: 'Good proposal',
grade: 9,
grade: '9',
status: ReviewStatus.DRAFT,
fapID: 1,
questionaryID: 1,
Expand All @@ -34,7 +34,7 @@ test('A user can not submit a review on a proposal', () => {
reviewMutations.updateReview(dummyUserNotOnProposalWithRole, {
reviewID: 1,
comment: 'Good proposal',
grade: 9,
grade: '9',
status: ReviewStatus.DRAFT,
fapID: 1,
questionaryID: 1,
Expand All @@ -50,7 +50,7 @@ test('A Fap chair can not modify Fap review if it is submitted', () => {
reviewMutations.updateReview(dummyFapChairWithRole, {
reviewID: 5,
comment: 'Good proposal test',
grade: 9,
grade: '9',
status: ReviewStatus.SUBMITTED,
fapID: 1,
questionaryID: 1,
Expand All @@ -66,7 +66,7 @@ test('A Fap secretary can not modify Fap review if it is submitted', () => {
reviewMutations.updateReview(dummyFapSecretaryWithRole, {
reviewID: 5,
comment: 'Good proposal test',
grade: 9,
grade: '9',
status: ReviewStatus.SUBMITTED,
fapID: 1,
questionaryID: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
ArgsType,
Ctx,
Field,
Float,
Int,
Mutation,
Resolver,
Expand All @@ -21,11 +20,11 @@ export class UpdateReviewArgs {
@Field()
public comment: string;

@Field(() => Float)
public grade: number;
@Field(() => String)
public grade: string;

@Field(() => ReviewStatus)
status: ReviewStatus;
public status: ReviewStatus;

@Field(() => Int)
public fapID: number;
Expand Down
14 changes: 13 additions & 1 deletion apps/backend/src/resolvers/types/FieldConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,19 @@ export class VisitBasisConfig extends ConfigBase {}
export class ExperimentSafetyReviewBasisConfig extends ConfigBase {}

@ObjectType()
export class FapReviewBasisConfig extends ConfigBase {}
export class FapReviewBasisConfig extends ConfigBase {
@Field(() => [String])
nonNumericOptions: string[];

@Field(() => Int)
minGrade: number;

@Field(() => Int)
maxGrade: number;

@Field(() => Int)
decimalPoints: number;
}

@ObjectType()
export class TechnicalReviewBasisConfig extends ConfigBase {}
Expand Down
5 changes: 2 additions & 3 deletions apps/backend/src/resolvers/types/Review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
Ctx,
Field,
FieldResolver,
Float,
Int,
ObjectType,
Resolver,
Expand All @@ -27,8 +26,8 @@ export class Review implements Partial<ReviewOrigin> {
@Field({ nullable: true })
public comment?: string;

@Field(() => Float, { nullable: true })
public grade?: number;
@Field(() => String, { nullable: true })
public grade?: string;

@Field(() => ReviewStatus)
public status: ReviewStatus;
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/utils/mathFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const average = (numbers: number[]) => {
export const getGrades = (reviews: Review[] | null | undefined) =>
reviews
?.filter((review) => review.status === ReviewStatus.SUBMITTED)
.map((review) => review.grade as number) ?? [];
.map((review) => parseFloat(review.grade)) ?? [];

export const sortByRankOrder = (
a: FapProposalWithReviewGradesAndRanking,
Expand Down
Loading