Skip to content

Instantly share code, notes, and snippets.

@radzserg
Last active May 30, 2020 04:32
Show Gist options
  • Select an option

  • Save radzserg/20cedc8ec9f0ac0d1683f09849624f91 to your computer and use it in GitHub Desktop.

Select an option

Save radzserg/20cedc8ec9f0ac0d1683f09849624f91 to your computer and use it in GitHub Desktop.
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