Skip to content

Commit

Permalink
Merge pull request #468 from bcgov/development
Browse files Browse the repository at this point in the history
multiple twu resources
  • Loading branch information
bdolor authored Mar 12, 2024
2 parents 3d1f7f2 + 2990b6f commit 352e578
Show file tree
Hide file tree
Showing 43 changed files with 2,403 additions and 1,265 deletions.
362 changes: 285 additions & 77 deletions src/back-end/lib/db/opportunity/team-with-us.ts

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions src/back-end/lib/db/proposal/team-with-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ async function rawHistoryRecordToHistoryRecord(
};
}

/**
* "raw" indicates reading data from the db and modifying the data to conform
* to type declarations in the application. In this case, the db holds a memberID
* which is then used to get a username 'idpUsername'.
*
* @param connection
* @param raw
*/
async function rawProposalTeamMemberToProposalTeamMember(
connection: Connection,
raw: RawProposalTeamMember
Expand Down Expand Up @@ -643,7 +651,7 @@ const readTWUProposalMembers = tryDb<[Id], RawProposalTeamMember[]>(
proposalId
);

query.select<RawProposalTeamMember[]>("member", "hourlyRate");
query.select<RawProposalTeamMember[]>("member", "hourlyRate", "resource");

const results = await query;

Expand Down Expand Up @@ -856,7 +864,8 @@ async function createTWUProposalTeamMembers(
{
proposal: proposalId,
member: teamMember.member,
hourlyRate: teamMember.hourlyRate
hourlyRate: teamMember.hourlyRate,
resource: teamMember.resource
},
"*"
);
Expand Down Expand Up @@ -1255,14 +1264,21 @@ async function calculatePriceScore(
"=",
"members.proposal"
)
.join("twuResources as resources", "members.resource", "=", "resources.id")
.whereIn("proposals.opportunity", function () {
this.where({ id: proposalId }).select("opportunity").from("twuProposals");
})
.whereIn("statuses.status", [
TWUProposalStatus.UnderReviewChallenge,
TWUProposalStatus.EvaluatedChallenge
])
.sum("members.hourlyRate as bid")
// multiple resources requires matching the hourly rate of the team member
// with the targetAllocation for the opportunity
.select(
connection.raw(
'SUM(members."hourlyRate" * resources."targetAllocation" / 100) AS bid'
)
)
.groupBy("proposals.id")
.select<ProposalBidRecord[]>("proposals.id")
.orderBy("bid", "asc");
Expand Down
25 changes: 25 additions & 0 deletions src/back-end/lib/db/service-area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ import {
TWUServiceAreaRecord
} from "shared/lib/resources/service-area";
import { Id } from "shared/lib/types";
import { TWUServiceArea } from "shared/lib/resources/opportunity/team-with-us";

/**
* Reads a service area from the database, returns a number (id) if given a string value (enum)
*
* @param connection
* @param serviceArea - the enum value
* @returns ServiceAreaId - the id value of the service area in the database
*/
export const readOneServiceAreaByServiceArea = tryDb<
[Id],
ServiceAreaId | null
Expand All @@ -15,3 +23,20 @@ export const readOneServiceAreaByServiceArea = tryDb<
.first();
return valid(result ? result.id : null);
});

/**
* Reads a service area from the database, returns a service area (enum) if given a number (id) value
*
* @param connection
* @param id - serviceAreaId
* @returns TWUServiceArea - the enum value
*/
export const readOneServiceAreaByServiceAreaId = tryDb<
[ServiceAreaId],
TWUServiceArea | null
>(async (connection, id) => {
const result = await connection<TWUServiceAreaRecord>("serviceAreas")
.where({ id })
.first();
return valid(result ? result.serviceArea : null);
});
12 changes: 7 additions & 5 deletions src/back-end/lib/mailer/notifications/affiliation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export async function addedToTeamT(affiliation: Affiliation): Promise<Emails> {
</p>
<p>
If you approve the membership, you can be included as a team
member on future Sprint With Us proposals submitted by{" "}
{organization.legalName}.
member on future Sprint With Us or Team With Us proposals
submitted by {organization.legalName}.
</p>
</div>
),
Expand Down Expand Up @@ -124,7 +124,8 @@ export async function approvedRequestToJoinT(
</p>
<p>
{memberName} can now be included in proposals submitted by{" "}
{organizationName} to Sprint With Us opportunities.
{organizationName} to Sprint With Us or Team With Us
opportunities.
</p>
</div>
),
Expand Down Expand Up @@ -184,7 +185,7 @@ export async function membershipCompleteT(
</p>
<p>
{organizationName} can now include you on proposals to Sprint With
Us opportunities.
Us or Team With Us opportunities.
</p>
</div>
),
Expand Down Expand Up @@ -214,7 +215,8 @@ export async function memberLeavesT(
<p>
{memberName} has left {organizationName}
{"'"}s team on the Digital Marketplace. They will no longer be
able to be included on proposals for Sprint With Us opportunities.
able to be included on proposals for Sprint With Us or Team With
Us opportunities.
</p>
</div>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ export function makeTWUOpportunityInformation(
opportunity: TWUOpportunity,
showDueDate = true
): templates.DescriptionListProps {
const serviceAreas = opportunity.resources.map((resource, index) => ({
name: "Service Area ".concat(`${index + 1}`),
value: `${startCase(lowerCase(resource.serviceArea))}`
}));
const items = [
{ name: "Type", value: "Team With Us" },
{ name: "Value", value: `$${formatAmount(opportunity.maxBudget)}` },
{
name: "Service Area",
value: `${startCase(lowerCase(opportunity.serviceArea))}`
},
...serviceAreas,
{
name: "Contract Start Date",
value: formatDate(opportunity.startDate, false)
Expand Down
2 changes: 1 addition & 1 deletion src/back-end/lib/mailer/notifications/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function inviteToRegisterT(
/>{" "}
for a Digital Marketplace account. Once you have signed up, you
can join their team and be included in proposals to Sprint With Us
opportunities.
or Team With Us opportunities.
</p>
</div>
),
Expand Down
6 changes: 3 additions & 3 deletions src/back-end/lib/resources/opportunity/sprint-with-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ const create: crud.Create<
const validatedMandatorySkills =
genericValidation.validateMandatorySkills(mandatorySkills);
const validatedOptionalSkills =
opportunityValidation.validateOptionalSkills(optionalSkills);
genericValidation.validateOptionalSkills(optionalSkills);
const validatedDescription =
genericValidation.validateDescription(description);
const validatedQuestionsWeight =
Expand Down Expand Up @@ -1077,7 +1077,7 @@ const update: crud.Update<
const validatedMandatorySkills =
genericValidation.validateMandatorySkills(mandatorySkills);
const validatedOptionalSkills =
opportunityValidation.validateOptionalSkills(optionalSkills);
genericValidation.validateOptionalSkills(optionalSkills);
const validatedDescription =
genericValidation.validateDescription(description);
const validatedQuestionsWeight =
Expand Down Expand Up @@ -1295,7 +1295,7 @@ const update: crud.Update<
genericValidation.validateMandatorySkills(
validatedSWUOpportunity.value.mandatorySkills
),
opportunityValidation.validateOptionalSkills(
genericValidation.validateOptionalSkills(
validatedSWUOpportunity.value.optionalSkills
),
genericValidation.validateDescription(
Expand Down
Loading

0 comments on commit 352e578

Please sign in to comment.