Skip to content

Commit

Permalink
#4275 - Document uploader email adjustment and time stamp in ui - par…
Browse files Browse the repository at this point in the history
…t 2 (#4393)

- Added new GC notify template;
- Added original file names to the message payload:

![image](https://github.com/user-attachments/assets/3820cc60-12a1-44c6-9f79-068cf2bab0ab)
- Changed UI to use `created_at` to for "Date submitted" column;
- Formatted "Date submitted" column to use the format "MMM DD YYYY
HH:mm":

![image](https://github.com/user-attachments/assets/aedfeef2-39c4-4779-b40c-0861489b5eb2)
- Added a e2e test to check the fileUpload update and the notification.
  • Loading branch information
andrepestana-aot authored Feb 27, 2025
1 parent e24918f commit c0d1fa4
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe("StudentInstitutionsController(e2e)-getStudentFileUploads", () => {
uniqueFileName: studentUploadedFile.uniqueFileName,
metadata: studentUploadedFile.metadata,
groupName: "Ministry communications",
updatedAt: studentUploadedFile.updatedAt.toISOString(),
createdAt: studentUploadedFile.updatedAt.toISOString(),
fileOrigin: studentUploadedFile.fileOrigin,
},
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import { HttpStatus, INestApplication } from "@nestjs/common";
import * as request from "supertest";
import {
BEARER_AUTH_TYPE,
createTestingAppModule,
FakeStudentUsersTypes,
getStudentToken,
mockUserLoginInfo,
} from "../../../../testHelpers";
import {
E2EDataSources,
createE2EDataSources,
saveFakeApplication,
saveFakeStudent,
saveFakeStudentFileUpload,
} from "@sims/test-utils";
import { TestingModule } from "@nestjs/testing";
import { getDateOnlyFormat } from "@sims/utilities";
import { FileOriginType, NotificationMessageType } from "@sims/sims-db";

describe("StudentStudentsController(e2e)-saveStudentUploadedFiles", () => {
let app: INestApplication;
let db: E2EDataSources;
let appModule: TestingModule;

beforeAll(async () => {
const { nestApplication, dataSource, module } =
await createTestingAppModule();
app = nestApplication;
db = createE2EDataSources(dataSource);

appModule = module;
await db.notificationMessage.update(
{ id: NotificationMessageType.StudentFileUpload },
{ emailContacts: ["[email protected]"] },
);
});

it("Should save all uploaded files when a proper student file upload request is made.", async () => {
// Arrange
const student = await saveFakeStudent(db.dataSource);
const application = await saveFakeApplication(db.dataSource, { student });
const studentToken = await getStudentToken(
FakeStudentUsersTypes.FakeStudentUserType1,
);
const studentFile1 = await saveFakeStudentFileUpload(
db.dataSource,
{
student,
creator: student.user,
},
{
fileOrigin: FileOriginType.Student,
groupName: "application",
},
);
const studentFile2 = await saveFakeStudentFileUpload(
db.dataSource,
{
student,
creator: student.user,
},
{
fileOrigin: FileOriginType.Student,
groupName: "application",
},
);

const payload = {
submittedForm: {
documentPurpose: "application",
applicationNumber: application.applicationNumber,
},
associatedFiles: [
studentFile1.uniqueFileName,
studentFile2.uniqueFileName,
],
};

const notificationMessage = await db.notificationMessage.findOne({
where: { id: NotificationMessageType.StudentFileUpload },
});

const endpoint = "/students/student/save-uploaded-files";

// Mock user service to return the saved student.
await mockUserLoginInfo(appModule, student);

// Act/Assert
await request(app.getHttpServer())
.patch(endpoint)
.send(payload)
.auth(studentToken, BEARER_AUTH_TYPE)
.expect(HttpStatus.OK);

const updatedStudentFiles = await db.studentFile.find({
select: {
id: true,
modifier: { id: true },
metadata: { applicationNumber: true },
},
where: { id: studentFile1.id },
relations: { modifier: true },
});

updatedStudentFiles.forEach((studentFile) => {
expect(studentFile).toMatchObject({
id: studentFile.id,
modifier: { id: student.user.id },
metadata: {
applicationNumber: application.applicationNumber,
},
});
});

const notification = await db.notification.findOne({
select: {
id: true,
messagePayload: true,
},
where: {
user: { id: student.user.id },
},
});
expect(notification.messagePayload).toEqual({
template_id: notificationMessage.templateId,
email_address: "[email protected]",
personalisation: {
dateTime: expect.any(String),
lastName: student.user.lastName,
birthDate: getDateOnlyFormat(student.birthDate),
fileNames: [studentFile1.fileName, studentFile2.fileName],
givenNames: student.user.firstName,
studentEmail: student.user.email,
documentPurpose: payload.submittedForm.documentPurpose,
applicationNumber: payload.submittedForm.applicationNumber,
},
});
});

afterAll(async () => {
await app?.close();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class StudentUploadFileAPIOutDTO {
export class StudentFileDetailsAPIOutDTO extends StudentUploadFileAPIOutDTO {
metadata: StudentFileMetadataAPIOutDTO;
groupName: string;
updatedAt: Date;
createdAt: Date;
}

export class StudentFileMetadataAPIOutDTO {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ export class StudentControllerService {
groupName: options?.extendedDetails
? studentDocument.groupName
: undefined,
updatedAt: options?.extendedDetails
? studentDocument.updatedAt
createdAt: options?.extendedDetails
? studentDocument.createdAt
: undefined,
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ export class StudentStudentsController extends BaseController {
studentUserToken.studentId,
);

const uploadedFiles = await this.fileService.getStudentFiles(
studentUserToken.studentId,
payload.associatedFiles,
);
const uploadedFileNames = uploadedFiles.map((file) => file.fileName);

// This method will be executed alongside with the transaction during the
// execution of the method updateStudentFiles.
const saveFileUploadNotification = (entityManager: EntityManager) =>
Expand All @@ -311,6 +317,7 @@ export class StudentStudentsController extends BaseController {
documentPurpose: payload.submittedForm.documentPurpose,
applicationNumber: payload.submittedForm.applicationNumber,
userId: student.user.id,
fileNames: uploadedFileNames,
},
studentUserToken.userId,
entityManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export class StudentFileService extends RecordDataModelService<StudentFile> {
})
.select("studentFile.id")
.addSelect("studentFile.uniqueFileName")
.addSelect("studentFile.fileName")
.getMany();
}

Expand Down Expand Up @@ -231,7 +232,7 @@ export class StudentFileService extends RecordDataModelService<StudentFile> {
"studentFile.fileName",
"studentFile.metadata",
"studentFile.groupName",
"studentFile.updatedAt",
"studentFile.createdAt",
"studentFile.fileOrigin",
])
.where("studentFile.student.id = :studentId", { studentId })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class NotificationActionsService {
studentEmail: notification.email,
documentPurpose: notification.documentPurpose,
dateTime: this.getDateTimeOnPSTTimeZone(),
fileNames: notification.fileNames,
},
},
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface StudentFileUploadNotification {
applicationNumber?: string;
documentPurpose: string;
userId: number;
fileNames: string[];
}

export interface MinistryStudentFileUploadNotification {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function createFakeStudentFileUpload(
},
options?: {
fileOrigin?: FileOriginType;
groupName?: string;
},
): StudentFile {
const studentFile = new StudentFile();
Expand All @@ -34,7 +35,7 @@ export function createFakeStudentFileUpload(
faker.datatype.uuid() +
"." +
faker.system.fileType();
studentFile.groupName = "Ministry communications";
studentFile.groupName = options?.groupName ?? "Ministry communications";
studentFile.student = relations?.student ?? createFakeStudent();
studentFile.creator = relations?.creator;
studentFile.fileOrigin = options?.fileOrigin ?? FileOriginType.Ministry;
Expand All @@ -55,7 +56,7 @@ export function createFakeStudentFileUpload(
export async function saveFakeStudentFileUpload(
dataSource: DataSource,
relations?: { student?: Student; creator?: User },
options?: { fileOrigin: FileOriginType },
options?: { fileOrigin: FileOriginType; groupName?: string },
): Promise<StudentFile> {
const studentFile = createFakeStudentFileUpload(relations, options);
const studentFileRepo = dataSource.getRepository(StudentFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
emptyStringFiller(slotProps.data.metadata?.applicationNumber)
}}</template></Column
>
<Column field="updatedAt" header="Date Submitted"
<Column field="createdAt" header="Date Submitted"
><template #body="slotProps">{{
dateOnlyLongString(slotProps.data.updatedAt)
getISODateHourMinuteString(slotProps.data.createdAt)
}}</template></Column
>
<Column field="updatedAt" header="File">
<Column header="File">
<template #body="slotProps">
<div
v-if="canDownloadFiles"
Expand Down Expand Up @@ -138,7 +138,7 @@ export default defineComponent({
setup(props, context) {
const studentFileUploads = ref([] as StudentUploadFileAPIOutDTO[]);
const fileUploadModal = ref({} as ModalDialog<FormIOForm | boolean>);
const { dateOnlyLongString, emptyStringFiller } = useFormatters();
const { getISODateHourMinuteString, emptyStringFiller } = useFormatters();
const fileUtils = useFileUtils();
const initialData = ref({ studentId: props.studentId });
const formioUtils = useFormioUtils();
Expand Down Expand Up @@ -171,7 +171,7 @@ export default defineComponent({
fileUtils,
DEFAULT_PAGE_LIMIT,
PAGINATION_LIST,
dateOnlyLongString,
getISODateHourMinuteString,
emptyStringFiller,
uploadFile,
Role,
Expand Down
2 changes: 1 addition & 1 deletion sources/packages/web/src/services/http/dto/Student.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export interface StudentFileDetailsAPIOutDTO
extends StudentUploadFileAPIOutDTO {
metadata: StudentFileMetadataAPIOutDTO;
groupName: string;
updatedAt: Date;
createdAt: Date;
}

export interface StudentFileMetadataAPIOutDTO {
Expand Down

0 comments on commit c0d1fa4

Please sign in to comment.