Skip to content

Commit

Permalink
fix: #6909 removed deletedAt column filter manually
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-rocket committed Oct 31, 2023
1 parent 0f7a88b commit eabfac1
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 77 deletions.
1 change: 1 addition & 0 deletions packages/core/src/core/entities/base.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export abstract class BaseEntity extends Model implements IBaseEntityModel {
format: 'date-time',
example: '2018-11-21T06:20:32.232Z'
})
@IsOptional()
@IsDateString()
@DeleteDateColumn()
deletedAt?: Date;
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/employee/employee.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export class Employee extends TenantOrganizationBaseEntity implements IEmployee
@Column({ nullable: true })
valueDate?: Date;


@ApiPropertyOptional({ type: () => String, maxLength: 200 })
@Column({ length: 200, nullable: true })
short_description?: string;
Expand Down
11 changes: 5 additions & 6 deletions packages/core/src/employee/employee.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,13 @@ export class EmployeeService extends TenantAwareCrudService<Employee> {
query.innerJoin(`${query.alias}.user`, 'user');
query.leftJoin(`${query.alias}.tags`, 'tags');
query.innerJoin(`user.organizations`, 'organizations');
/**
* Set skip/take options for pagination
*/

query.setFindOptions({
/**
* Set skip/take options for pagination
*/
skip: options && options.skip ? options.take * (options.skip - 1) : 0,
take: options && options.take ? options.take : 10
});
query.setFindOptions({
take: options && options.take ? options.take : 10,
/**
* Load selected table properties/fields for self & relational select.
*/
Expand Down
49 changes: 14 additions & 35 deletions packages/core/src/time-tracking/statistic/statistic.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ export class StatisticService {
new Brackets((qb: WhereExpressionBuilder) => {
qb.andWhere(`"timeLogs"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"timeLogs"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"timeLogs"."deletedAt" IS NULL`);
})
);
})
Expand Down Expand Up @@ -314,7 +313,6 @@ export class StatisticService {
new Brackets((qb: WhereExpressionBuilder) => {
qb.andWhere(`"timeLogs"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"timeLogs"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"timeLogs"."deletedAt" IS NULL`);
})
);
})
Expand Down Expand Up @@ -450,7 +448,6 @@ export class StatisticService {
new Brackets((qb: WhereExpressionBuilder) => {
qb.andWhere(`"timeLogs"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"timeLogs"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"timeLogs"."deletedAt" IS NULL`);
})
);
})
Expand Down Expand Up @@ -515,7 +512,6 @@ export class StatisticService {
new Brackets((qb: WhereExpressionBuilder) => {
qb.andWhere(`"timeLogs"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"timeLogs"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"timeLogs"."deletedAt" IS NULL`);
})
);
})
Expand Down Expand Up @@ -611,7 +607,6 @@ export class StatisticService {
new Brackets((qb: WhereExpressionBuilder) => {
qb.andWhere(`"timeLogs"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"timeLogs"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"timeLogs"."deletedAt" IS NULL`);
})
);
})
Expand Down Expand Up @@ -696,7 +691,6 @@ export class StatisticService {
});
qb.andWhere(`"timeLogs"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"timeLogs"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"timeLogs"."deletedAt" IS NULL`);
})
)
.andWhere(
Expand Down Expand Up @@ -799,7 +793,6 @@ export class StatisticService {
new Brackets((qb: WhereExpressionBuilder) => {
qb.andWhere(`"${query.alias}"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"${query.alias}"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"${query.alias}"."deletedAt" IS NULL`);
})
)
.andWhere(
Expand Down Expand Up @@ -868,7 +861,6 @@ export class StatisticService {
new Brackets((qb: WhereExpressionBuilder) => {
qb.andWhere(`"${totalDurationQuery.alias}"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"${totalDurationQuery.alias}"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"${totalDurationQuery.alias}"."deletedAt" IS NULL`);
})
)
.andWhere(
Expand Down Expand Up @@ -992,12 +984,11 @@ export class StatisticService {
.addSelect(`"task"."id"`, 'taskId')
.addSelect(`"${todayQuery.alias}"."updatedAt"`, 'updatedAt')
.addSelect(
`${
['sqlite', 'better-sqlite3'].includes(
this.configService.dbConnectionOptions.type
)
? `COALESCE(ROUND(SUM((julianday(COALESCE("${todayQuery.alias}"."stoppedAt", datetime('now'))) - julianday("${todayQuery.alias}"."startedAt")) * 86400) / COUNT("time_slot"."id")), 0)`
: `COALESCE(ROUND(SUM(extract(epoch from (COALESCE("${todayQuery.alias}"."stoppedAt", NOW()) - "${todayQuery.alias}"."startedAt"))) / COUNT("time_slot"."id")), 0)`
`${['sqlite', 'better-sqlite3'].includes(
this.configService.dbConnectionOptions.type
)
? `COALESCE(ROUND(SUM((julianday(COALESCE("${todayQuery.alias}"."stoppedAt", datetime('now'))) - julianday("${todayQuery.alias}"."startedAt")) * 86400) / COUNT("time_slot"."id")), 0)`
: `COALESCE(ROUND(SUM(extract(epoch from (COALESCE("${todayQuery.alias}"."stoppedAt", NOW()) - "${todayQuery.alias}"."startedAt"))) / COUNT("time_slot"."id")), 0)`
}`,
`today_duration`
)
Expand Down Expand Up @@ -1025,26 +1016,22 @@ export class StatisticService {
)
.andWhere(
new Brackets((qb: WhereExpressionBuilder) => {
qb.andWhere(
`"${todayQuery.alias}"."tenantId" = :tenantId`,
{ tenantId }
);
qb.andWhere(
`"${todayQuery.alias}"."organizationId" = :organizationId`,
{ organizationId }
);
qb.andWhere(`"${todayQuery.alias}"."deletedAt" IS NULL`);
qb.andWhere(`"${todayQuery.alias}"."tenantId" = :tenantId`, {
tenantId
});
qb.andWhere(`"${todayQuery.alias}"."organizationId" = :organizationId`, {
organizationId
});
})
)
.andWhere(
new Brackets((qb: WhereExpressionBuilder) => {
qb.andWhere(`"time_slot"."tenantId" = :tenantId`, {
tenantId,
});
qb.andWhere(
`"time_slot"."organizationId" = :organizationId`,
{ organizationId }
);
qb.andWhere(`"time_slot"."organizationId" = :organizationId`, {
organizationId
});
})
)
.andWhere(
Expand Down Expand Up @@ -1128,7 +1115,6 @@ export class StatisticService {
new Brackets((qb: WhereExpressionBuilder) => {
qb.andWhere(`"${query.alias}"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"${query.alias}"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"${query.alias}"."deletedAt" IS NULL`);
})
)
.andWhere(
Expand Down Expand Up @@ -1230,7 +1216,6 @@ export class StatisticService {
new Brackets((qb: WhereExpressionBuilder) => {
qb.andWhere(`"${totalDurationQuery.alias}"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"${totalDurationQuery.alias}"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"${totalDurationQuery.alias}"."deletedAt" IS NULL`);
})
)
.andWhere(
Expand Down Expand Up @@ -1346,7 +1331,6 @@ export class StatisticService {
new Brackets((web: WhereExpressionBuilder) => {
web.andWhere(`"${qb.alias}"."tenantId" = :tenantId`, { tenantId });
web.andWhere(`"${qb.alias}"."organizationId" = :organizationId`, { organizationId });
web.andWhere(`"${qb.alias}"."deletedAt" IS NULL`);
})
);
qb.andWhere(
Expand Down Expand Up @@ -1471,7 +1455,6 @@ export class StatisticService {
new Brackets((qb: WhereExpressionBuilder) => {
qb.andWhere(`"time_log"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"time_log"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"time_log"."deletedAt" IS NULL`);
})
)
.andWhere(
Expand Down Expand Up @@ -1540,7 +1523,6 @@ export class StatisticService {
new Brackets((qb: WhereExpressionBuilder) => {
qb.andWhere(`"time_log"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"time_log"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"time_log"."deletedAt" IS NULL`);
})
)
.andWhere(
Expand Down Expand Up @@ -1622,7 +1604,6 @@ export class StatisticService {
new Brackets((qb: WhereExpressionBuilder) => {
qb.andWhere(`"${query.alias}"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"${query.alias}"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"${query.alias}"."deletedAt" IS NULL`);
})
);
query.andWhere(
Expand Down Expand Up @@ -1722,7 +1703,6 @@ export class StatisticService {
});
web.andWhere(`"timeLogs"."tenantId" = :tenantId`, { tenantId });
web.andWhere(`"timeLogs"."organizationId" = :organizationId`, { organizationId });
web.andWhere(`"timeLogs"."deletedAt" IS NULL`);
})
);
qb.andWhere(
Expand Down Expand Up @@ -1838,7 +1818,6 @@ export class StatisticService {
new Brackets((qb: WhereExpressionBuilder) => {
qb.andWhere(`"${query.alias}"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"${query.alias}"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"${query.alias}"."deletedAt" IS NULL`);
})
);
qb.andWhere(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class GetConflictTimeLogHandler
.where(`"${conflictQuery.alias}"."employeeId" = :employeeId`, { employeeId })
.andWhere(`"${conflictQuery.alias}"."tenantId" = :tenantId`, { tenantId })
.andWhere(`"${conflictQuery.alias}"."organizationId" = :organizationId`, { organizationId })
.andWhere(`"${conflictQuery.alias}"."deletedAt" IS null`)
.andWhere(
['sqlite', 'better-sqlite3'].includes(this.configService.dbConnectionOptions.type)
? `'${startedAt}' >= "${conflictQuery.alias}"."startedAt" and '${startedAt}' <= "${conflictQuery.alias}"."stoppedAt"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class TimeLogDeleteHandler
@InjectRepository(TimeLog)
private readonly timeLogRepository: Repository<TimeLog>,
private readonly commandBus: CommandBus
) {}
) { }

public async execute(
command: TimeLogDeleteCommand
Expand Down Expand Up @@ -55,10 +55,9 @@ export class TimeLogDeleteHandler
id: In(pluck(timeLogs, 'id'))
});
} else {
deleteResult = await this.timeLogRepository.update(
{ id: In(pluck(timeLogs, 'id')) },
{ deletedAt: new Date() }
);
deleteResult = await this.timeLogRepository.softDelete({
id: In(pluck(timeLogs, 'id'))
});
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export class CreateTimeSlotHandler
web.andWhere(`"${qb.alias}"."source" = :source`, { source });
web.andWhere(`"${qb.alias}"."logType" = :logType`, { logType });
web.andWhere(`"${qb.alias}"."stoppedAt" IS NOT NULL`);
web.andWhere(`"${qb.alias}"."deletedAt" IS NULL`);
})
);
qb.addOrderBy(`"${qb.alias}"."createdAt"`, 'DESC');
Expand Down Expand Up @@ -162,7 +161,6 @@ export class CreateTimeSlotHandler
web.andWhere(`"${qb.alias}"."logType" = :logType`, { logType });
web.andWhere(`"${qb.alias}"."employeeId" = :employeeId`, { employeeId });
web.andWhere(`"${qb.alias}"."stoppedAt" IS NOT NULL`);
web.andWhere(`"${qb.alias}"."deletedAt" IS NULL`);
})
);
qb.andWhere(`"${qb.alias}"."id" IN (:...timeLogIds)`, {
Expand Down
17 changes: 8 additions & 9 deletions packages/core/src/time-tracking/time-slot/time-slot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ export class TimeSlotService extends TenantAwareCrudService<TimeSlot> {
}

const { start, end } = (startDate && endDate) ?
getDateRangeFormat(
moment.utc(startDate),
moment.utc(endDate)
) :
getDateRangeFormat(
moment().startOf('day').utc(),
moment().endOf('day').utc()
);
getDateRangeFormat(
moment.utc(startDate),
moment.utc(endDate)
) :
getDateRangeFormat(
moment().startOf('day').utc(),
moment().endOf('day').utc()
);

const query = this.timeSlotRepository.createQueryBuilder('time_slot');
query.setFindOptions({
Expand Down Expand Up @@ -168,7 +168,6 @@ export class TimeSlotService extends TenantAwareCrudService<TimeSlot> {
new Brackets((web: WhereExpressionBuilder) => {
web.andWhere(`"time_log"."tenantId" = :tenantId`, { tenantId });
web.andWhere(`"time_log"."organizationId" = :organizationId`, { organizationId });
web.andWhere(`"time_log"."deletedAt" IS NULL`);
})
);
qb.andWhere(
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/time-tracking/timer/timer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export class TimerService {
},
},
where: {
deletedAt: IsNull(),
...(source ? { source } : {}),
startedAt: Between(start, end),
stoppedAt: Not(IsNull()),
Expand All @@ -117,7 +116,6 @@ export class TimerService {
// Get today's last log (running or completed)
const lastLog = await this.timeLogRepository.findOne({
where: {
deletedAt: IsNull(),
...(source ? { source } : {}),
startedAt: Between(start, end),
stoppedAt: Not(IsNull()),
Expand Down Expand Up @@ -424,7 +422,6 @@ export class TimerService {
const { id: employeeId } = employee;
return await this.timeLogRepository.findOne({
where: {
deletedAt: IsNull(),
stoppedAt: Not(IsNull()),
employeeId,
tenantId,
Expand Down Expand Up @@ -496,7 +493,6 @@ export class TimerService {
*/
const lastLog = await this.timeLogRepository.findOne({
where: {
deletedAt: IsNull(),
startedAt: Not(IsNull()),
stoppedAt: Not(IsNull()),
employeeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class TimesheetFirstOrCreateHandler
private readonly employeeRepository: Repository<Employee>,

private readonly commandBus: CommandBus
) {}
) { }

public async execute(
command: TimesheetFirstOrCreateCommand
Expand Down Expand Up @@ -73,7 +73,6 @@ export class TimesheetFirstOrCreateHandler
qb.andWhere(`"${query.alias}"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"${query.alias}"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"${query.alias}"."employeeId" = :employeeId`, { employeeId });
qb.andWhere(`"${query.alias}"."deletedAt" IS NULL`);
})
);
});
Expand Down
23 changes: 11 additions & 12 deletions packages/core/src/time-tracking/timesheet/timesheet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ export class TimeSheetService extends TenantAwareCrudService<Timesheet> {

const { organizationId, startDate, endDate } = request;
const { start, end } = (startDate && endDate) ?
getDateRangeFormat(
moment.utc(startDate),
moment.utc(endDate)
) :
// use current start of the month if startDate not found
// use current end of the month if endDate not found
getDateRangeFormat(
moment().startOf('month').utc(),
moment().endOf('month').utc()
);
getDateRangeFormat(
moment.utc(startDate),
moment.utc(endDate)
) :
// use current start of the month if startDate not found
// use current end of the month if endDate not found
getDateRangeFormat(
moment().startOf('month').utc(),
moment().endOf('month').utc()
);

const employeeIds: string[] = [];
if (
Expand All @@ -114,7 +114,7 @@ export class TimeSheetService extends TenantAwareCrudService<Timesheet> {

qb.andWhere(
new Brackets((qb: WhereExpressionBuilder) => {
qb.where( {
qb.where({
startedAt: Between(start, end),
...(employeeIds.length > 0 ? { employeeId: In(employeeIds) } : {})
});
Expand All @@ -123,7 +123,6 @@ export class TimeSheetService extends TenantAwareCrudService<Timesheet> {

qb.andWhere(`"${qb.alias}"."tenantId" = :tenantId`, { tenantId });
qb.andWhere(`"${qb.alias}"."organizationId" = :organizationId`, { organizationId });
qb.andWhere(`"${qb.alias}"."deletedAt" IS NULL`);
return qb;
}
}

0 comments on commit eabfac1

Please sign in to comment.