Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1977 - Request Offering Change: Student Application Tracker - Part 1 [Email Notification] #2114

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ import {
getUserFullNameLikeSearch,
transformToApplicationEntitySortField,
} from "@sims/sims-db";
import { Brackets, Repository } from "typeorm";
import { DataSource, Brackets, Repository } from "typeorm";
import { PaginatedResults, PaginationOptions } from "../../utilities";
import { NotificationActionsService, SystemUsersService } from "@sims/services";

@Injectable()
export class ApplicationOfferingChangeRequestService {
constructor(
private readonly dataSource: DataSource,
@InjectRepository(Application)
private readonly applicationRepo: Repository<Application>,
@InjectRepository(ApplicationOfferingChangeRequest)
private readonly applicationOfferingChangeRequestRepo: Repository<ApplicationOfferingChangeRequest>,
private readonly notificationActionsService: NotificationActionsService,
private readonly systemUsersService: SystemUsersService,
) {}

/**
Expand Down Expand Up @@ -81,8 +85,10 @@ export class ApplicationOfferingChangeRequestService {
"offering.studyEndDate",
"offering.offeringIntensity",
"student.id",
"user.id",
"user.firstName",
"user.lastName",
"user.email",
])
.innerJoin("application.programYear", "programYear")
.innerJoin("application.currentAssessment", "currentAssessment")
Expand Down Expand Up @@ -290,7 +296,7 @@ export class ApplicationOfferingChangeRequestService {
}

/**
* Creates a new application offering change request.
* Creates a new application offering change request and saves an offering change request inprogress with student notification message to the database.
* @param locationId location id used for authorization.
* @param applicationId application that will have the change requested.
* @param offeringId offering being requested to be changed.
Expand Down Expand Up @@ -323,7 +329,22 @@ export class ApplicationOfferingChangeRequestService {
newRequest.applicationOfferingChangeRequestStatus =
ApplicationOfferingChangeRequestStatus.InProgressWithStudent;
newRequest.reason = reason;

return this.applicationOfferingChangeRequestRepo.save(newRequest);
return this.dataSource.transaction(async (transactionEntityManager) => {
const applicationOfferingChangeRequest = await transactionEntityManager
.getRepository(ApplicationOfferingChangeRequest)
.save(newRequest);
const systemUser = await this.systemUsersService.systemUser();
await this.notificationActionsService.saveApplicationOfferingChangeRequestInProgressWithStudent(
{
givenNames: application.student.user.firstName,
lastName: application.student.user.lastName,
toAddress: application.student.user.email,
userId: application.student.user.id,
},
systemUser.id,
transactionEntityManager,
);
return applicationOfferingChangeRequest;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { getSQLFileData } from "../utilities/sqlLoader";

export class InsertApplicationOfferingChangeRequestInProgressWithStudentMessage1689361018784
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
getSQLFileData(
"Insert-application-offering-change-request-inprogress-with-student-message.sql",
"NotificationMessages",
),
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
getSQLFileData(
"Delete-application-offering-change-request-inprogress-with-student-message.sql",
"NotificationMessages",
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DELETE FROM
sims.notification_messages
WHERE
ID = 13;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
INSERT INTO
sims.notification_messages(id, description, template_id)
VALUES
(
13,
'Application Offering Change Request In Progress With Student',
'545fe311-7fea-428d-8522-56e12b641b1e'
);
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
StudentNotification,
ECEResponseFileProcessingNotification,
NotificationEmailMessage,
ApplicationOfferingChangeRequestInProgressWithStudentNotification,
} from "..";
import { GCNotifyService } from "./gc-notify.service";
import { NotificationService } from "./notification.service";
Expand Down Expand Up @@ -150,6 +151,42 @@ export class NotificationActionsService {
);
}

/**
* Creates a notification when an Offering Change Request is inprogress with the student.
* @param notification input parameters to generate the notification.
* @param auditUserId user that should be considered the one that is causing the changes.
* @param entityManager optional entity manager to execute in transaction.
*/
async saveApplicationOfferingChangeRequestInProgressWithStudent(
notification: ApplicationOfferingChangeRequestInProgressWithStudentNotification,
auditUserId: number,
entityManager?: EntityManager,
): Promise<void> {
const templateId = await this.notificationMessageService.getTemplateId(
NotificationMessageType.ApplicationOfferingChangeRequestInProgressWithStudent,
);
const messagePayload: NotificationEmailMessage = {
email_address: notification.toAddress,
template_id: templateId,
personalisation: {
givenNames: notification.givenNames ?? "",
lastName: notification.lastName,
},
};
const notificationToSend = {
userId: notification.userId,
messageType:
NotificationMessageType.ApplicationOfferingChangeRequestInProgressWithStudent,
messagePayload: messagePayload,
};
// Save notification into notification table.
await this.notificationService.saveNotifications(
[notificationToSend],
auditUserId,
{ entityManager },
);
}

/**
* Creates a new notification when a new restriction is added to the student account.
* @param notifications notifications information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ export interface MSFAACancellationNotification {
userId: number;
}

export interface ApplicationOfferingChangeRequestInProgressWithStudentNotification {
givenNames: string;
lastName: string;
toAddress: string;
userId: number;
}

export interface StudentRestrictionAddedNotification {
givenNames: string;
lastName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,8 @@ export enum NotificationMessageType {
* MSFAA record gets cancelled.
*/
MSFAACancellation = 12,
/**
* An Application Offering Change Request is in progress with the student.
*/
ApplicationOfferingChangeRequestInProgressWithStudent = 13,
}