-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from fdhhhdjd/developer
#159 [Cront - Backend] Run Cron API Student
- Loading branch information
Showing
9 changed files
with
155 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
const cron = require('node-cron'); | ||
const cronCtrl = require('./v1/controllers/cron.controller'); | ||
//! SHARE | ||
const CONSTANTS = require('../share/configs/constants'); | ||
|
||
//! LIBRARY | ||
const cron = require('node-cron'); | ||
|
||
//! MODEL | ||
const cron_verification_student = require('./v1/cron_student/controllers/cron_verification.controller'); | ||
const cron_reset_password_student = require('./v1/cron_student/controllers/cron_reset_password.controller'); | ||
|
||
/** | ||
* @author Nguyễn Tiến Tài | ||
* @created_at 16/12/2022 | ||
* @description Run all Cron | ||
* @updated_at 28/02/2022 | ||
* @description Run Cron delete verification | ||
*/ | ||
|
||
cron.schedule(CONSTANTS._5_SECONDS_CRON, () => { | ||
cronCtrl.cron_demo(); | ||
// Delete verification | ||
cron_verification_student.cron_deleted_verification_student(); | ||
|
||
// Delete reset password | ||
cron_reset_password_student.cron_deleted_reset_password_student(); | ||
}); | ||
console.info('Server cron running !!!'); |
18 changes: 0 additions & 18 deletions
18
backend-manager-student/src/cron_job/v1/controllers/cron.controller.js
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
...anager-student/src/cron_job/v1/cron_student/controllers/cron_reset_password.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//! Share | ||
const HELPER = require('../../../../share/utils/helper'); | ||
const CONSTANTS = require('../../../../share/configs/constants'); | ||
|
||
//! Model | ||
const user_reset_password_model = require('../../../../share/models/user_reset_password.model'); | ||
|
||
module.exports = { | ||
/** | ||
* @author Nguyễn Tiến Tài | ||
* @created_at 28/02/2022 | ||
* @description cron_deleted_reset_password_student | ||
* @function cron_deleted_reset_password_student | ||
*/ | ||
async cron_deleted_reset_password_student() { | ||
try { | ||
// Get all table reset_password | ||
const resetPasswordList = await user_reset_password_model.getResetPasswordList(); | ||
|
||
// Verification exit data | ||
if (resetPasswordList.length > 0) { | ||
// Repeat every data | ||
for (const resetPassword of resetPasswordList) { | ||
// Check data is expired | ||
const isExpired = HELPER.isExpired(resetPassword.reset_password_expire); | ||
|
||
// If expired delete | ||
if (isExpired !== CONSTANTS.DELETED_DISABLE) { | ||
await user_reset_password_model.updateResetPassword( | ||
{ isdeleted: CONSTANTS.DELETED_ENABLE }, | ||
{ id: resetPassword.id }, | ||
{ id: 'id' }, | ||
); | ||
} | ||
} | ||
|
||
console.info('CRON DELETE RESET PASSWORD DONE !'); | ||
} else { | ||
console.error('NO LIST RESET PASSWORD!!!'); | ||
} | ||
} catch (error) { | ||
console.error('UPDATE FAIL!', error); | ||
} | ||
}, | ||
}; |
46 changes: 46 additions & 0 deletions
46
...-manager-student/src/cron_job/v1/cron_student/controllers/cron_verification.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//! Share | ||
const HELPER = require('../../../../share/utils/helper'); | ||
const CONSTANTS = require('../../../../share/configs/constants'); | ||
|
||
//! Model | ||
const user_verification_model = require('../../../../share/models/user_verification.model'); | ||
|
||
module.exports = { | ||
/** | ||
* @author Nguyễn Tiến Tài | ||
* @created_at 16/12/2022 | ||
* @updated_at 28/02/2022 | ||
* @description cron_deleted_verification_student | ||
* @function cron_deleted_verification_student | ||
*/ | ||
async cron_deleted_verification_student() { | ||
try { | ||
// Get all table verification | ||
const verificationList = await user_verification_model.getVerificationList(); | ||
|
||
// Verification exit data | ||
if (verificationList.length > 0) { | ||
// Repeat every data | ||
for (const verification of verificationList) { | ||
// Check data is expired | ||
const isExpired = HELPER.isExpired(verification.linkEmailExpire); | ||
|
||
// If expired delete | ||
if (isExpired !== CONSTANTS.DELETED_DISABLE) { | ||
await user_verification_model.updateVerification( | ||
{ isdeleted: CONSTANTS.DELETED_ENABLE }, | ||
{ verify_id: verification.verify_id }, | ||
{ verify_id: 'verify_id' }, | ||
); | ||
} | ||
} | ||
|
||
console.info('CRON DELETE VERIFICATION DONE !'); | ||
} else { | ||
console.error('NO LIST VERIFICATION!!!'); | ||
} | ||
} catch (error) { | ||
console.error('UPDATE FAIL!', error); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
backend-manager-student/src/user_api/v1/controllers/user.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters