Skip to content

Commit

Permalink
EDX-1859 - converts all edx date pickers to standardized one
Browse files Browse the repository at this point in the history
  • Loading branch information
mightycox committed Oct 11, 2023
1 parent f70d2ad commit ea55ebf
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 569 deletions.
2 changes: 1 addition & 1 deletion backend/src/components/edx/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ const createSearchParamObject = (key, value) => {
valueType = VALUE_TYPE.UUID;
} else if (key === 'createDate') {
value.forEach((date, index) => {
value[index] = date + 'T00:00:00';
value[index] = date;
});
if (value.length === 1) {
value.push(LocalDateTime.parse(value[0]).plusHours(23).plusMinutes(59).plusSeconds(59));
Expand Down
48 changes: 16 additions & 32 deletions backend/src/components/institute/institute.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ async function getDistricts(req, res) {
async function addDistrictContact(req, res) {
try {
const token = getBackendToken(req);
const formatter = DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss');

let district = cacheService.getDistrictJSONByDistrictId(req.body.districtID);
if(!district || !hasDistrictAdminRole(req)){
Expand All @@ -85,8 +84,8 @@ async function addDistrictContact(req, res) {
phoneExtension: req.body.phoneExtension,
alternatePhoneNumber: req.body.alternatePhoneNumber,
alternatePhoneExtension: req.body.alternatePhoneExtension,
effectiveDate: req.body.effectiveDate ? LocalDate.parse(req.body.effectiveDate).atStartOfDay().format(formatter) : null,
expiryDate: req.body.expiryDate ? LocalDate.parse(req.body.expiryDate).atStartOfDay().format(formatter) : null
effectiveDate: req.body.effectiveDate ? req.body.effectiveDate : null,
expiryDate: req.body.expiryDate ? req.body.expiryDate : null
};

const data = await utils.postData(token, url, payload, null, utils.getUser(req).idir_username);
Expand Down Expand Up @@ -166,7 +165,6 @@ async function updateDistrict(req, res) {
async function updateDistrictContact(req, res) {
try {
const token = getBackendToken(req);
const formatter = DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss');

let district = cacheService.getDistrictJSONByDistrictId(req.body.districtId);
if(!district || !hasDistrictAdminRole(req)){
Expand All @@ -185,8 +183,6 @@ async function updateDistrictContact(req, res) {
params.updateDate = null;
params.createDate = null;
params.updateUser = utils.getUser(req).idir_username;
params.effectiveDate = params.effectiveDate ? LocalDate.parse(req.body.effectiveDate).atStartOfDay().format(formatter) : null;
params.expiryDate = req.body.expiryDate ? LocalDate.parse(req.body.expiryDate).atStartOfDay().format(formatter) : null;

const result = await utils.putData(token, `${config.get('server:institute:instituteDistrictURL')}/${req.body.districtId}/contact/${req.params.contactId}` , params, utils.getUser(req).idir_username);
return res.status(HttpStatus.OK).json(result);
Expand All @@ -199,7 +195,6 @@ async function updateDistrictContact(req, res) {
async function deleteDistrictContact(req, res) {
try {
const token = getBackendToken(req);
const formatter = DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss');

let district = cacheService.getDistrictJSONByDistrictId(req.params.districtId);
if(!district || !hasDistrictAdminRole(req)){
Expand All @@ -225,7 +220,7 @@ async function deleteDistrictContact(req, res) {
contact.createDate = null;
contact.updateDate = null;
contact.updateUser = utils.getUser(req).idir_username;
contact.expiryDate = LocalDateTime.now().format(formatter);
contact.expiryDate = LocalDate.now().atStartOfDay().format(DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss'));

await utils.putData(token, config.get('server:institute:instituteDistrictURL') + '/' + req.params.districtId + '/contact/'+ req.params.contactId , contact, utils.getUser(req).idir_username);

Expand Down Expand Up @@ -347,8 +342,6 @@ async function addSchool(req, res) {
});
}

const formatter = DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss');

const payload = {
createUser: utils.getUser(req).idir_username,
createDate: null,
Expand All @@ -366,7 +359,7 @@ async function addSchool(req, res) {
schoolOrganizationCode: req.body.schoolOrganizationCode,
schoolCategoryCode: req.body.schoolCategoryCode,
facilityTypeCode: req.body.facilityTypeCode,
openedDate: req.body.openedDate ? LocalDate.parse(req.body.openedDate).atStartOfDay().format(formatter) : null,
openedDate: req.body.openedDate ? req.body.openedDate : null,
closedDate: null,
addresses: [],
grades: [],
Expand Down Expand Up @@ -496,7 +489,6 @@ async function deleteSchoolNote(req, res) {
async function addSchoolContact(req, res) {
try {
const token = getBackendToken(req);
const formatter = DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss');

let school = cacheService.getSchoolBySchoolID(req.body.schoolID);
if(!school || !hasSchoolAdminRole(req, school)){
Expand All @@ -523,8 +515,8 @@ async function addSchoolContact(req, res) {
phoneExtension: req.body.phoneExtension,
alternatePhoneNumber: req.body.alternatePhoneNumber,
alternatePhoneExtension: req.body.alternatePhoneExtension,
effectiveDate: req.body.effectiveDate ? LocalDate.parse(req.body.effectiveDate).atStartOfDay().format(formatter) : null,
expiryDate: req.body.expiryDate ? LocalDate.parse(req.body.expiryDate).atStartOfDay().format(formatter) : null
effectiveDate: req.body.effectiveDate ? req.body.effectiveDate : null,
expiryDate: req.body.expiryDate ? req.body.expiryDate : null
};

const data = await utils.postData(token, url, payload, null, utils.getUser(req).idir_username);
Expand All @@ -539,7 +531,6 @@ async function addSchoolContact(req, res) {
async function updateSchoolContact(req, res) {
try {
const token = getBackendToken(req);
const formatter = DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss');

let school = cacheService.getSchoolBySchoolID(req.body.schoolID);
if(!school || !hasSchoolAdminRole(req, school)){
Expand All @@ -558,8 +549,9 @@ async function updateSchoolContact(req, res) {
params.updateDate = null;
params.createDate = null;
params.updateUser = utils.getUser(req).idir_username;
params.effectiveDate = params.effectiveDate ? LocalDate.parse(req.body.effectiveDate).atStartOfDay().format(formatter) : null;
params.expiryDate = req.body.expiryDate ? LocalDate.parse(req.body.expiryDate).atStartOfDay().format(formatter) : null;
params.effectiveDate = params.effectiveDate ? req.body.effectiveDate : null;
params.expiryDate = req.body.expiryDate ? req.body.expiryDate : null;
params.expiryDate = req.body.expiryDate ? req.body.expiryDate : null;

const result = await utils.putData(token, config.get('server:institute:instituteSchoolURL') + '/' + req.body.schoolID + '/contact/'+ req.params.contactId , params, utils.getUser(req).idir_username);
return res.status(HttpStatus.OK).json(result);
Expand All @@ -572,7 +564,6 @@ async function updateSchoolContact(req, res) {
async function deleteSchoolContact(req, res) {
try {
const token = getBackendToken(req);
const formatter = DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss');

let school = cacheService.getSchoolBySchoolID(req.params.schoolId);
if(!school || !hasSchoolAdminRole(req, school)){
Expand All @@ -598,7 +589,7 @@ async function deleteSchoolContact(req, res) {
contact.createDate = null;
contact.updateDate = null;
contact.updateUser = utils.getUser(req).idir_username;
contact.expiryDate = LocalDateTime.now().format(formatter);
contact.expiryDate = LocalDate.now().atStartOfDay().format(DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss'));

await utils.putData(token, config.get('server:institute:instituteSchoolURL') + '/' + req.params.schoolId + '/contact/'+ req.params.contactId , contact, utils.getUser(req).idir_username);

Expand All @@ -612,7 +603,6 @@ async function deleteSchoolContact(req, res) {
async function addAuthorityContact(req, res) {
try {
const token = getBackendToken(req);
const formatter = DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss');

let authority = cacheService.getAuthorityJSONByAuthorityId(req.body.authorityID);
if(!authority || !hasAuthorityAdminRole(req, authority)){
Expand All @@ -639,8 +629,8 @@ async function addAuthorityContact(req, res) {
phoneExtension: req.body.phoneExtension,
alternatePhoneNumber: req.body.alternatePhoneNumber,
alternatePhoneExtension: req.body.alternatePhoneExtension,
effectiveDate: req.body.effectiveDate ? LocalDate.parse(req.body.effectiveDate).atStartOfDay().format(formatter) : null,
expiryDate: req.body.expiryDate ? LocalDate.parse(req.body.expiryDate).atStartOfDay().format(formatter) : null
effectiveDate: req.body.effectiveDate ? req.body.effectiveDate : null,
expiryDate: req.body.expiryDate ? req.body.expiryDate : null
};

const data = await utils.postData(token, url, payload, null, utils.getUser(req).idir_username);
Expand All @@ -655,7 +645,6 @@ async function addAuthorityContact(req, res) {
async function updateAuthorityContact(req, res) {
try {
const token = getBackendToken(req);
const formatter = DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss');

let authority = cacheService.getAuthorityJSONByAuthorityId(req.body.independentAuthorityId);
if(!authority || !hasAuthorityAdminRole(req, authority)){
Expand All @@ -674,8 +663,6 @@ async function updateAuthorityContact(req, res) {
params.updateDate = null;
params.createDate = null;
params.updateUser = utils.getUser(req).idir_username;
params.effectiveDate = params.effectiveDate ? LocalDate.parse(req.body.effectiveDate).atStartOfDay().format(formatter) : null;
params.expiryDate = req.body.expiryDate ? LocalDate.parse(req.body.expiryDate).atStartOfDay().format(formatter) : null;

const result = await utils.putData(token, config.get('server:institute:instituteAuthorityURL') + '/' + req.body.independentAuthorityId + '/contact/'+ req.params.contactId , params, utils.getUser(req).idir_username);
return res.status(HttpStatus.OK).json(result);
Expand All @@ -688,7 +675,6 @@ async function updateAuthorityContact(req, res) {
async function deleteAuthorityContact(req, res) {
try {
const token = getBackendToken(req);
const formatter = DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss');

let authority = cacheService.getAuthorityJSONByAuthorityId(req.params.independentAuthorityId);
if(!authority || !hasAuthorityAdminRole(req, authority)){
Expand All @@ -714,7 +700,7 @@ async function deleteAuthorityContact(req, res) {
contact.createDate = null;
contact.updateDate = null;
contact.updateUser = utils.getUser(req).idir_username;
contact.expiryDate = LocalDateTime.now().format(formatter);
contact.expiryDate = LocalDate.now().atStartOfDay().format(DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss'));

await utils.putData(token, config.get('server:institute:instituteAuthorityURL') + '/' + req.params.independentAuthorityId + '/contact/'+ req.params.contactId , contact, utils.getUser(req).idir_username);

Expand All @@ -728,7 +714,6 @@ async function deleteAuthorityContact(req, res) {
async function addAuthority(req, res) {
try {
const token = getBackendToken(req);
const formatter = DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss');

if(!hasAuthorityAdminRole(req)){
return res.status(HttpStatus.UNAUTHORIZED).json({
Expand All @@ -742,7 +727,7 @@ async function addAuthority(req, res) {

displayName: req.body.authorityName,
authorityTypeCode: req.body.authorityTypeCode,
openedDate: req.body.openDate ? LocalDate.parse(req.body.openDate).atStartOfDay().format(formatter) : null,
openedDate: req.body.openDate ? req.body.openDate : null,
email: req.body.email,
phoneNumber: req.body.phoneNumber,
faxNumber: req.body.faxNumber,
Expand Down Expand Up @@ -991,7 +976,6 @@ async function getSchoolsPaginated(req, res){
async function moveSchool(req, res) {
try {
const token = getBackendToken(req);
const formatter = DateTimeFormatter.ofPattern('yyyy-MM-dd\'T\'HH:mm:ss');

if(!hasSchoolAdminRole(req, req.body.toSchool)){
return res.status(HttpStatus.UNAUTHORIZED).json({
Expand All @@ -1000,7 +984,7 @@ async function moveSchool(req, res) {
}

const incomingPayload = req.body;
incomingPayload.toSchool.openedDate = LocalDate.parse(incomingPayload.toSchool.moveDate).atStartOfDay().format(formatter);
incomingPayload.toSchool.openedDate = incomingPayload.toSchool.moveDate;
incomingPayload.toSchool.createDate = null;
incomingPayload.toSchool.updateDate = null;
incomingPayload.toSchool.createUser = utils.getUser(req).idir_username;
Expand Down Expand Up @@ -1055,7 +1039,7 @@ async function moveSchool(req, res) {

const payload = {
toSchool: incomingPayload.toSchool,
moveDate: LocalDate.parse(incomingPayload.toSchool.moveDate).atStartOfDay().format(formatter),
moveDate: incomingPayload.toSchool.moveDate,
fromSchoolId: req.body.fromSchoolId
};

Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@fortawesome/fontawesome-free": "6.4.0",
"@js-joda/core": "^5.5.3",
"@mdi/font": "^7.2.96",
"@vuepic/vue-datepicker": "^7.0.0",
"axios": "^1.4.0",
"chart.js": "^4.3.0",
"chartjs-plugin-datalabels": "^2.2.0",
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/institute/AuthorityDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,8 @@
:date-of-last-school-closure="closedDateOfLastClosingSchool"
:list-of-open-schools="listOfOpenSchools"
:list-of-closing-schools="listOfClosingSchools"
@updateAuthorityDates="handleUpdatesToAuthorityStatus"
@authorityStatus:closeEditAuthorityStatusPage="openAuthorityStatusEditCard = !openAuthorityStatusEditCard"
@update-authority-dates="handleUpdatesToAuthorityStatus"
@authority-status:close-edit-authority-status-page="openAuthorityStatusEditCard = !openAuthorityStatusEditCard"
/>
</v-dialog>
</v-form>
Expand Down Expand Up @@ -961,7 +961,7 @@ export default {
}
}).then(response => {
this.listOfClosingSchools = response.data.content;
this.closedDateOfLastClosingSchool = response.data.content[0] ? response.data.content[0].closedDate.substring(0, 10) : null;
this.closedDateOfLastClosingSchool = response.data.content[0] ? response.data.content[0].closedDate : null;
}).catch(error => {
console.error(error);
this.setFailureAlert(error?.response?.data?.message ? error?.response?.data?.message : 'An error occurred while trying to find the closed date of the last closing school. Please try again later.');
Expand Down Expand Up @@ -1107,12 +1107,12 @@ export default {
async handleUpdatesToAuthorityStatus(updatedDatesForAuthority) {
await this.$nextTick();
if (updatedDatesForAuthority.openedDate) {
this.authorityCopy.openedDate = updatedDatesForAuthority.openedDate?.replaceAll('/', '-').concat('T00:00:00');
this.authorityCopy.openedDate = updatedDatesForAuthority.openedDate;
} else {
this.authorityCopy.openedDate = null;
}
if (updatedDatesForAuthority.closedDate) {
this.authorityCopy.closedDate = updatedDatesForAuthority.closedDate?.replaceAll('/', '-').concat('T00:00:00');
this.authorityCopy.closedDate = updatedDatesForAuthority.closedDate;
} else {
this.authorityCopy.closedDate = null;
}
Expand Down
Loading

0 comments on commit ea55ebf

Please sign in to comment.