fixing absensi
This commit is contained in:
@@ -36,18 +36,21 @@ const create = async (req, res) => {
|
|||||||
|
|
||||||
|
|
||||||
const user = await User.findOne({ where: { id: user_id } });
|
const user = await User.findOne({ where: { id: user_id } });
|
||||||
if (!user) return response.failed(res, 404, 'User tidak ditemukan');
|
if (!user) {
|
||||||
|
await t.rollback()
|
||||||
|
return response.failed(res, 404, 'User tidak ditemukan');
|
||||||
|
}
|
||||||
|
|
||||||
const branch = await Branch.findOne({ where: { id: user.branch_id } });
|
const branch = await Branch.findOne({ where: { id: user.branch_id } });
|
||||||
if (!branch) return response.failed(res, 404, 'Branch kantor tidak ditemukan');
|
if (!branch) {
|
||||||
|
await t.rollback()
|
||||||
|
return response.failed(res, 404, 'Branch kantor tidak ditemukan');
|
||||||
|
}
|
||||||
|
|
||||||
let attendance = await Attedances.findOne({
|
let attendance = await Attedances.findOne({
|
||||||
where: { user_id, date: today },
|
where: { user_id, date: today },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (attendance && ['sick', 'permission'].includes(attendance.type)) {
|
|
||||||
return response.failed(res, 400, `Hari ini Anda sudah absen ${attendance.type}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// === Jika izin (sakit / izin) ===
|
// === Jika izin (sakit / izin) ===
|
||||||
if (['sick', 'permission'].includes(type)) {
|
if (['sick', 'permission'].includes(type)) {
|
||||||
@@ -65,6 +68,10 @@ const create = async (req, res) => {
|
|||||||
await t.commit();
|
await t.commit();
|
||||||
return response.success(res, attendance, 'Izin berhasil disimpan');
|
return response.success(res, attendance, 'Izin berhasil disimpan');
|
||||||
}
|
}
|
||||||
|
if (attendance && ['sick', 'permission'].includes(attendance.type)) {
|
||||||
|
await t.rollback()
|
||||||
|
return response.failed(res, 400, `Hari ini Anda sudah absen ${attendance.type}`);
|
||||||
|
}
|
||||||
|
|
||||||
if (attendance && attendance.clock_in) {
|
if (attendance && attendance.clock_in) {
|
||||||
// 🕛 Jika branch tidak mengaktifkan absen siang
|
// 🕛 Jika branch tidak mengaktifkan absen siang
|
||||||
|
|||||||
Reference in New Issue
Block a user