fix(reporting): add table alias parameter to date range clause method
This commit is contained in:
@@ -25,9 +25,10 @@ export default abstract class ReportingControllerBaseWithTimezone extends Workle
|
|||||||
* @param key - Date range key (e.g., YESTERDAY, LAST_WEEK)
|
* @param key - Date range key (e.g., YESTERDAY, LAST_WEEK)
|
||||||
* @param dateRange - Array of date strings
|
* @param dateRange - Array of date strings
|
||||||
* @param userTimezone - User's timezone (e.g., 'America/New_York')
|
* @param userTimezone - User's timezone (e.g., 'America/New_York')
|
||||||
|
* @param tableAlias - Table alias to use (e.g., 'twl', 'task_work_log')
|
||||||
* @returns SQL clause for date filtering
|
* @returns SQL clause for date filtering
|
||||||
*/
|
*/
|
||||||
protected static getDateRangeClauseWithTimezone(key: string, dateRange: string[], userTimezone: string) {
|
protected static getDateRangeClauseWithTimezone(key: string, dateRange: string[], userTimezone: string, tableAlias: string = 'task_work_log') {
|
||||||
// For custom date ranges
|
// For custom date ranges
|
||||||
if (dateRange.length === 2) {
|
if (dateRange.length === 2) {
|
||||||
// Convert dates to user's timezone start/end of day
|
// Convert dates to user's timezone start/end of day
|
||||||
@@ -40,10 +41,10 @@ export default abstract class ReportingControllerBaseWithTimezone extends Workle
|
|||||||
|
|
||||||
if (start.isSame(end, 'day')) {
|
if (start.isSame(end, 'day')) {
|
||||||
// Single day selection
|
// Single day selection
|
||||||
return `AND task_work_log.created_at >= '${startUtc}'::TIMESTAMP AND task_work_log.created_at <= '${endUtc}'::TIMESTAMP`;
|
return `AND ${tableAlias}.created_at >= '${startUtc}'::TIMESTAMP AND ${tableAlias}.created_at <= '${endUtc}'::TIMESTAMP`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `AND task_work_log.created_at >= '${startUtc}'::TIMESTAMP AND task_work_log.created_at <= '${endUtc}'::TIMESTAMP`;
|
return `AND ${tableAlias}.created_at >= '${startUtc}'::TIMESTAMP AND ${tableAlias}.created_at <= '${endUtc}'::TIMESTAMP`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For predefined ranges, calculate based on user's timezone
|
// For predefined ranges, calculate based on user's timezone
|
||||||
@@ -74,7 +75,7 @@ export default abstract class ReportingControllerBaseWithTimezone extends Workle
|
|||||||
if (startDate && endDate) {
|
if (startDate && endDate) {
|
||||||
const startUtc = startDate.utc().format("YYYY-MM-DD HH:mm:ss");
|
const startUtc = startDate.utc().format("YYYY-MM-DD HH:mm:ss");
|
||||||
const endUtc = endDate.utc().format("YYYY-MM-DD HH:mm:ss");
|
const endUtc = endDate.utc().format("YYYY-MM-DD HH:mm:ss");
|
||||||
return `AND task_work_log.created_at >= '${startUtc}'::TIMESTAMP AND task_work_log.created_at <= '${endUtc}'::TIMESTAMP`;
|
return `AND ${tableAlias}.created_at >= '${startUtc}'::TIMESTAMP AND ${tableAlias}.created_at <= '${endUtc}'::TIMESTAMP`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -548,7 +548,7 @@ export default class ReportingMembersController extends ReportingControllerBaseW
|
|||||||
|
|
||||||
// Get user timezone for proper date filtering
|
// Get user timezone for proper date filtering
|
||||||
const userTimezone = await this.getUserTimezone(req.user?.id as string);
|
const userTimezone = await this.getUserTimezone(req.user?.id as string);
|
||||||
const durationClause = this.getDateRangeClauseWithTimezone(duration as string || DATE_RANGES.LAST_WEEK, dateRange, userTimezone);
|
const durationClause = this.getDateRangeClauseWithTimezone(duration as string || DATE_RANGES.LAST_WEEK, dateRange, userTimezone, 'twl');
|
||||||
const minMaxDateClause = this.getMinMaxDates(duration as string || DATE_RANGES.LAST_WEEK, dateRange, "task_work_log");
|
const minMaxDateClause = this.getMinMaxDates(duration as string || DATE_RANGES.LAST_WEEK, dateRange, "task_work_log");
|
||||||
const memberName = (req.query.member_name as string)?.trim() || null;
|
const memberName = (req.query.member_name as string)?.trim() || null;
|
||||||
|
|
||||||
@@ -1101,7 +1101,7 @@ export default class ReportingMembersController extends ReportingControllerBaseW
|
|||||||
|
|
||||||
// Get user timezone for proper date filtering
|
// Get user timezone for proper date filtering
|
||||||
const userTimezone = await this.getUserTimezone(req.user?.id as string);
|
const userTimezone = await this.getUserTimezone(req.user?.id as string);
|
||||||
const durationClause = this.getDateRangeClauseWithTimezone(duration || DATE_RANGES.LAST_WEEK, date_range, userTimezone);
|
const durationClause = this.getDateRangeClauseWithTimezone(duration || DATE_RANGES.LAST_WEEK, date_range, userTimezone, 'twl');
|
||||||
const minMaxDateClause = this.getMinMaxDates(duration || DATE_RANGES.LAST_WEEK, date_range, "task_work_log");
|
const minMaxDateClause = this.getMinMaxDates(duration || DATE_RANGES.LAST_WEEK, date_range, "task_work_log");
|
||||||
|
|
||||||
const billableQuery = this.buildBillableQuery(billable);
|
const billableQuery = this.buildBillableQuery(billable);
|
||||||
|
|||||||
Reference in New Issue
Block a user