- Introduced new `attendances` and `visits` tables to manage employee attendance and customer visits, including relevant fields for check-in and check-out details. - Updated `company_settings` to include a `check_in_radius_meters` column for attendance validation. - Implemented foreign key constraints to ensure data integrity between `attendances`, `visits`, `employees`, `branches`, and other related entities. - Created new services and controllers for handling attendance and visit operations, including check-in, check-out, and bulk actions. - Enhanced DTOs for attendance and visit data transfer, including validation for input data. - Added unit and integration tests to validate the new functionalities and ensure proper handling of attendance and visit records. - Created migration scripts to apply the necessary database schema changes for the new features.
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { sql } from 'drizzle-orm';
|
|
import { bigint, index, pgTable, uniqueIndex, uuid } from 'drizzle-orm/pg-core';
|
|
import { branches } from './branches-table';
|
|
import { checkInColumns, checkOutColumns } from './checkpoint-columns';
|
|
import { employees } from './employees-table';
|
|
import { primaryEntityColumns } from './primary-entity-columns';
|
|
import { users } from './schema';
|
|
|
|
export const attendances = pgTable(
|
|
'attendances',
|
|
{
|
|
id: uuid('id').defaultRandom().notNull().primaryKey(),
|
|
employeeId: uuid('employee_id')
|
|
.notNull()
|
|
.references(() => employees.id, { onDelete: 'restrict' }),
|
|
branchId: uuid('branch_id')
|
|
.notNull()
|
|
.references(() => branches.id, { onDelete: 'restrict' }),
|
|
date: bigint('date', { mode: 'number' }).notNull(),
|
|
...checkInColumns,
|
|
...checkOutColumns,
|
|
...primaryEntityColumns(users),
|
|
},
|
|
(t) => [
|
|
uniqueIndex('attendances_employee_date_live_unique')
|
|
.on(t.employeeId, t.date)
|
|
.where(sql`${t.status} <> 'archived'`),
|
|
uniqueIndex('attendances_employee_open_unique')
|
|
.on(t.employeeId)
|
|
.where(sql`${t.checkOutAt} IS NULL AND ${t.status} <> 'archived'`),
|
|
index('attendances_employee_id_idx').on(t.employeeId),
|
|
index('attendances_branch_id_idx').on(t.branchId),
|
|
],
|
|
);
|
|
|
|
export type AttendanceRow = typeof attendances.$inferSelect;
|
|
export type NewAttendanceRow = typeof attendances.$inferInsert;
|