Skip to content

Commit

Permalink
Merge pull request #6973 from ever-co/feat/#6972-last-logs
Browse files Browse the repository at this point in the history
feat: #6972 Added Last Log permission, flag to filter by organization…
  • Loading branch information
rahul-rocket authored Oct 13, 2023
2 parents fa50083 + e593ace commit a75b577
Show file tree
Hide file tree
Showing 19 changed files with 258 additions and 129 deletions.
3 changes: 2 additions & 1 deletion apps/gauzy/src/assets/i18n/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,8 @@
"ORG_TASK_VIEW": "عرض المهام",
"ORG_TASK_EDIT": "تحرير المهام",
"ORG_TASK_DELETE": "حذف المهام",
"ORG_TASK_SETTING": "إعدادات المهام"
"ORG_TASK_SETTING": "إعدادات المهام",
"ORG_MEMBER_LAST_LOG_VIEW": "عرض السجل الأخير"
},
"BILLING": "الفوترة",
"BUDGET": "ميزانية",
Expand Down
3 changes: 2 additions & 1 deletion apps/gauzy/src/assets/i18n/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2042,7 +2042,8 @@
"ALLOW_MODIFY_TIME": "Allow Modify Time",
"ALLOW_MANUAL_TIME": "Allow Manual Time",
"DELETE_SCREENSHOTS": "Allow Delete Screenshot",
"ORG_TASK_SETTING": "Настройки на задачите"
"ORG_TASK_SETTING": "Настройки на задачите",
"ORG_MEMBER_LAST_LOG_VIEW": "Преглед на последния запис"
},
"BILLING": "Billing",
"BUDGET": "Budget",
Expand Down
3 changes: 2 additions & 1 deletion apps/gauzy/src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,8 @@
"ORG_TASK_VIEW": "Ansicht von Aufgaben",
"ORG_TASK_EDIT": "Aufgaben bearbeiten",
"ORG_TASK_DELETE": "Aufgaben löschen",
"ORG_TASK_SETTING": "Aufgabeeinstellungen"
"ORG_TASK_SETTING": "Aufgabeeinstellungen",
"ORG_MEMBER_LAST_LOG_VIEW": "Letztes Protokoll anzeigen"
},
"BILLING": "Rechnungsstellung",
"BUDGET": "Budget",
Expand Down
3 changes: 2 additions & 1 deletion apps/gauzy/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,8 @@
"ORG_TASK_DELETE": "Delete Tasks",
"ORG_TASK_SETTING": "Task Settings",
"IMPORT_ADD": "Ability to import your data",
"EXPORT_ADD": "Ability to export your data"
"EXPORT_ADD": "Ability to export your data",
"ORG_MEMBER_LAST_LOG_VIEW": "View Last Log"
},
"BILLING": "Billing",
"BUDGET": "Budget",
Expand Down
3 changes: 2 additions & 1 deletion apps/gauzy/src/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,8 @@
"ORG_TASK_VIEW": "Ver tareas",
"ORG_TASK_EDIT": "Editar tareas",
"ORG_TASK_DELETE": "Eliminar tareas",
"ORG_TASK_SETTING": "Configuración de tarea"
"ORG_TASK_SETTING": "Configuración de tarea",
"ORG_MEMBER_LAST_LOG_VIEW": "Ver último registro"
},
"BILLING": "Facturación",
"BUDGET": "Presupuesto",
Expand Down
3 changes: 2 additions & 1 deletion apps/gauzy/src/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2084,7 +2084,8 @@
"ORG_TASK_VIEW": "Afficher les tâches",
"ORG_TASK_EDIT": "Modifier les tâches",
"ORG_TASK_DELETE": "Supprimer les tâches",
"ORG_TASK_SETTING": "Paramètres de tâche"
"ORG_TASK_SETTING": "Paramètres de tâche",
"ORG_MEMBER_LAST_LOG_VIEW": "Voir le dernier journal"
},
"BILLING": "Facturation",
"BUDGET": "Budget",
Expand Down
3 changes: 2 additions & 1 deletion apps/gauzy/src/assets/i18n/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -2042,7 +2042,8 @@
"ALLOW_MODIFY_TIME": "Allow Modify Time",
"ALLOW_MANUAL_TIME": "Allow Manual Time",
"DELETE_SCREENSHOTS": "Allow Delete Screenshot",
"ORG_TASK_SETTING": "Task Settings"
"ORG_TASK_SETTING": "Task Settings",
"ORG_MEMBER_LAST_LOG_VIEW": "צפה ביומן האחרון"
},
"BILLING": "Billing",
"BUDGET": "Budget",
Expand Down
3 changes: 2 additions & 1 deletion apps/gauzy/src/assets/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,8 @@
"ORG_TASK_VIEW": "Visualizza le attività",
"ORG_TASK_EDIT": "Modifica Compiti",
"ORG_TASK_DELETE": "Elimina compiti",
"ORG_TASK_SETTING": "Impostazioni attività"
"ORG_TASK_SETTING": "Impostazioni attività",
"ORG_MEMBER_LAST_LOG_VIEW": "Visualizza l'ultimo registro"
},
"BILLING": "Fatturazione",
"BUDGET": "Bilancio",
Expand Down
3 changes: 2 additions & 1 deletion apps/gauzy/src/assets/i18n/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,8 @@
"ORG_TASK_VIEW": "Taken bekijken",
"ORG_TASK_EDIT": "Taken bewerken",
"ORG_TASK_DELETE": "Taken verwijderen",
"ORG_TASK_SETTING": "Taakinstellingen"
"ORG_TASK_SETTING": "Taakinstellingen",
"ORG_MEMBER_LAST_LOG_VIEW": "Bekijk laatste logboek"
},
"BILLING": "Facturatie",
"BUDGET": "Budget",
Expand Down
3 changes: 2 additions & 1 deletion apps/gauzy/src/assets/i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,8 @@
"ORG_TASK_VIEW": "Pokaż zadania",
"ORG_TASK_EDIT": "Edytuj zadania",
"ORG_TASK_DELETE": "Usuń zadania",
"ORG_TASK_SETTING": "Ustawienia zadania"
"ORG_TASK_SETTING": "Ustawienia zadania",
"ORG_MEMBER_LAST_LOG_VIEW": "Zobacz ostatni dziennik"
},
"BILLING": "Rozliczenie / Faktury",
"BUDGET": "Budżet",
Expand Down
3 changes: 2 additions & 1 deletion apps/gauzy/src/assets/i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,8 @@
"ORG_TASK_VIEW": "Ver tarefas",
"ORG_TASK_EDIT": "Editar Tarefas",
"ORG_TASK_DELETE": "Excluir tarefas",
"ORG_TASK_SETTING": "Configurações da tarefa"
"ORG_TASK_SETTING": "Configurações da tarefa",
"ORG_MEMBER_LAST_LOG_VIEW": "Ver último registro"
},
"BILLING": "Faturamento",
"BUDGET": "Orçamento",
Expand Down
3 changes: 2 additions & 1 deletion apps/gauzy/src/assets/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -2042,7 +2042,8 @@
"ALLOW_MODIFY_TIME": "Разрешить изменять время",
"ALLOW_MANUAL_TIME": "Разрешить ручное время",
"DELETE_SCREENSHOTS": "Разрешить удаление скриншота",
"ORG_TASK_SETTING": "Параметры задачи"
"ORG_TASK_SETTING": "Параметры задачи",
"ORG_MEMBER_LAST_LOG_VIEW": "Посмотреть последний журнал"
},
"BILLING": "Биллинг",
"BUDGET": "Бюджет",
Expand Down
3 changes: 2 additions & 1 deletion apps/gauzy/src/assets/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,8 @@
"ORG_TASK_VIEW": "查看任务",
"ORG_TASK_EDIT": "编辑任务",
"ORG_TASK_DELETE": "删除任务",
"ORG_TASK_SETTING": "任务设置"
"ORG_TASK_SETTING": "任务设置",
"ORG_MEMBER_LAST_LOG_VIEW": "查看最后日志"
},
"BILLING": "计费",
"BUDGET": "预算",
Expand Down
7 changes: 4 additions & 3 deletions packages/contracts/src/organization-team.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IOrganizationProject } from './organization-projects.model';

export interface IOrganizationTeam
extends IBasePerTenantAndOrganizationEntityModel,
IRelationalImageAsset {
IRelationalImageAsset {
name: string;
color?: string;
emoji?: string;
Expand All @@ -28,7 +28,7 @@ export interface IOrganizationTeam

export interface IOrganizationTeamFindInput
extends IBasePerTenantAndOrganizationEntityModel,
IRelationalEmployee {
IRelationalEmployee {
name?: string;
prefix?: string;
public?: boolean;
Expand All @@ -37,7 +37,7 @@ export interface IOrganizationTeamFindInput

export interface IOrganizationTeamCreateInput
extends IBasePerTenantAndOrganizationEntityModel,
IRelationalImageAsset {
IRelationalImageAsset {
name: string;
emoji?: string;
teamSize?: string;
Expand All @@ -60,6 +60,7 @@ export interface IOrganizationTeamUpdateInput

export interface IOrganizationTeamStatisticInput extends ITimerStatusInput {
withLaskWorkedTask: boolean;
includeOrganizationTeamId?: boolean;
}

export interface IRelationalOrganizationTeam {
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/src/role-permission.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export enum PermissionsEnum {
ALLOW_MODIFY_TIME = 'ALLOW_MODIFY_TIME',
ALLOW_MANUAL_TIME = 'ALLOW_MANUAL_TIME',
DELETE_SCREENSHOTS = 'DELETE_SCREENSHOTS',
ORG_MEMBER_LAST_LOG_VIEW = 'ORG_MEMBER_LAST_LOG_VIEW',
}

export const PermissionGroups = {
Expand Down Expand Up @@ -270,6 +271,7 @@ export const PermissionGroups = {
PermissionsEnum.ALLOW_MANUAL_TIME,
PermissionsEnum.DELETE_SCREENSHOTS,
PermissionsEnum.ACCESS_DELETE_ACCOUNT,
PermissionsEnum.ORG_MEMBER_LAST_LOG_VIEW,
],

//Readonly permissions, are only enabled for Super Admin/Admin role
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
import { ApiPropertyOptional, IntersectionType } from '@nestjs/swagger';
import { IsOptional } from 'class-validator';
import { Transform, TransformFnParams } from 'class-transformer';
import { IDateRangePicker, IOrganizationTeamStatisticInput } from '@gauzy/contracts';
import {
IDateRangePicker,
IOrganizationTeamStatisticInput,
} from '@gauzy/contracts';
import { parseToBoolean } from '@gauzy/common';
import { DateRangeQueryDTO, RelationsQueryDTO } from './../../shared/dto';
/**
* Get team statistic request DTO validation
*/
export class OrganizationTeamStatisticDTO extends IntersectionType(
DateRangeQueryDTO,
RelationsQueryDTO
) implements IOrganizationTeamStatisticInput, IDateRangePicker {
export class OrganizationTeamStatisticDTO
extends IntersectionType(DateRangeQueryDTO, RelationsQueryDTO)
implements IOrganizationTeamStatisticInput, IDateRangePicker
{
/**
* Indicates if last worked task row should be included in entity result.
*/
@ApiPropertyOptional({ type: 'boolean' })
@IsOptional()
@Transform(({ value }: TransformFnParams) => value ? parseToBoolean(value) : false)
@Transform(({ value }: TransformFnParams) =>
value ? parseToBoolean(value) : false
)
readonly withLaskWorkedTask: boolean;

/**
* Indicates if organizationTeamId should be used to filter the records.
*/
@ApiPropertyOptional({ type: 'boolean' })
@IsOptional()
@Transform(({ value }: TransformFnParams) =>
value ? parseToBoolean(value) : false
)
readonly includeOrganizationTeamId?: boolean;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { BadRequestException } from '@nestjs/common';
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs';
import { IDateRangePicker, IOrganizationTeam, IOrganizationTeamEmployee, IOrganizationTeamStatisticInput } from '@gauzy/contracts';
import {
IDateRangePicker,
IOrganizationTeam,
IOrganizationTeamEmployee,
IOrganizationTeamStatisticInput,
} from '@gauzy/contracts';
import { parseToBoolean } from '@gauzy/common';
import { GetOrganizationTeamStatisticQuery } from '../get-organization-team-statistic.query';
import { OrganizationTeamService } from '../../organization-team.service';
Expand All @@ -9,13 +14,13 @@ import { StatisticService } from './../../../time-tracking/statistic';

@QueryHandler(GetOrganizationTeamStatisticQuery)
export class GetOrganizationTeamStatisticHandler
implements IQueryHandler<GetOrganizationTeamStatisticQuery> {

implements IQueryHandler<GetOrganizationTeamStatisticQuery>
{
constructor(
private readonly timerService: TimerService,
private readonly organizationTeamService: OrganizationTeamService,
private readonly _statisticService: StatisticService
) { }
) {}

public async execute(
query: GetOrganizationTeamStatisticQuery
Expand All @@ -24,17 +29,24 @@ export class GetOrganizationTeamStatisticHandler
const { organizationTeamId, options } = query;
const { withLaskWorkedTask } = options;

const organizationTeam = await this.organizationTeamService.findOneByIdString(organizationTeamId, {
...(options['relations']
? {
relations: options['relations'],
const organizationTeam =
await this.organizationTeamService.findOneByIdString(
organizationTeamId,
{
...(options['relations']
? {
relations: options['relations'],
}
: {}),
}
: {}),
});
);
if ('members' in organizationTeam) {
const { members, organizationId, tenantId } = organizationTeam;
if (Boolean(withLaskWorkedTask)) {
organizationTeam['members'] = await this.syncLastWorkedTask({ members, organizationId, tenantId }, options);
organizationTeam['members'] = await this.syncLastWorkedTask(
{ members, organizationId, tenantId },
options
);
}
}
return organizationTeam;
Expand All @@ -50,48 +62,60 @@ export class GetOrganizationTeamStatisticHandler
* @returns
*/
async syncLastWorkedTask(
{
organizationId,
tenantId,
members
},
{ organizationId, tenantId, members },
options: IDateRangePicker & IOrganizationTeamStatisticInput
): Promise<IOrganizationTeamEmployee[]> {
try {
const { startDate, endDate, withLaskWorkedTask, source } = options;
const {
startDate,
endDate,
withLaskWorkedTask,
source,
includeOrganizationTeamId,
} = options;
return await Promise.all(
await members.map(async (member: IOrganizationTeamEmployee) => {
const { employeeId, organizationTeamId } = member;
const timerWorkedStatus =
await this.timerService.getTimerWorkedStatus({
source,
employeeId,
organizationTeamId,
...(includeOrganizationTeamId === false
? {}
: { organizationTeamId }),
organizationId,
tenantId,
...(parseToBoolean(withLaskWorkedTask)
? {
relations: ['task'],
}
relations: ['task'],
}
: {}),
});

return {
...member,
lastWorkedTask: parseToBoolean(withLaskWorkedTask) ? timerWorkedStatus.lastLog?.task : null,
lastWorkedTask: parseToBoolean(withLaskWorkedTask)
? timerWorkedStatus.lastLog?.task
: null,
running: timerWorkedStatus?.running,
duration: timerWorkedStatus?.duration,
timerStatus: timerWorkedStatus?.timerStatus,
totalWorkedTasks: await this._statisticService.getTasks({
organizationId,
tenantId,
organizationTeamId,
employeeIds: [employeeId],
}),
totalWorkedTasks: await this._statisticService.getTasks(
{
organizationId,
tenantId,
...(includeOrganizationTeamId === false
? {}
: { organizationTeamId }),
employeeIds: [employeeId],
}
),
totalTodayTasks: await this._statisticService.getTasks({
organizationId,
tenantId,
organizationTeamId,
...(includeOrganizationTeamId === false
? {}
: { organizationTeamId }),
employeeIds: [employeeId],
startDate,
endDate,
Expand Down
Loading

0 comments on commit a75b577

Please sign in to comment.