Skip to content

Commit 41d51cb

Browse files
yoganandanessgithub-actions[bot]
authored andcommitted
WIP
1 parent 9b3939e commit 41d51cb

19 files changed

Lines changed: 492 additions & 13 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
DO
2+
$DO$
3+
DECLARE
4+
invite_id_var1 int;
5+
invite_id_var2 int;
6+
invite_id_var3 int;
7+
invite_id_var4 int;
8+
BEGIN
9+
10+
INSERT INTO invites (code, email, created_by, created_at, claimed_by, claimed_at, is_email_sent, expires_at, template_id)
11+
VALUES ('DAVE001', 'david@teleworm.us', 1, NOW(), NULL, NULL, false, NULL, 'user-office-registration-invitation-co-proposer');
12+
13+
SELECT invite_id
14+
INTO invite_id_var1
15+
FROM invites
16+
WHERE email = 'david@teleworm.us' AND code = 'DAVE001';
17+
18+
INSERT INTO invites (code, email, created_by, created_at, claimed_by, claimed_at, is_email_sent, expires_at, template_id)
19+
VALUES ('BEN001', 'ben@inbox.com', 1, NOW(), NULL, NULL, false, NULL, 'user-office-registration-invitation-co-proposer');
20+
21+
SELECT invite_id
22+
INTO invite_id_var2
23+
FROM invites
24+
WHERE email = 'ben@inbox.com' AND code = 'BEN001';
25+
26+
INSERT INTO co_proposer_claims (invite_id, proposal_pk) VALUES (invite_id_var1, 1);
27+
INSERT INTO co_proposer_claims (invite_id, proposal_pk) VALUES (invite_id_var2, 1);
28+
29+
INSERT INTO invites (code, email, created_by, created_at, claimed_by, claimed_at, is_email_sent, expires_at, template_id)
30+
VALUES ('DAVE002', 'david@teleworm.us', 1, NOW(), NULL, NULL, false, NULL, '');
31+
32+
SELECT invite_id
33+
INTO invite_id_var3
34+
FROM invites
35+
WHERE email = 'david@teleworm.us' AND code = 'DAVE002';
36+
37+
INSERT INTO invites (code, email, created_by, created_at, claimed_by, claimed_at, is_email_sent, expires_at, template_id)
38+
VALUES ('BEN002', 'ben@inbox.com', 1, NOW(), NULL, NULL, false, NULL, '');
39+
40+
SELECT invite_id
41+
INTO invite_id_var4
42+
FROM invites
43+
WHERE email = 'ben@inbox.com' AND code = 'BEN002';
44+
45+
INSERT INTO co_proposer_claims (invite_id, proposal_pk) VALUES (invite_id_var3, 2);
46+
INSERT INTO co_proposer_claims (invite_id, proposal_pk) VALUES (invite_id_var4, 2);
47+
48+
END;
49+
$DO$
50+
LANGUAGE plpgsql;

apps/backend/src/auth/ProposalAuthorization.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ export class ProposalAuthorization {
242242
return isInternalReviewerOnSomeTechnicalReview;
243243
}
244244

245+
// async isInvitee(agent: UserWithRole, proposalPk: number) {
246+
// return this.inviteDataSource.isInvitee(agent.id, proposalPk);
247+
// }
248+
245249
async hasReadRights(
246250
agent: UserWithRole | null,
247251
proposalOrProposalId: Proposal | number

apps/backend/src/datasources/InviteDataSource.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface GetInvitesFilter {
55
createdAfter?: Date;
66
isClaimed?: boolean;
77
isExpired?: boolean;
8+
email?: string;
89
}
910

1011
export interface InviteDataSource {

apps/backend/src/datasources/ProposalDataSource.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Event } from '../events/event.enum';
22
import { Call } from '../models/Call';
3-
import { Proposal, Proposals } from '../models/Proposal';
3+
import { InvitedProposal, Proposal, Proposals } from '../models/Proposal';
44
import { ProposalView } from '../models/ProposalView';
55
import { TechnicalReview } from '../models/TechnicalReview';
66
import { UserWithRole } from '../models/User';
@@ -92,4 +92,5 @@ export interface ProposalDataSource {
9292
sortDirection?: string,
9393
searchText?: string
9494
): Promise<{ totalCount: number; proposals: ProposalView[] }>;
95+
getInvitedProposal(inviteId: number): Promise<InvitedProposal | null>;
9596
}

apps/backend/src/datasources/mockups/ProposalDataSource.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import 'reflect-metadata';
22
import { Event } from '../../events/event.enum';
33
import { AllocationTimeUnits, Call } from '../../models/Call';
44
import { FapMeetingDecision } from '../../models/FapMeetingDecision';
5-
import { Proposal, ProposalEndStatus, Proposals } from '../../models/Proposal';
5+
import {
6+
InvitedProposal,
7+
Proposal,
8+
ProposalEndStatus,
9+
Proposals,
10+
} from '../../models/Proposal';
611
import { ProposalView } from '../../models/ProposalView';
712
import {
813
TechnicalReview,
@@ -422,4 +427,8 @@ export class ProposalDataSourceMock implements ProposalDataSource {
422427
) {
423428
return { totalCount: 1, proposals: [dummyProposalView] };
424429
}
430+
431+
getInvitedProposal(inviteId: number): Promise<InvitedProposal | null> {
432+
throw new Error('Method not implemented.');
433+
}
425434
}

apps/backend/src/datasources/postgres/InviteDataSource.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Invite } from '../../models/Invite';
44
import { GetInvitesFilter, InviteDataSource } from '../InviteDataSource';
55
import database from './database';
66
import { createInviteObject, InviteRecord } from './records';
7-
87
export default class PostgresInviteDataSource implements InviteDataSource {
98
findCoProposerInvites(
109
proposalPk: number,
@@ -100,6 +99,10 @@ export default class PostgresInviteDataSource implements InviteDataSource {
10099
if (filter.isExpired) {
101100
query.where('expires_at', '<', new Date());
102101
}
102+
103+
if (filter.email) {
104+
query.where('email', filter.email);
105+
}
103106
})
104107
.then((invites: InviteRecord[]) => invites.map(createInviteObject));
105108
}

apps/backend/src/datasources/postgres/ProposalDataSource.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { inject, injectable } from 'tsyringe';
77
import { Tokens } from '../../config/Tokens';
88
import { Event } from '../../events/event.enum';
99
import { Call } from '../../models/Call';
10-
import { Proposal, Proposals } from '../../models/Proposal';
10+
import { InvitedProposal, Proposal, Proposals } from '../../models/Proposal';
1111
import { ProposalView } from '../../models/ProposalView';
1212
import { getQuestionDefinition } from '../../models/questionTypes/QuestionRegistry';
1313
import { ReviewerFilter } from '../../models/Review';
@@ -40,6 +40,8 @@ import {
4040
TechnicalReviewRecord,
4141
TechniqueRecord,
4242
createProposalViewObjectWithTechniques,
43+
InvitedProposalRecord,
44+
createInvitedProposalObject,
4345
} from './records';
4446

4547
const fieldMap: { [key: string]: string } = {
@@ -1309,4 +1311,21 @@ export default class PostgresProposalDataSource implements ProposalDataSource {
13091311

13101312
return proposal ? createProposalObject(proposal[0]) : null;
13111313
}
1314+
1315+
async getInvitedProposal(inviteId: number): Promise<InvitedProposal | null> {
1316+
const proposals: InvitedProposalRecord[] | undefined = await database
1317+
.select(
1318+
'proposals.proposal_id',
1319+
'proposals.title',
1320+
'proposals.abstract',
1321+
'proposals.proposer_id'
1322+
)
1323+
.from('co_proposer_claims')
1324+
.join('proposals', {
1325+
'co_proposer_claims.proposal_pk': 'proposals.proposal_pk',
1326+
})
1327+
.where('invite_id', inviteId);
1328+
1329+
return proposals ? createInvitedProposalObject(proposals[0]) : null;
1330+
}
13121331
}

apps/backend/src/datasources/postgres/records.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ import { Institution } from '../../models/Institution';
2424
import { Instrument } from '../../models/Instrument';
2525
import { Invite } from '../../models/Invite';
2626
import { PredefinedMessage } from '../../models/PredefinedMessage';
27-
import { Proposal, ProposalEndStatus } from '../../models/Proposal';
27+
import {
28+
InvitedProposal,
29+
Proposal,
30+
ProposalEndStatus,
31+
} from '../../models/Proposal';
2832
import { ProposalInternalComment } from '../../models/ProposalInternalComment';
2933
import { ProposalPdfTemplate } from '../../models/ProposalPdfTemplate';
3034
import { ProposalView } from '../../models/ProposalView';
@@ -173,6 +177,13 @@ export interface ProposalViewRecord {
173177
readonly techniques: ProposalViewTechnique[];
174178
}
175179

180+
export interface InvitedProposalRecord {
181+
readonly proposal_id: string;
182+
readonly proposer_id: number;
183+
readonly title: string;
184+
readonly abstract: string;
185+
}
186+
176187
export interface TopicRecord {
177188
readonly topic_id: number;
178189
readonly topic_title: string;
@@ -901,6 +912,15 @@ export const createProposalViewObject = (proposal: ProposalViewRecord) => {
901912
);
902913
};
903914

915+
export const createInvitedProposalObject = (record: InvitedProposalRecord) => {
916+
return new InvitedProposal(
917+
record.proposal_id,
918+
record.proposer_id,
919+
record.title,
920+
record.abstract
921+
);
922+
};
923+
904924
export const createFieldDependencyObject = (
905925
fieldDependency: FieldDependencyRecord & { natural_key: string }
906926
) => {

apps/backend/src/models/Proposal.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ export class Proposal {
5252
) {}
5353
}
5454

55+
export class InvitedProposal {
56+
constructor(
57+
public proposalId: string,
58+
public proposerId: number,
59+
public title: string,
60+
public abstract: string
61+
) {}
62+
}
63+
5564
export class ProposalPks {
5665
constructor(public proposalPks: number[]) {}
5766
}

apps/backend/src/queries/InviteQueries.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,19 @@ export default class InviteQueries {
5757

5858
return invites;
5959
}
60+
61+
@Authorized()
62+
async getUserInvites(agent: UserWithRole | null) {
63+
if (!agent) {
64+
return [];
65+
}
66+
67+
const invites = await this.dataSource.getInvites({
68+
email: agent.email,
69+
isClaimed: false,
70+
isExpired: false,
71+
});
72+
73+
return invites;
74+
}
6075
}

0 commit comments

Comments
 (0)