-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5127ea0
commit fc613ce
Showing
1 changed file
with
63 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { AttendanceDao } from '../dao/attendance.dao'; | ||
import {handleError} from '../models/Error'; | ||
export class AttendanceService { | ||
static createAttendance = async(req)=>{ | ||
const {username, realname, date, state} = req.body; | ||
try{ | ||
const result = AttendanceDao.createAttendance(username,realname,state,date); | ||
return result; | ||
}catch(err){ | ||
console.log(err); | ||
throw new handleError(404,'Create Attendance fail'); | ||
} | ||
}; | ||
|
||
static deleteAttendances = async(req)=>{ | ||
const {startDate,endDate} = req.query; | ||
try{ | ||
const result = await AttendanceDao.deleteAttendances(startDate,endDate); | ||
if(result.ok == 0){ | ||
throw new handleError(404,'Attendance not found'); | ||
} | ||
return result; | ||
}catch(err){ | ||
console.log(err); | ||
throw new handleError(404,'Delete Attendance fail'); | ||
} | ||
} | ||
|
||
static getAttendanceByDate = async(req)=>{ | ||
const {date} = req.params; | ||
try{ | ||
const result = await AttendanceDao.getAttendanceByDate(date); | ||
return result; | ||
}catch(err){ | ||
console.log(err); | ||
throw new handleError(404,'Attendance not found'); | ||
} | ||
} | ||
|
||
static getAttendanceByPeriod = async(req)=>{ | ||
const {username} = req.params; | ||
const {startDate,endDate} = req.query; | ||
try{ | ||
const result = await AttendanceDao.getAttendanceByPeriod(username,startDate,endDate); | ||
return result; | ||
}catch(err){ | ||
console.log(err); | ||
throw new handleError(404,'Attendance not found'); | ||
} | ||
} | ||
|
||
static updateAttendance = async(req)=>{ | ||
const {username,date} = req.params; | ||
const {state} = req.body; | ||
try{ | ||
const result = await AttendanceDao.updateAttendance(username,date,state); | ||
return result; | ||
}catch(err){ | ||
console.log(err); | ||
throw new handleError(404,'Attendance not found'); | ||
} | ||
} | ||
} |