Skip to content

Commit

Permalink
[ADD] service and dto
Browse files Browse the repository at this point in the history
  • Loading branch information
af-ofr committed Apr 9, 2024
1 parent 712b3cb commit 7ee0993
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/modules/event-engine/event-engine.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ export class EventEngineService {
}
}

async handleProposalRevertUacApproval(proposal: Proposal, vote: boolean, location: MiiLocation) {
if (proposal) {
const proposalUrl = this.getProposalUrl(proposal);
await this.locationVoteService.handleRevertUacApproval(proposal, vote, location, proposalUrl);
}
}

async handleProposalContractSign(proposal: Proposal, vote: boolean, user: IRequestUser) {
if (proposal) {
const proposalUrl = this.getProposalUrl(proposal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ export class LocationVoteService {

await Promise.allSettled(emailTasks);
}

async handleRevertUacApproval(proposal: Proposal, vote: boolean, location: MiiLocation, proposalUrl: string) {
// ?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ContractingUploadDto } from '../dto/contracting-upload.dto';
import { ProposalMarkConditionAcceptedReturnDto } from '../dto/proposal/proposal.dto';
import { SetDizApprovalDto } from '../dto/set-diz-approval.dto';
import { SetUacApprovalDto, SetUacApprovalWithFileDto } from '../dto/set-uac-approval.dto';
import { RevertUacApprovalDto } from '../dto/revert-uac-approval.dto';
import { SignContractDto, SignContractWithFileDto } from '../dto/sign-contract.dto';
import { InitContractingDto } from '../dto/proposal/init-contracting.dto';

Expand Down Expand Up @@ -73,15 +74,13 @@ export class ProposalContractingController {
@ApiOperation({ summary: 'Reverts the UAC Approval' })
@ApiNoContentResponse({ description: 'UAC Approval reverted. No content returns.' })
@HttpCode(204)
// @ApiBody({ type: RevertUacApprovalDto }) [RevertUacApprovalDto - to be created]
@ApiBody({ type: RevertUacApprovalDto })
async revertUacApproval(
@Param() { id }: MongoIdParamDto,
// @Body() vote: RevertUacApprovalDto, [RevertUacApprovalDto - to be created]
@Body() vote: RevertUacApprovalDto,
@Request() { user }: FdpgRequest,
): Promise<void> {
// deletes the proposal's blob
// creates new update in the proposal's history
return await this.proposalContractingService.revertUacApproval(id, user);
return await this.proposalContractingService.revertUacApproval(id, vote, user, location);
}

@Auth(Role.FdpgMember)
Expand Down
14 changes: 14 additions & 0 deletions src/modules/proposal/dto/revert-uac-approval.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Exclude, Expose } from 'class-transformer';
import { IsBoolean, IsEnum } from 'class-validator';
import { MiiLocation } from 'src/shared/constants/mii-locations';

@Exclude()
export class RevertUacApprovalDto {
@Expose()
@IsBoolean()
value: boolean;

@Expose()
@IsEnum(MiiLocation)
location: MiiLocation;
}
1 change: 1 addition & 0 deletions src/modules/proposal/enums/history-event.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum HistoryEventType {
ProposalRework = 'PROPOSAL_REWORK',
ProposalRejected = 'PROPOSAL_REJECT',
ProposalLocationCheck = 'PROPOSAL_LOCATION_CHECK',
ProposalUacApprovalReverted = 'PROPOSAL_UAC_APPROVAL_REVERTED',
ProposalContracting = 'PROPOSAL_CONTRACTING',
ProposalDataDelivery = 'PROPOSAL_DATA_DELIVERY',
ProposalDataCorrupt = 'PROPOSAL_DATA_CORRUPT',
Expand Down
1 change: 1 addition & 0 deletions src/modules/proposal/enums/proposal-status.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum ProposalStatus {
Rework = 'REWORK',
FdpgCheck = 'FDPG_CHECK',
LocationCheck = 'LOCATION_CHECK',
UacApprovalReverted = 'UAC_APPROVAL_REVERTED',
Contracting = 'CONTRACTING',
ExpectDataDelivery = 'EXPECT_DATA_DELIVERY',
DataResearch = 'DATA_RESEARCH',
Expand Down
3 changes: 3 additions & 0 deletions src/modules/proposal/schema/proposal.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ export class Proposal {
@Prop([String])
uacApprovedLocations: MiiLocation[];

@Prop([String])
revertUacApprovalLocations: MiiLocation[];

@Prop([String])
requestedButExcludedLocations: MiiLocation[];

Expand Down
27 changes: 26 additions & 1 deletion src/modules/proposal/services/proposal-contracting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { StorageService } from '../../storage/storage.service';
import { EventEngineService } from '../../event-engine/event-engine.service';
import { ProposalMarkConditionAcceptedReturnDto } from '../dto/proposal/proposal.dto';
import { SetUacApprovalDto } from '../dto/set-uac-approval.dto';
import { RevertUacApprovalDto } from '../dto/revert-uac-approval.dto';
import { SignContractDto } from '../dto/sign-contract.dto';
import { UploadDto } from '../dto/upload.dto';
import { ProposalValidation } from '../enums/porposal-validation.enum';
Expand All @@ -21,13 +22,15 @@ import {
addUacApproval,
addUacApprovalWithCondition,
addUacConditionReview,
addRevertUacApproval,
} from '../utils/add-location-vote.util';
import {
addHistoryItemForContractSign,
addHistoryItemForDizApproval,
addHistoryItemForStatus,
addHistoryItemForUacApproval,
addHistoryItemForUacCondition,
addHistoryItemForRevertUacApproval,
} from '../utils/proposal-history.util';
import { addUpload, getBlobName } from '../utils/proposal.utils';
import { validateContractSign } from '../utils/validate-contract-sign.util';
Expand Down Expand Up @@ -86,7 +89,29 @@ export class ProposalContractingService {
await this.eventEngineService.handleProposalUacApproval(saveResult, vote.value, user.miiLocation);
}

async revertUacApproval(proposalId: string, user: IRequestUser): Promise<void> {}
async revertUacApproval(
proposalId: string,
revert: RevertUacApprovalDto,
user: IRequestUser,
location: RevertUacApprovalDto,
): Promise<void> {
// condition "if revert === true" needed?

//validateRevertUacApproval ?
const toBeUpdated = await this.proposalCrudService.findDocument(proposalId, user, undefined, true);
addRevertUacApproval(proposalId, user, revert);

// deletes the proposal's blob
const toBeDeleted = await this.proposalCrudService.findDocument(proposalId, user);
const blobName = getBlobName(toBeDeleted.id, UseCaseUpload.ContractCondition);
await this.storageService.deleteBlob(blobName);

// adds history item
addHistoryItemForRevertUacApproval(user, location);

const saveResult = await toBeUpdated.save();
await this.eventEngineService.handleProposalRevertUacApproval(saveResult, revert.value, user.miiLocation);
}

async initContracting(
proposalId: string,
Expand Down
8 changes: 8 additions & 0 deletions src/modules/proposal/utils/add-location-vote.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ConditionalApproval } from '../schema/sub-schema/conditional-approval.s
import { UacApproval } from '../schema/sub-schema/uac-approval.schema';
import { addFdpgTaskAndReturnId, removeFdpgTask } from './add-fdpg-task.util';
import { clearLocationsVotes } from './location-flow.util';
import { RevertUacApprovalDto } from '../dto/revert-uac-approval.dto';

export const addDizApproval = (proposal: Proposal, user: IRequestUser, vote: SetDizApprovalDto) => {
clearLocationsVotes(proposal, user.miiLocation);
Expand Down Expand Up @@ -141,3 +142,10 @@ export const addUacConditionReview = (
proposal.requestedButExcludedLocations.push(condition.location);
}
};

export const addRevertUacApproval = (proposal: Proposal, user: IRequestUser, revert: RevertUacApprovalDto) => {
clearLocationsVotes(proposal, user.miiLocation);
if (revert.value) {
proposal.requestedButExcludedLocations.push(user.miiLocation);
}
};
4 changes: 4 additions & 0 deletions src/modules/proposal/utils/location-flow.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import { ConditionalApproval } from '../schema/sub-schema/conditional-approval.s
import { UacApproval } from '../schema/sub-schema/uac-approval.schema';
import { addHistoryItemForContractSystemReject, addHistoryItemForUacCondition } from './proposal-history.util';
import { excludeUnselectedLocations } from './unselect-approved-location.util';
import { filter } from 'rxjs';

export const clearLocationsVotes = (proposal: Proposal, location: MiiLocation) => {
proposal.openDizChecks = proposal.openDizChecks.filter((filterLocation) => filterLocation !== location);
proposal.dizApprovedLocations = proposal.dizApprovedLocations.filter((filterLocation) => filterLocation !== location);
proposal.uacApprovedLocations = proposal.uacApprovedLocations.filter((filterLocation) => filterLocation !== location);
proposal.revertUacApprovalLocations = proposal.revertUacApprovalLocations.filter(
(filterLocation) => filterLocation !== location,
);
proposal.signedContracts = proposal.signedContracts.filter((filterLocation) => filterLocation !== location);
proposal.requestedButExcludedLocations = proposal.requestedButExcludedLocations.filter(
(filterLocation) => filterLocation !== location,
Expand Down
8 changes: 8 additions & 0 deletions src/modules/proposal/utils/proposal-history.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export const addHistoryItemForStatus = (
case ProposalStatus.LocationCheck:
type = HistoryEventType.ProposalLocationCheck;
break;
case ProposalStatus.UacApprovalReverted:
type = HistoryEventType.ProposalUacApprovalReverted;
case ProposalStatus.Contracting:
type = HistoryEventType.ProposalContracting;
break;
Expand Down Expand Up @@ -131,6 +133,12 @@ export const addHistoryItemForUnselectedLocation = (
pushHistoryItem(proposalAfterChanges, user, type, location);
};

export const addHistoryItemForRevertUacApproval = (user: IRequestUser, location: MiiLocation): void => {
const type = HistoryEventType.ProposalUacApprovalReverted;

pushHistoryItem(user, type, location);
};

export const addHistoryItemForContractSign = (
proposalAfterChanges: Proposal,
user: IRequestUser,
Expand Down

0 comments on commit 7ee0993

Please sign in to comment.