Add user and employee management enhancements with database schema updates
- Introduced new columns `status`, `created_by`, and `updated_by` in the `users` table to track user status and ownership. - Updated the `employees` table to include a foreign key reference to the `users` table via `user_id`. - Created migration script `0012_users_primary.sql` to apply these changes to the database schema. - Enhanced the `EmployeesService` and `EmployeesRepository` to support user assignments and related data retrieval. - Updated DTOs and service methods to reflect the new user and employee relationships. - Added unit tests to validate the new functionality and ensure data integrity. - Modified existing controllers to accommodate the new fields and relationships in user and employee management.
This commit is contained in:
@@ -9,8 +9,12 @@ import {
|
||||
IsUUID,
|
||||
Matches,
|
||||
MaxLength,
|
||||
ValidateIf,
|
||||
} from 'class-validator';
|
||||
import { PaginationQueryDto } from '../../../../common/http/response';
|
||||
import {
|
||||
PaginationQueryDto,
|
||||
UserRelationDto,
|
||||
} from '../../../../common/http/response';
|
||||
import { CORE_STATUSES } from '../../../../common/value-objects/status/status';
|
||||
import {
|
||||
EMPLOYEE_CODE_MAX_LENGTH,
|
||||
@@ -55,6 +59,11 @@ export class CreateEmployeeDto {
|
||||
@IsOptional()
|
||||
@IsIn([...CORE_STATUSES])
|
||||
status?: string;
|
||||
|
||||
@ApiPropertyOptional({ format: 'uuid' })
|
||||
@IsOptional()
|
||||
@IsUUID('4')
|
||||
userId?: string;
|
||||
}
|
||||
|
||||
export class UpdateEmployeeDto {
|
||||
@@ -88,6 +97,11 @@ export class UpdateEmployeeDto {
|
||||
@IsOptional()
|
||||
@IsIn([...EMPLOYEE_POSITIONS])
|
||||
position?: string;
|
||||
|
||||
@ApiPropertyOptional({ format: 'uuid', nullable: true })
|
||||
@ValidateIf((_, value) => value !== undefined)
|
||||
@IsUUID('4')
|
||||
userId?: string | null;
|
||||
}
|
||||
|
||||
export class UpdateEmployeeStatusDto {
|
||||
@@ -142,6 +156,11 @@ export class ListEmployeesQueryDto extends PaginationQueryDto {
|
||||
@IsIn([...CORE_STATUSES])
|
||||
status?: string;
|
||||
|
||||
@ApiPropertyOptional({ format: 'uuid' })
|
||||
@IsOptional()
|
||||
@IsUUID('4')
|
||||
userId?: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: 'Case-insensitive match on code or name',
|
||||
})
|
||||
@@ -180,4 +199,7 @@ export class EmployeeDto {
|
||||
|
||||
@ApiProperty({ format: 'uuid' })
|
||||
updatedBy!: string;
|
||||
|
||||
@ApiPropertyOptional({ type: UserRelationDto, nullable: true })
|
||||
user!: UserRelationDto | null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user