Skip to content

Commit

Permalink
[ZARS-645][ADD] rework status check for tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
af-ak authored Dec 4, 2023
1 parent ae3e694 commit 2484fb9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/modules/comment/__tests__/comment.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { CommentType } from '../enums/comment-type.enum';
import { ReferenceType } from '../enums/reference-type.enum';
import { CommentDocument } from '../schema/comment.schema';
import { ProposalCrudService } from 'src/modules/proposal/services/proposal-crud.service';
import { ProposalStatus } from 'src/modules/proposal/enums/proposal-status.enum';

class CommentModel {
constructor(private data) {}
Expand Down Expand Up @@ -263,15 +264,23 @@ describe('CommentService', () => {
isFromLocation: role === Role.Researcher ? false : true,
} as unknown as IRequestUser;

const proposal = {
status: ProposalStatus.Rework,
} as unknown as ProposalDocument;

CommentModel.find.mockResolvedValue([mainComment]);

proposalCrudService.findDocument.mockResolvedValueOnce(proposal);

const result = await service.findForItem(commentReferenceDto, user);
let filter: FilterQuery<Comment> = {
...commentReferenceDto,
};

if (role === Role.Researcher) {
if (role === Role.Researcher && proposal.status === ProposalStatus.Rework) {
filter.type = { $in: [CommentType.ProposalMessageToOwner, CommentType.ProposalTask] };
} else if (role === Role.Researcher) {
filter.type = { $in: [CommentType.ProposalMessageToOwner] };
} else {
filter.type = { $in: [CommentType.ProposalMessageToLocation, CommentType.ProposalTaskFdpg] };
filter.locations = { $in: [user.miiLocation, MiiLocation.VirtualAll] };
Expand Down
14 changes: 12 additions & 2 deletions src/modules/comment/comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ValidationGroup } from './enums/validation-group.enum';
import { Answer } from './schema/answer.schema';
import { validateIsDoneAccess } from './utils/is-done-access.util';
import { ProposalCrudService } from '../proposal/services/proposal-crud.service';
import { ProposalStatus } from '../proposal/enums/proposal-status.enum';

@Injectable()
export class CommentService {
Expand Down Expand Up @@ -142,9 +143,18 @@ export class CommentService {
const filter: FilterQuery<Comment> = {
...commentReference,
};

if (user.singleKnownRole === Role.Researcher) {
const projection = { status: 1 };
const proposal = await this.proposalCrudService.findDocument(
commentReference.referenceDocumentId,
user,
projection,
false,
);

if (user.singleKnownRole === Role.Researcher && proposal.status === ProposalStatus.Rework) {
filter.type = { $in: [CommentType.ProposalMessageToOwner, CommentType.ProposalTask] };
} else if (user.singleKnownRole === Role.Researcher) {
filter.type = { $in: [CommentType.ProposalMessageToOwner] };
} else if (user.isFromLocation) {
filter.type = { $in: [CommentType.ProposalMessageToLocation, CommentType.ProposalTaskFdpg] };
filter.locations = { $in: [user.miiLocation, MiiLocation.VirtualAll] };
Expand Down

0 comments on commit 2484fb9

Please sign in to comment.