Skip to content
This repository was archived by the owner on Oct 20, 2022. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f44f3d5
feat: Call should end on endCycle instead of endCall date
martin-trajanovski Jun 2, 2022
a339ef1
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jun 8, 2022
dae940d
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jun 9, 2022
ac77bf6
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jun 9, 2022
c1ba916
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jun 9, 2022
cd0afcc
revert some changes and fix the call end by cycle date
martin-trajanovski Jun 10, 2022
a94a878
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jun 13, 2022
135ba52
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jun 15, 2022
8efce0a
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jun 21, 2022
a759010
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jun 21, 2022
bb01167
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jun 21, 2022
69d2562
feat: Change isActive logic on the call with introducing new flag in …
martin-trajanovski Jun 21, 2022
dec5e27
fix unit tests
martin-trajanovski Jun 22, 2022
09e02e8
Fix the call ended comparisson and checks
martin-trajanovski Jun 22, 2022
b981842
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jun 22, 2022
e7a5419
fix failing unit tests
martin-trajanovski Jun 23, 2022
68cf2e8
Merge branch 'SWAP-2465-end-call-after-cycle-end' of https://github.c…
martin-trajanovski Jun 23, 2022
72a4696
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jun 27, 2022
1908c24
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jul 4, 2022
3804a0c
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jul 20, 2022
4c82bf5
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jul 25, 2022
733bfdb
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jul 25, 2022
adc42d3
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Jul 27, 2022
956668b
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Aug 5, 2022
e4486f0
Merge branch 'develop' into SWAP-2465-end-call-after-cycle-end
martin-trajanovski Aug 15, 2022
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: 12 additions & 0 deletions db_patches/0124_AddIsActiveCallFlag.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DO
$$
BEGIN
IF register_patch('AddIsActiveCallFlag.sql', 'Martin Trajanovski', 'Add is_active flag to the calls table', '2022-06-21') THEN

ALTER TABLE "call"
ADD COLUMN is_active boolean DEFAULT true;

END IF;
END;
$$
LANGUAGE plpgsql;
121 changes: 38 additions & 83 deletions 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"@user-office-software/duo-logger": "^2.0.2",
"@user-office-software/duo-message-broker": "^1.3.0",
"@user-office-software/duo-validation": "^3.2.0",
"apollo-graphql": "^0.9.5",
"apollo-graphql": "^0.9.7",
"apollo-server-core": "^3.9.0",
"apollo-server-express": "^3.6.3",
"apollo-server-express": "^3.9.0",
"await-to-js": "^2.1.1",
"axios": "^0.26.0",
"bcryptjs": "^2.4.3",
Expand Down
8 changes: 4 additions & 4 deletions src/auth/ProposalAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class ProposalAuthorization {

private async isProposalEditable(proposal: Proposal): Promise<boolean> {
const callId = proposal.callId;
const isCallActive = await this.callDataSource.checkActiveCall(callId);
const isCallEnded = await this.callDataSource.isCallEnded(callId);
const proposalStatus = (
await this.proposalSettingsDataSource.getProposalStatus(proposal.statusId)
)?.shortCode;
Expand All @@ -205,10 +205,10 @@ export class ProposalAuthorization {
return true;
}

if (isCallActive) {
return proposalStatus === ProposalStatusDefaultShortCodes.DRAFT;
} else {
if (isCallEnded) {
return false;
} else {
return proposalStatus === ProposalStatusDefaultShortCodes.DRAFT;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/datasources/CallDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export interface CallDataSource {
args: RemoveAssignedInstrumentFromCallInput
): Promise<Call>;
getCallsByInstrumentScientist(scientistId: number): Promise<Call[]>;
checkActiveCall(callId: number): Promise<boolean>;
isCallEnded(callId: number): Promise<boolean>;
}
13 changes: 8 additions & 5 deletions src/datasources/mockups/CallDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const dummyCallFactory = (values?: Partial<Call>) => {
values?.esiTemplateId || 2,
values?.allocationTimeUnit || AllocationTimeUnits.Day,
values?.title || 'Title',
values?.description || 'Description'
values?.description || 'Description',
values?.isActive || true
);
};

Expand Down Expand Up @@ -65,7 +66,8 @@ export const dummyCall = new Call(
2,
AllocationTimeUnits.Day,
'',
''
'',
true
);

export const anotherDummyCall = new Call(
Expand Down Expand Up @@ -94,7 +96,8 @@ export const anotherDummyCall = new Call(
2,
AllocationTimeUnits.Day,
'',
''
'',
true
);

export const dummyCalls = [dummyCall, anotherDummyCall];
Expand Down Expand Up @@ -153,7 +156,7 @@ export class CallDataSourceMock implements CallDataSource {
return dummyCalls;
}

async checkActiveCall(callId: number): Promise<boolean> {
return callId === 1;
async isCallEnded(callId: number): Promise<boolean> {
return callId !== 1;
}
}
29 changes: 17 additions & 12 deletions src/datasources/postgres/CallDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@ export default class PostgresCallDataSource implements CallDataSource {

// if filter is explicitly set to true or false
if (filter?.isActive === true) {
const currentDate = new Date().toISOString();
query
.where('start_call', '<=', currentDate)
.andWhere('end_call', '>=', currentDate);
query.where('is_active', true);
} else if (filter?.isActive === false) {
const currentDate = new Date().toISOString();
query
.where('start_call', '>=', currentDate)
.orWhere('end_call', '<=', currentDate);
query.where('is_active', false);
}

/**
* NOTE: We are comparing dates instead of using the call_ended flag,
* because the flag is set once per hour and we could have a gap.
* TODO: Maybe there is a need to use the timezone setting here but not quite sure about it. Discussion is needed here!
Copy link
Contributor

Choose a reason for hiding this comment

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

I would have thought this would be fine as new Date().toISOString() and start_call and end_call is all in UTC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@simonfernandes thank you I can remove the comment then. 🙂

*/
const currentDate = new Date().toISOString();
if (filter?.isEnded === true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the filter value isEnded used? If no service is using it we could consider removing it.

query.where('call_ended', true);
query
.where('start_call', '>=', currentDate)
.andWhere('end_call', '<=', currentDate);
} else if (filter?.isEnded === false) {
query.where('call_ended', false);
query
.where('start_call', '<=', currentDate)
.andWhere('end_call', '>=', currentDate);
}

if (filter?.isReviewEnded === true) {
Expand Down Expand Up @@ -233,6 +237,7 @@ export default class PostgresCallDataSource implements CallDataSource {
allocation_time_unit: args.allocationTimeUnit,
title: args.title,
description: args.description,
is_active: args.isActive,
},
['*']
)
Expand Down Expand Up @@ -315,7 +320,7 @@ export default class PostgresCallDataSource implements CallDataSource {
return records.map(createCallObject);
}

public async checkActiveCall(callId: number): Promise<boolean> {
public async isCallEnded(callId: number): Promise<boolean> {
const currentDate = new Date().toISOString();

return database
Expand All @@ -325,6 +330,6 @@ export default class PostgresCallDataSource implements CallDataSource {
.andWhere('end_call', '>=', currentDate)
.andWhere('call_id', '=', callId)
.first()
.then((call: CallRecord) => (call ? true : false));
.then((call: CallRecord) => (call ? false : true));
}
}
Loading