Skip to content

Commit

Permalink
fix: quick refactor for soft removal entities
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-rocket committed Oct 5, 2024
1 parent 611f6f2 commit 423a8ca
Show file tree
Hide file tree
Showing 20 changed files with 234 additions and 213 deletions.
59 changes: 38 additions & 21 deletions packages/core/src/shared/dto/filters-query.dto.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
import { ApiPropertyOptional } from "@nestjs/swagger";
import { IsEnum, IsOptional } from "class-validator";
import { ITimeLogFilters, TimeLogSourceEnum, TimeLogType } from "@gauzy/contracts";
import { IsBetweenActivty } from "./../../shared/validators";
import { ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsEnum, IsOptional } from 'class-validator';
import { ITimeLogFilters, TimeLogSourceEnum, TimeLogType } from '@gauzy/contracts';
import { IsBetweenActivty } from './../../shared/validators';

Check warning on line 5 in packages/core/src/shared/dto/filters-query.dto.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Activty)

/**
* Get filters common request DTO validation
* Data Transfer Object for filtering time logs based on source, log type, and activity level.
* This DTO provides optional filters to refine time log queries.
*/
export class FiltersQueryDTO implements ITimeLogFilters {
/**
* Filters time logs by their source.
* Can include multiple sources like Desktop, Web, or Mobile.
* If not provided, no filtering by source will be applied.
*/
@ApiPropertyOptional({ enum: TimeLogSourceEnum })
@IsOptional()
@IsEnum(TimeLogSourceEnum, { each: true })
source: TimeLogSourceEnum[];

@ApiPropertyOptional({ enum: TimeLogSourceEnum })
@IsOptional()
@IsEnum(TimeLogSourceEnum, { each: true })
readonly source: TimeLogSourceEnum[];
/**
* Filters time logs by their log type (Manual, Tracked, etc.).
* Multiple log types can be specified.
* If not provided, no filtering by log type will be applied.
*/
@ApiPropertyOptional({ enum: TimeLogType })
@IsOptional()
@IsEnum(TimeLogType, { each: true })
logType: TimeLogType[];

@ApiPropertyOptional({ enum: TimeLogType })
@IsOptional()
@IsEnum(TimeLogType, { each: true })
readonly logType: TimeLogType[];

@ApiPropertyOptional({ type: () => 'object' })
@IsOptional()
@IsBetweenActivty(FiltersQueryDTO, (it) => it.activityLevel)
readonly activityLevel: {
start: number;
end: number;
};
/**
* Filters time logs by activity level, specifying a range between `start` and `end`.
* This filter limits logs to a specific activity range (e.g., from 10% to 90% activity).
* If not provided, no filtering by activity level will be applied.
*/
@ApiPropertyOptional({ type: () => Object })
@IsOptional()
@IsBetweenActivty(FiltersQueryDTO, (it) => it.activityLevel)

Check warning on line 39 in packages/core/src/shared/dto/filters-query.dto.ts

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Activty)
@Type(() => Object)
activityLevel: {
start: number;
end: number;
};
}
19 changes: 9 additions & 10 deletions packages/core/src/shared/dto/relations-query.dto.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { ApiPropertyOptional } from "@nestjs/swagger";
import { Transform, TransformFnParams } from "class-transformer";
import { IsArray, IsOptional } from "class-validator";
import { IBaseRelationsEntityModel } from "@gauzy/contracts";
import { ApiPropertyOptional } from '@nestjs/swagger';
import { Transform, TransformFnParams } from 'class-transformer';
import { IsArray, IsOptional } from 'class-validator';
import { IBaseRelationsEntityModel } from '@gauzy/contracts';

/**
* Get relations request DTO validation
*/
export class RelationsQueryDTO implements IBaseRelationsEntityModel {

@ApiPropertyOptional({ type: () => Array, isArray: true })
@IsOptional()
@IsArray()
@Transform(({ value }: TransformFnParams) => (value) ? value.map((element: string) => element.trim()) : [])
readonly relations: string[] = [];
@ApiPropertyOptional({ type: () => Array, isArray: true })
@IsOptional()
@IsArray()
@Transform(({ value }: TransformFnParams) => (value ? value.map((element: string) => element.trim()) : []))
readonly relations: string[] = [];
}
59 changes: 29 additions & 30 deletions packages/core/src/shared/dto/selectors-query.dto.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsOptional, IsArray } from 'class-validator';
import { ITimeLogFilters } from '@gauzy/contracts';
import { ID, ITimeLogFilters } from '@gauzy/contracts';
import { DateRangeQueryDTO } from './date-range-query.dto';

/**
* Get selectors common request DTO validation.
* Extends DateRangeQueryDTO to include date range filters.
*/
export class SelectorsQueryDTO extends DateRangeQueryDTO implements ITimeLogFilters {
/**
* An array of employee IDs for filtering time logs.
*/
@ApiPropertyOptional({ type: () => Array, isArray: true })
@IsOptional()
@IsArray()
employeeIds: ID[];

/**
* An array of employee IDs for filtering time logs.
*/
@ApiPropertyOptional({ type: () => Array, isArray: true })
@IsOptional()
@IsArray()
readonly employeeIds: string[];
/**
* An array of project IDs for filtering time logs.
*/
@ApiPropertyOptional({ type: () => Array, isArray: true })
@IsOptional()
@IsArray()
projectIds: ID[];

/**
* An array of project IDs for filtering time logs.
*/
@ApiPropertyOptional({ type: () => Array, isArray: true })
@IsOptional()
@IsArray()
readonly projectIds: string[];
/**
* An array of task IDs for filtering time logs.
*/
@ApiPropertyOptional({ type: () => Array, isArray: true })
@IsOptional()
@IsArray()
taskIds: ID[];

/**
* An array of task IDs for filtering time logs.
*/
@ApiPropertyOptional({ type: () => Array, isArray: true })
@IsOptional()
@IsArray()
readonly taskIds: string[];

/**
* An array of team IDs for filtering time logs.
*/
@ApiPropertyOptional({ type: () => Array, isArray: true })
@IsOptional()
@IsArray()
readonly teamIds: string[];
/**
* An array of team IDs for filtering time logs.
*/
@ApiPropertyOptional({ type: () => Array, isArray: true })
@IsOptional()
@IsArray()
teamIds: ID[];
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ArrayNotEmpty, IsBoolean, IsOptional } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { ArrayNotEmpty } from 'class-validator';
import { ID, IDeleteTimeLog } from '@gauzy/contracts';
import { DeleteQueryDTO } from '../../../shared/dto';
import { ForceDeleteDTO } from '../../dto/force-delete.dto';
import { TimeLog } from '../time-log.entity';

/**
Expand All @@ -13,22 +13,12 @@ import { TimeLog } from '../time-log.entity';
* that must not be empty and an optional `forceDelete` flag to determine
* whether a hard or soft delete should be performed.
*/
export class DeleteTimeLogDTO extends DeleteQueryDTO<TimeLog> implements IDeleteTimeLog {
export class DeleteTimeLogDTO extends ForceDeleteDTO<TimeLog> implements IDeleteTimeLog {
/**
* An array of time log IDs that need to be deleted.
* This field is required and must contain at least one ID.
*/
@ApiProperty({ type: () => Array })
@ArrayNotEmpty()
readonly logIds: ID[] = [];

/**
* A flag to determine whether to force delete the time logs.
* If `true`, a hard delete will be performed; otherwise, a soft delete is used.
* This field is optional and defaults to `false`.
*/
@ApiPropertyOptional({ type: () => Boolean })
@IsOptional()
@IsBoolean()
readonly forceDelete: boolean = false;
}
2 changes: 1 addition & 1 deletion packages/core/src/time-tracking/time-log/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './create-time-log.dto';
export * from './delete-time-log.dto';
export * from './update-time-log.dto';
export * from './create-time-log.dto';
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { CommandBus } from '@nestjs/cqrs';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { DeleteResult, FindOneOptions, UpdateResult } from 'typeorm';
import { ITimeLog, PermissionsEnum, IGetTimeLogConflictInput } from '@gauzy/contracts';
import { ITimeLog, PermissionsEnum, IGetTimeLogConflictInput, ID } from '@gauzy/contracts';
import { TimeLogService } from './time-log.service';
import { Permissions } from './../../shared/decorators';
import { OrganizationPermissionGuard, PermissionGuard, TenantBaseGuard } from './../../shared/guards';
Expand Down Expand Up @@ -239,10 +239,7 @@ export class TimeLogController {
* @returns The found time log.
*/
@Get(':id')
async findById(
@Param('id', UUIDValidationPipe) id: ITimeLog['id'],
@Query() options: FindOneOptions
): Promise<ITimeLog> {
async findById(@Param('id', UUIDValidationPipe) id: ID, @Query() options: FindOneOptions): Promise<ITimeLog> {
return await this._timeLogService.findOneByIdString(id, options);
}

Expand Down Expand Up @@ -288,7 +285,7 @@ export class TimeLogController {
@UseGuards(OrganizationPermissionGuard)
@Permissions(PermissionsEnum.ALLOW_MODIFY_TIME)
async updateManualTime(
@Param('id', UUIDValidationPipe) id: ITimeLog['id'],
@Param('id', UUIDValidationPipe) id: ID,
@Body(TimeLogBodyTransformPipe, new ValidationPipe({ transform: true })) entity: UpdateManualTimeLogDTO
): Promise<ITimeLog> {
return await this._timeLogService.updateManualTime(id, entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ import { IDeleteTimeSlot } from '@gauzy/contracts';
export class DeleteTimeSlotCommand implements ICommand {
static readonly type = '[TimeSlot] delete';

constructor(
public readonly query: IDeleteTimeSlot
) {}
constructor(public readonly query: IDeleteTimeSlot) {}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { ICommand } from '@nestjs/cqrs';
import { ITimeSlotMinute } from '@gauzy/contracts';
import { ID, ITimeSlotMinute } from '@gauzy/contracts';

export class UpdateTimeSlotMinutesCommand implements ICommand {
static readonly type = '[TimeSlotMinutes] update';

constructor(
public readonly id: string,
public readonly input: ITimeSlotMinute
) {}
constructor(public readonly id: ID, public readonly input: ITimeSlotMinute) {}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { ICommand } from '@nestjs/cqrs';
import { ITimeSlot } from '@gauzy/contracts';
import { ID, ITimeSlot } from '@gauzy/contracts';

export class UpdateTimeSlotCommand implements ICommand {
static readonly type = '[TimeSlot] update';

constructor(
public readonly id: string,
public readonly input: ITimeSlot
) {}
constructor(public readonly id: ID, public readonly input: ITimeSlot) {}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ArrayNotEmpty, IsBoolean, IsOptional } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { ArrayNotEmpty } from 'class-validator';
import { ID, IDeleteTimeSlot } from '@gauzy/contracts';
import { TenantOrganizationBaseDTO } from '../../../core/dto';
import { ForceDeleteDTO } from '../../dto/force-delete.dto';
import { TimeSlot } from '../time-slot.entity';

export class DeleteTimeSlotDTO extends TenantOrganizationBaseDTO implements IDeleteTimeSlot {
export class DeleteTimeSlotDTO extends ForceDeleteDTO<TimeSlot> implements IDeleteTimeSlot {
/**
* An array of IDs representing the time slots to be deleted.
* This array must not be empty and ensures that at least one time slot is selected for deletion.
*/
@ApiProperty({ type: () => Array })
@ArrayNotEmpty()
readonly ids: ID[] = [];

/**
* A flag to determine whether to force delete the time logs.
* If `true`, a hard delete will be performed; otherwise, a soft delete is used.
* This field is optional and defaults to `false`.
*/
@ApiPropertyOptional({ type: () => Boolean })
@IsOptional()
@IsBoolean()
readonly forceDelete: boolean = false;
}
3 changes: 2 additions & 1 deletion packages/core/src/time-tracking/time-slot/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { DeleteTimeSlotDTO } from './delete-time-slot.dto';
export * from './time-slot-query.dto';
export * from './delete-time-slot.dto';

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IntersectionType } from '@nestjs/swagger';
import { IGetTimeSlotInput } from '@gauzy/contracts';
import { FiltersQueryDTO, RelationsQueryDTO, SelectorsQueryDTO } from '../../../shared/dto';

/**
* Get time slot request DTO validation
*/
export class TimeSlotQueryDTO
extends IntersectionType(FiltersQueryDTO, IntersectionType(RelationsQueryDTO, SelectorsQueryDTO))
implements IGetTimeSlotInput {}
Loading

0 comments on commit 423a8ca

Please sign in to comment.