-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReportHandler.js
More file actions
48 lines (38 loc) · 1.64 KB
/
ReportHandler.js
File metadata and controls
48 lines (38 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const ReportsDataBaseHandler = require('./ReportsDataBaseHandler')
const db_password = require('./dbpswd')
class ReportHandler {
constructor() {
this.reportsDbHandler = new ReportsDataBaseHandler({
user: 'fqhdvfjibpslvq',
host: 'ec2-52-86-177-34.compute-1.amazonaws.com',
database: 'd591fltfo2mqg4',
password: process.env.DATABASE_PASSWORD || db_password,
port: 5432,
ssl: {
rejectUnauthorized: false
}
})
}
async deleteReport(reportId) {
// Deletes the report with id 'reportId' from the database.
return await this.reportsDbHandler.deleteReport(reportId)
}
async saveReport(employeeId, taskId,
date, hours, minutes, description) {
// Saves a new report into the database with:
// 'date' parameter as a string in the following format: 'yyyy/mm/dd'.
// 'hours' parameter being an integer indicating the entire hours dedicated to the task.
// 'minutes' parameter being an integer indicating the extra minutes dedicated to the task
// out of entire hours.
if (new Date() < new Date(date)) {
return { status: 400 }
}
return await this.reportsDbHandler.saveReport(employeeId, taskId,
date, parseInt(hours) * 60 + parseInt(minutes), description)
}
async updateReport(reportId, hours, minutes) {
// Updates the time destined to report with id 'reportId' in the database.
return await this.reportsDbHandler.updateReport(reportId, hours * 60 + minutes)
}
}
module.exports = ReportHandler