Last active
May 30, 2020 04:32
-
-
Save radzserg/20cedc8ec9f0ac0d1683f09849624f91 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class DailyAttendanceReport { | |
| public constructor( | |
| private knex: Knex, | |
| private viewRenderer: ViewRenderer, | |
| private emailTransport: EmailTransport | |
| ) {} | |
| public generate = () => { | |
| const since = moment() | |
| .subtract(1, "days") | |
| .startOf("day"); | |
| const till = moment().startOf("day"); | |
| const report = this.knex("daily_attendance") | |
| .column("DATE(inserted_at)", "COUNT(*)") | |
| .groupByRaw("DATE(inserted_at)") | |
| .where("inserted_at", ">=", since) | |
| .where("inserted_at", "<", till); | |
| const adminEmails = this.knex("users") | |
| .where({ team: "Marketing", role: "ADMIN" }) | |
| .map(admin => admin.email); | |
| const emailBody = this.viewRenderer.render("daily_attendance_report", { | |
| report | |
| }); | |
| adminEmails.forEach(adminEmail => { | |
| this.emailTransport.send( | |
| adminEmail, | |
| "Daily Attendance Report", | |
| emailBody | |
| ); | |
| }); | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment