Skip to content

Commit

Permalink
Merge pull request #13 from bcgov/ux/submissions-alignment
Browse files Browse the repository at this point in the history
Submissions view UX/UI alignment
  • Loading branch information
jujaga authored Jan 12, 2024
2 parents a08d642 + eb14ba8 commit c0465fb
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 132 deletions.
59 changes: 47 additions & 12 deletions app/src/controllers/chefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,79 @@ import { IdentityProvider } from '../components/constants';

import type { JwtPayload } from 'jsonwebtoken';
import type { NextFunction, Request, Response } from '../interfaces/IExpress';
import type { ChefsFormConfig, ChefsFormConfigData, ChefsSubmissionFormExport } from '../types';
import type { ChefsFormConfig, ChefsFormConfigData, ChefsSubmissionForm, ChefsSubmissionFormExport } from '../types';

const controller = {
getFormExport: async (req: Request, res: Response, next: NextFunction) => {
try {
const cfg = config.get('server.chefs.forms') as ChefsFormConfig;
let formData = new Array<ChefsSubmissionFormExport>();

// Get a JSON export of all form data merged into a single array
await Promise.all(
const exportData: Array<Partial<ChefsSubmissionForm & { formId: string }>> = await Promise.all(
Object.values<ChefsFormConfigData>(cfg).map(async (x: ChefsFormConfigData) => {
const data = await chefsService.getFormExport(x.id);
data.forEach((d: ChefsSubmissionFormExport) => (d.form.id = x.id));
formData = formData.concat(data);
return (await chefsService.getFormExport(x.id)).map((data: ChefsSubmissionFormExport) => {
const financiallySupportedValues = {
financiallySupportedBC: isTruthy(data.isBCHousingSupported),
financiallySupportedIndigenous: isTruthy(data.isIndigenousHousingProviderSupported),
financiallySupportedNonProfit: isTruthy(data.isNonProfitSupported),
financiallySupportedHousingCoop: isTruthy(data.isHousingCooperativeSupported)
};

return {
formId: x.id,
submissionId: data.form.submissionId,
confirmationId: data.form.confirmationId,
contactEmail: data.contactEmail,
contactPhoneNumber: data.contactPhoneNumber,
contactName: `${data.contactFirstName} ${data.contactLastName}`,
financiallySupported: Object.values(financiallySupportedValues).includes(true),
...financiallySupportedValues,
intakeStatus: data.form.status,
latitude: data.latitude,
longitude: data.longitude,
naturalDisaster: data.naturalDisasterInd,
projectName: data.companyNameRegistered,
queuePriority: data.queuePriority,
singleFamilyUnits: data.singleFamilyUnits ?? data.multiFamilyUnits,
streetAddress: data.streetAddress,
submittedAt: data.form.createdAt,
submittedBy: data.form.username
};
});
})
);
).then((x) => x.filter((y) => y.length).flat());

// Get a list of all submission IDs
const result = await chefsService.searchSubmissions({
submissionId: exportData.map((x) => x.submissionId as string)
});

// Overwrite export data with application data where possible
const mergedExportData = exportData.map((x: Partial<ChefsSubmissionForm & { formId: string }>) => ({
...x,
...result.find((y) => y?.submissionId === x.submissionId)
}));

/*
* Filter Data source
* IDIR users should be able to see all submissions
* BCeID/Business should only see their own submissions
*/
const filterData = (data: Array<ChefsSubmissionFormExport>) => {
const filterData = (data: Array<Partial<ChefsSubmissionForm & { formId: string }>>) => {
const tokenPayload = req.currentUser?.tokenPayload as JwtPayload;
const filterToUser = tokenPayload && tokenPayload.identity_provider !== IdentityProvider.IDIR;

if (isTruthy(filterToUser)) {
return data.filter(
(x: { form: { username: string } }) =>
x.form.username.toUpperCase().substring(0, x.form.username.indexOf('@')) ===
(x: Partial<ChefsSubmissionForm>) =>
x.submittedBy?.toUpperCase().substring(0, x.submittedBy.indexOf('@')) ===
(req.currentUser?.tokenPayload as JwtPayload).bceid_username.toUpperCase()
);
} else {
return data;
}
};

res.status(200).send(filterData(formData));
res.status(200).send(filterData(mergedExportData));
} catch (e: unknown) {
next(e);
}
Expand Down
25 changes: 24 additions & 1 deletion app/src/services/chefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import prisma from '../db/dataConnection';
import { submission } from '../db/models';

import type { AxiosInstance, AxiosRequestConfig } from 'axios';
import type { ChefsSubmissionForm } from '../types';
import type { ChefsSubmissionForm, SubmissionSearchParameters } from '../types';

/**
* @function chefsAxios
Expand Down Expand Up @@ -105,6 +105,29 @@ const service = {
}
},

/**
* @function searchSubmissions
* Search and filter for specific submission
* @param {string[]} [params.submissionId] Optional array of uuids representing the submission ID
* @returns {Promise<object>} The result of running the findMany operation
*/
searchSubmissions: async (params: SubmissionSearchParameters) => {
const result = await prisma.submission.findMany({
where: {
OR: [
{
submissionId: { in: params.submissionId }
}
]
},
include: {
user: true
}
});

return result.map((x) => submission.fromDBModel(x));
},

updateSubmission: async (data: ChefsSubmissionForm) => {
try {
await prisma.submission.update({
Expand Down
4 changes: 2 additions & 2 deletions app/src/services/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ const service = {
where: {
OR: [
{
userId: { in: params.userId, mode: 'insensitive' }
userId: { in: params.userId }
},
{
identityId: { in: params.identityId, mode: 'insensitive' }
identityId: { in: params.identityId }
},
{
idp: { in: params.idp, mode: 'insensitive' }
Expand Down
24 changes: 23 additions & 1 deletion app/src/types/ChefsSubmissionFormExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,27 @@ export type ChefsSubmissionFormExport = {
assignee: string;
assigneedEmail: string;
};
// Additional form field data will be added

submissionId: string;
confirmationId: string;
contactEmail: string;
contactPhoneNumber: string;
contactFirstName: string;
contactLastName: string;
financiallySupported: boolean;
intakeStatus: string;
isBCHousingSupported: boolean;
isIndigenousHousingProviderSupported: boolean;
isNonProfitSupported: boolean;
isHousingCooperativeSupported: boolean;
latitude: number;
longitude: number;
naturalDisasterInd: boolean;
companyNameRegistered: string;
queuePriority: number;
singleFamilyUnits: string;
multiFamilyUnits: string;
streetAddress: string;
createdAt: string;
createdBy: string;
};
3 changes: 3 additions & 0 deletions app/src/types/SubmissionSearchParameters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type SubmissionSearchParameters = {
submissionId?: Array<string>;
};
1 change: 1 addition & 0 deletions app/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type { ChefsSubmissionForm } from './ChefsSubmissionForm';
export type { ChefsSubmissionFormExport } from './ChefsSubmissionFormExport';
export type { CurrentUser } from './CurrentUser';
export type { IdentityProvider } from './IdentityProvider';
export type { SubmissionSearchParameters } from './SubmissionSearchParameters';
export type { User } from './User';
export type { UserSearchParameters } from './UserSearchParameters';
export type { YRN } from './YRN';
1 change: 1 addition & 0 deletions frontend/src/types/ChefsSubmissionForm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { User } from './User';

export type ChefsSubmissionForm = {
formId?: string;
submissionId: string;
confirmationId: string;
submittedAt: string;
Expand Down
Loading

0 comments on commit c0465fb

Please sign in to comment.