Skip to content

Commit

Permalink
fix: daily plan save by team
Browse files Browse the repository at this point in the history
  • Loading branch information
GloireMutaliko21 committed Oct 3, 2024
1 parent 4fd1585 commit 7040ec7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/contracts/src/daily-plan.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface IDailyPlanTasksUpdateInput

// Interface for data type should be sent when need to delete a task from many daily plans
export interface IDailyPlansTasksUpdateInput
extends Pick<IDailyPlanCreateInput, 'employeeId'>,
extends Pick<IDailyPlanCreateInput, 'employeeId' | 'organizationTeamId'>,
IBasePerTenantAndOrganizationEntityModel {
plansIds: ID[];
}
6 changes: 4 additions & 2 deletions packages/core/src/tasks/daily-plan/daily-plan.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class DailyPlanService extends TenantAwareCrudService<DailyPlan> {
async createDailyPlan(partialEntity: IDailyPlanCreateInput): Promise<IDailyPlan> {
try {
const tenantId = RequestContext.currentTenantId();
const { employeeId, organizationId, taskId } = partialEntity;
const { employeeId, organizationId, organizationTeamId, taskId } = partialEntity;

const dailyPlanDate = new Date(partialEntity.date).toISOString().split('T')[0];

Expand All @@ -56,6 +56,7 @@ export class DailyPlanService extends TenantAwareCrudService<DailyPlan> {
query.setFindOptions({ relations: { tasks: true } });
query.where('"dailyPlan"."tenantId" = :tenantId', { tenantId });
query.andWhere('"dailyPlan"."organizationId" = :organizationId', { organizationId });
query.andWhere('"dailyPlan"."organizationTeamId" = :organizationTeamId', { organizationTeamId });
query.andWhere(p(`DATE("dailyPlan"."date") = :dailyPlanDate`), { dailyPlanDate: `${dailyPlanDate}` });
query.andWhere('"dailyPlan"."employeeId" = :employeeId', { employeeId });
let dailyPlan = await query.getOne();
Expand Down Expand Up @@ -317,7 +318,7 @@ export class DailyPlanService extends TenantAwareCrudService<DailyPlan> {
async removeTaskFromManyPlans(taskId: ID, input: IDailyPlansTasksUpdateInput): Promise<IDailyPlan[]> {
try {
const tenantId = RequestContext.currentTenantId();
const { employeeId, plansIds, organizationId } = input;
const { employeeId, plansIds, organizationId, organizationTeamId } = input;
const currentDate = new Date().toISOString().split('T')[0];

// Initial query
Expand All @@ -331,6 +332,7 @@ export class DailyPlanService extends TenantAwareCrudService<DailyPlan> {
// Conditions
query.where(p(`"${query.alias}"."tenantId" = :tenantId`), { tenantId });
query.andWhere(p(`"${query.alias}"."organizationId" = :organizationId`), { organizationId });
query.andWhere(p(`"${query.alias}"."organizationTeamId" = :organizationTeamId`), { organizationTeamId });
query.andWhere(p(`"${query.alias}"."employeeId" = :employeeId`), { employeeId });

// Find condition must include only today and future plans. We cannot delete tasks from past plans
Expand Down

0 comments on commit 7040ec7

Please sign in to comment.