Skip to content

Commit

Permalink
fixed staff updation
Browse files Browse the repository at this point in the history
  • Loading branch information
sayeedajmal committed Feb 11, 2024
1 parent 0dac50c commit 1dbdbf0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
29 changes: 13 additions & 16 deletions Web/Position.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,39 @@

<body>
<h1 style="text-align: center;">Staff Position</h1>
<h3 style="text-align: center;" id="responseShow"></h3>

<form id="updateForm" style="font-size: 2.5rem;text-align: center;align-items: center;align-content: center;">

<input type="text" placeholder="position" name="position" /><br />
<input type="checkbox" placeholder="enabled" name="enabled" value="true">Enabled<br>
<input type="text" placeholder="position" id="position" /><br />
<input type="checkbox" placeholder="enabled" id="enabled">Enabled<br>

<button type="reset">Clear</button>
<button type="button" onclick="updateStaffPosition()">Submit</button>
</form>
<h3 style="text-align: center;" id="responseShow"></h3>
</body>
<script>
function updateStaffPosition() {
var responseShow = document.getElementById("responseShow");
var position = document.getElementById('position').value;
var enabled = document.getElementById('enabled').checked;

// Construct the form data as a string
var formDataString = '&position=' + encodeURIComponent(position) + '&enabled=' + (enabled ? 'true' : 'false');

var formData = {
position: document.querySelector('input[name="position"]').value,
enabled: document.querySelector('input[name="enabled"]').checked
};

fetch('http://localhost:8080/api/v1/staff/updateStaffPosition?staffId=3', {
fetch('http://localhost:8080/api/v1/staff/updateStaffPosition?staffId=3' + formDataString, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
}).then(response => response.json())

}).then(response => response.text())
.then(data => {
if (typeof data === 'object') {
responseshow.innerText = JSON.stringify(data);
} else {
responseshow.innerText = data;
}
responseShow.innerText = data;
})
.catch(error => {
responseshow.innerText = 'Error ' + error;
responseShow.innerText = 'Error ' + error;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,12 @@ public ResponseEntity<String> updateStaff(@RequestBody Staff updatedStaff) throw
*/
@Transactional
@PatchMapping("updateStaffPosition")
public ResponseEntity<String> positionStaff(@RequestParam("staffId") Integer staffId,
@RequestParam String position,
@RequestParam Boolean enabled) throws BloodException {
public ResponseEntity<String> positionStaff(@RequestParam("staffId") Integer staffId, String position,
boolean enabled) throws BloodException {
Staff byId = staffService.findById(staffId);

byId.setPosition(position);
byId.setEnabled(enabled);

staffService.updateStaff(byId);
mailService.sendStaffPositionNotification(byId);
return new ResponseEntity<>("Updated Successfully", HttpStatus.OK);
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/strong/BloodDonation/Email/MailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ public void sendStaffWelcomeEmail(Staff staff) {
@Async
public void sendStaffPositionNotification(Staff staff) {
String subject = "Staff Position Update";
String status = staff.isEnabled() ? "Active" : "Deactive";

String htmlContent = "<html><head><style>"
+ "body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background-color: #f5f5f5; }"
+ ".container { background-color: #fff; padding: 20px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); }"
Expand All @@ -275,7 +277,7 @@ public void sendStaffPositionNotification(Staff staff) {
+ "<h4>We're delighted to inform you that you've been assigned the position of <b>" + staff.getPosition()
+ "</b>.</h4>"
+ "<p>Thank you for your dedication and commitment to our team. We believe you'll excel in your new role!</p>"
+ "<h4>Your position has been successfully updated. You are now <b><i>" + staff.isEnabled() + "</i></b>.</h4>"
+ "<h4>Your position has been successfully updated. You are now <b><i>" + status + "</i></b>.</h4>"
+ "<p>Best regards,</p>"
+ "<p>The " + OrganisationName + " Manager</p>"
+ "</div>"
Expand Down Expand Up @@ -303,7 +305,7 @@ public void sendDonationConfirmation(Donation donation) {
+ "<p>We are writing to express our sincere gratitude for your recent blood donation. Your generosity will make a real difference in the lives of others.</p>"
+ "<p>Here are the details of your donation:</p>"
+ "<ul class='blood-details'>"
+ "<li>Date: " + LocalDateTime.now() + "</li>"
+ "<li>Date: " + LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + "</li>"
+ "<li>Location: " + OrganisationLocation + "</li>"
+ "<li>Blood type: " + donation.getDonor().getBloodType() + "</li>"
+ "<li>Amount donated: " + donation.getQuantity() + " ml</li>"
Expand Down Expand Up @@ -335,7 +337,7 @@ public void sendDonationUpdateNotification(Donation donation) {
+ "<p>We're writing to inform you that there has been an update to your recent blood donation.</p>"
+ "<p>Here are the details:</p>"
+ "<ul class='blood-details'>"
+ "<li>Date: " + LocalDateTime.now() + "</li>"
+ "<li>Date: " + LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + "</li>"
+ "<li>Location: " + OrganisationLocation + "</li>"
+ "<li>Blood type: " + donation.getDonor().getBloodType() + "</li>"
+ "<li>Updated Quantity: " + donation.getQuantity() + " ml</li>"
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/strong/BloodDonation/Model/Staff.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Staff {
@Column(nullable = false)
private String staffName;

@Column(nullable = false)
private String position;

@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public JavaMailSender getJavaMailSender() {
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://127.0.0.1:5500")
.allowedMethods("GET", "POST", "PUT", "DELETE");
.allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH");
WebMvcConfigurer.super.addCorsMappings(registry);
}

Expand Down

0 comments on commit 1dbdbf0

Please sign in to comment.