Skip to content
Merged
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
10 changes: 6 additions & 4 deletions apps/backend/src/datasources/postgres/ProposalDataSource.ts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot

Here is my suggestion

async getInvitedProposal(inviteId: number): Promise<InvitedProposal | null> {
return await database
.select(
'proposals.proposal_id',
'proposer.firstname as proposer_name',
'proposals.abstract',
'proposals.title'
)
.from('co_proposer_claims')
.join('proposals', {
'co_proposer_claims.proposal_pk': 'proposals.proposal_pk',
})
.join('users as proposer', {
'proposals.proposer_id': 'proposer.user_id',
})
.where('invite_id', inviteId)
.first()
.then((proposal: InvitedProposalRecord) => {
return proposal ? createInvitedProposalObject(proposal) : null;
});
}

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.

This is already implemented in commit 33426ebgetInvitedProposal uses .first() with the .then() guard exactly as suggested.

Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ export default class PostgresProposalDataSource implements ProposalDataSource {
}

async getInvitedProposal(inviteId: number): Promise<InvitedProposal | null> {
const proposals: InvitedProposalRecord[] | undefined = await database
return await database
.select(
'proposals.proposal_id',
'proposer.firstname as proposer_name',
Expand All @@ -1433,8 +1433,10 @@ export default class PostgresProposalDataSource implements ProposalDataSource {
.join('users as proposer', {
'proposals.proposer_id': 'proposer.user_id',
})
.where('invite_id', inviteId);

return proposals ? createInvitedProposalObject(proposals[0]) : null;
.where('invite_id', inviteId)
.first()
.then((proposal: InvitedProposalRecord | undefined) =>
proposal ? createInvitedProposalObject(proposal) : null
);
}
}
Loading