Skip to content

Commit

Permalink
bugfix: [#269] Volunteering hours set on a date appear on the followi…
Browse files Browse the repository at this point in the history
…ng one (#299)
  • Loading branch information
radulescuandrew authored Jul 18, 2024
1 parent 7fdd662 commit ad9ccf1
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion backend/src/common/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const QUEUES: Record<QUEUES_TYPES, string> = {
};

export const DATE_CONSTANTS = {
YYYY_MM_DD_HH_SS: 'yyyy-MM-dd HH:MM:SS',
YYYY_MM_DD_HH_SS: 'yyyy-MM-dd HH:mm:ss',
YYYY_MM_DD: 'yyyy-MM-dd',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,26 @@ export abstract class RepositoryWithPagination<T extends BaseEntity>
column: string,
start: Date,
end?: Date,
customDateFormat?: string,
): SelectQueryBuilder<T> {
const prefix = column.split('.').join('');
if (end) {
query.andWhere(`${column} BETWEEN :${prefix}Start AND :${prefix}End`, {
[`${prefix}Start`]: format(start, DATE_CONSTANTS.YYYY_MM_DD_HH_SS),
[`${prefix}End`]: format(end, DATE_CONSTANTS.YYYY_MM_DD_HH_SS),
[`${prefix}Start`]: format(
start,
customDateFormat || DATE_CONSTANTS.YYYY_MM_DD_HH_SS,
),
[`${prefix}End`]: format(
end,
customDateFormat || DATE_CONSTANTS.YYYY_MM_DD_HH_SS,
),
});
} else {
query.andWhere(`${column} >= :${prefix}Start`, {
[`${prefix}Start`]: format(start, DATE_CONSTANTS.YYYY_MM_DD),
[`${prefix}Start`]: format(
start,
customDateFormat || DATE_CONSTANTS.YYYY_MM_DD,
),
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class Migrations1721119397821 implements MigrationInterface {
name = 'ChangeActivityLogDatetimeToDate1721119397821';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "activity_log" ALTER COLUMN date TYPE DATE USING date::DATE;`,
);
}

public async down(): Promise<void> {
// Nothing we can do
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class ActivityLogEntity extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ type: 'timestamptz', name: 'date' })
@Column({ type: 'date', name: 'date' })
date: Date;

@Column({ type: 'integer', name: 'hours' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
IActivityLogModel,
UpdateActivityLogOptions,
} from '../models/activity-log.model';
import { DATE_CONSTANTS } from 'src/common/constants/constants';

@Injectable()
export class ActivityLogRepositoryService
Expand Down Expand Up @@ -152,6 +153,7 @@ export class ActivityLogRepositoryService
'activityLog.date',
findOptions.executionDateStart,
findOptions.executionDateEnd,
DATE_CONSTANTS.YYYY_MM_DD,
);
}

Expand Down
17 changes: 11 additions & 6 deletions frontend/src/services/activity-log/activity-log.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IPaginatedEntity } from '../../common/interfaces/paginated-entity.inter
import { formatEndDateISO9075, formatStartDateISO9075 } from '../../common/utils/utils';
import { ActivityLogFormTypes } from '../../components/ActivityLogForm';
import API from '../api';
import { format } from 'date-fns';

export interface GetActivityLogsParams {
limit: number;
Expand Down Expand Up @@ -37,9 +38,9 @@ export const getActivityLogs = async ({
params: {
...params,
...(executionDateStart
? { executionDateStart: formatStartDateISO9075(executionDateStart) }
? { executionDateStart: format(executionDateStart, 'yyyy-MM-dd') }
: {}),
...(executionDateEnd ? { executionDateEnd: formatEndDateISO9075(executionDateEnd) } : {}),
...(executionDateEnd ? { executionDateEnd: format(executionDateEnd, 'yyyy-MM-dd') } : {}),
...(registrationDateStart
? { registrationDateStart: formatStartDateISO9075(registrationDateStart) }
: {}),
Expand Down Expand Up @@ -76,8 +77,12 @@ export const getActivityLogsForDownload = async ({
search,
status,
approvedOrRejectedBy,
executionDateStart,
executionDateEnd,
executionDateStart: executionDateStart
? format(executionDateStart, 'yyyy-MM-dd')
: executionDateStart,
executionDateEnd: executionDateEnd
? format(executionDateEnd, 'yyyy-MM-dd')
: executionDateEnd,
volunteerId,
},
responseType: 'arraybuffer',
Expand Down Expand Up @@ -120,7 +125,7 @@ const formatAddActivityLogPayload = (data: ActivityLogFormTypes): object => {
const { volunteer, task, event, ...payload } = data;
return {
...payload,
date: formatEndDateISO9075(payload.date),
date: format(payload.date, 'yyyy-MM-dd'),
volunteerId: volunteer.value,
...(task.value !== CONSTANTS.OTHER ? { activityTypeId: task.value } : {}),
...(event ? { eventId: event.value } : {}),
Expand All @@ -133,7 +138,7 @@ const formatEditActivityLogPayload = (data: ActivityLogFormTypes): object => {

return {
...payload,
date: formatEndDateISO9075(payload.date),
date: format(payload.date, 'yyyy-MM-dd'),
...(task.value !== CONSTANTS.OTHER ? { activityTypeId: task.value } : {}),
...(event ? { eventId: event.value } : {}),
};
Expand Down
6 changes: 3 additions & 3 deletions mobile/src/services/activity-log/activity-log.api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { endOfDay, formatISO9075 } from 'date-fns';
import { format } from 'date-fns';
import { ActivityLogStatus } from '../../common/enums/activity-log.status.enum';
import { OrderDirection } from '../../common/enums/order-direction.enum';
import { IActivityLogCounters } from '../../common/interfaces/activity-log-counters.interface';
Expand All @@ -21,7 +21,7 @@ export const createActivityLog = async (payload: ActivityLogFormTypes): Promise<
return API.post('/mobile/activity-log', {
...log,
...(activityTypeId !== CONSTANTS.OTHER_OPTION ? { activityTypeId } : {}),
date: formatISO9075(endOfDay(payload.date)),
date: format(payload.date, 'yyyy-MM-dd'),
}).then((res) => res.data);
};

Expand All @@ -33,7 +33,7 @@ export const updateActivityLog = async (
return API.patch(`/mobile/activity-log/${volunteerId}`, {
...log,
...(activityTypeId !== CONSTANTS.OTHER_OPTION ? { activityTypeId } : {}),
...(updates.date ? { date: formatISO9075(endOfDay(updates.date)) } : {}),
...(updates.date ? { date: format(updates.date, 'yyyy-MM-dd') } : {}),
}).then((res) => res.data);
};

Expand Down

0 comments on commit ad9ccf1

Please sign in to comment.