From f2c968150219ced545fe0b16ffbbd5290f4247e9 Mon Sep 17 00:00:00 2001 From: Aleksandra Frost Date: Thu, 11 Apr 2024 11:20:12 +0200 Subject: [PATCH] [ADD] rename uac approval to location decision --- .../proposal-contracting.controller.ts | 16 +++++------ ...dto.ts => revert-location-decision.dto.ts} | 8 ++---- .../proposal/schema/proposal.schema.ts | 3 -- .../proposal-contracting.service.spec.ts | 2 +- .../services/proposal-contracting.service.ts | 28 +++++++++---------- .../__tests__/add-location-vote.util.spec.ts | 2 +- ...e.util.ts => handle-location-vote.util.ts} | 23 +++++++++++---- .../proposal/utils/location-flow.util.ts | 3 -- .../proposal/utils/proposal-history.util.ts | 2 +- .../proposal/utils/validate-vote.util.ts | 2 ++ 10 files changed, 46 insertions(+), 43 deletions(-) rename src/modules/proposal/dto/{revert-uac-approval.dto.ts => revert-location-decision.dto.ts} (58%) rename src/modules/proposal/utils/{add-location-vote.util.ts => handle-location-vote.util.ts} (89%) diff --git a/src/modules/proposal/controller/proposal-contracting.controller.ts b/src/modules/proposal/controller/proposal-contracting.controller.ts index 68c5634..81f931e 100644 --- a/src/modules/proposal/controller/proposal-contracting.controller.ts +++ b/src/modules/proposal/controller/proposal-contracting.controller.ts @@ -25,7 +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 { RevertLocationDecisionDto } from '../dto/revert-location-decision.dto'; import { SignContractDto, SignContractWithFileDto } from '../dto/sign-contract.dto'; import { InitContractingDto } from '../dto/proposal/init-contracting.dto'; @@ -68,19 +68,19 @@ export class ProposalContractingController { } @Auth(Role.FdpgMember) - @Put(':id/revertUacApproval') // PUT or POST? - @UsePipes(ValidationPipe) // ValidationPipe? + @Put(':id/revertLocationDecision') + @UsePipes(ValidationPipe) @ApiNotFoundResponse({ description: 'Proposal could not be found' }) - @ApiOperation({ summary: 'Reverts the UAC Approval' }) - @ApiNoContentResponse({ description: 'UAC Approval reverted. No content returns.' }) + @ApiOperation({ summary: 'Reverts the Location Decision' }) + @ApiNoContentResponse({ description: 'Location Devision reverted. No content returns.' }) @HttpCode(204) - @ApiBody({ type: RevertUacApprovalDto }) + @ApiBody({ type: RevertLocationDecisionDto }) async revertUacApproval( @Param() { id }: MongoIdParamDto, - @Body() vote: RevertUacApprovalDto, + @Body() vote: RevertLocationDecisionDto, @Request() { user }: FdpgRequest, ): Promise { - return await this.proposalContractingService.revertUacApproval(id, vote, user, location); + return await this.proposalContractingService.revertLocationDecision(id, vote, user); } @Auth(Role.FdpgMember) diff --git a/src/modules/proposal/dto/revert-uac-approval.dto.ts b/src/modules/proposal/dto/revert-location-decision.dto.ts similarity index 58% rename from src/modules/proposal/dto/revert-uac-approval.dto.ts rename to src/modules/proposal/dto/revert-location-decision.dto.ts index 83c4d79..e113541 100644 --- a/src/modules/proposal/dto/revert-uac-approval.dto.ts +++ b/src/modules/proposal/dto/revert-location-decision.dto.ts @@ -1,13 +1,9 @@ import { Exclude, Expose } from 'class-transformer'; -import { IsBoolean, IsEnum } from 'class-validator'; +import { IsEnum } from 'class-validator'; import { MiiLocation } from 'src/shared/constants/mii-locations'; @Exclude() -export class RevertUacApprovalDto { - @Expose() - @IsBoolean() - value: boolean; - +export class RevertLocationDecisionDto { @Expose() @IsEnum(MiiLocation) location: MiiLocation; diff --git a/src/modules/proposal/schema/proposal.schema.ts b/src/modules/proposal/schema/proposal.schema.ts index 24e7ef4..21bd159 100644 --- a/src/modules/proposal/schema/proposal.schema.ts +++ b/src/modules/proposal/schema/proposal.schema.ts @@ -170,9 +170,6 @@ export class Proposal { @Prop([String]) uacApprovedLocations: MiiLocation[]; - @Prop([String]) - revertUacApprovalLocations: MiiLocation[]; - @Prop([String]) requestedButExcludedLocations: MiiLocation[]; diff --git a/src/modules/proposal/services/__tests__/proposal-contracting.service.spec.ts b/src/modules/proposal/services/__tests__/proposal-contracting.service.spec.ts index e78f3f9..9596ae9 100644 --- a/src/modules/proposal/services/__tests__/proposal-contracting.service.spec.ts +++ b/src/modules/proposal/services/__tests__/proposal-contracting.service.spec.ts @@ -10,7 +10,7 @@ import { SignContractDto } from '../../dto/sign-contract.dto'; import { ProposalStatus } from '../../enums/proposal-status.enum'; import { ProposalDocument } from '../../schema/proposal.schema'; import { addContractSign } from '../../utils/add-contract-sign.util'; -import { addDizApproval, addUacApproval, addUacApprovalWithCondition } from '../../utils/add-location-vote.util'; +import { addDizApproval, addUacApproval, addUacApprovalWithCondition } from '../../utils/handle-location-vote.util'; import { addHistoryItemForContractSign, addHistoryItemForDizApproval, diff --git a/src/modules/proposal/services/proposal-contracting.service.ts b/src/modules/proposal/services/proposal-contracting.service.ts index 23d3413..5b535d2 100644 --- a/src/modules/proposal/services/proposal-contracting.service.ts +++ b/src/modules/proposal/services/proposal-contracting.service.ts @@ -8,7 +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 { RevertLocationDecisionDto } from '../dto/revert-location-decision.dto'; import { SignContractDto } from '../dto/sign-contract.dto'; import { UploadDto } from '../dto/upload.dto'; import { ProposalValidation } from '../enums/porposal-validation.enum'; @@ -22,8 +22,8 @@ import { addUacApproval, addUacApprovalWithCondition, addUacConditionReview, - addRevertUacApproval, -} from '../utils/add-location-vote.util'; + addRevertLocationDecision, +} from '../utils/handle-location-vote.util'; import { addHistoryItemForContractSign, addHistoryItemForDizApproval, @@ -89,28 +89,26 @@ export class ProposalContractingService { await this.eventEngineService.handleProposalUacApproval(saveResult, vote.value, user.miiLocation); } - async revertUacApproval( + async revertLocationDecision( proposalId: string, - revert: RevertUacApprovalDto, + revert: RevertLocationDecisionDto, user: IRequestUser, - location: RevertUacApprovalDto, ): Promise { - // condition "if revert === true" needed? + //[TODO] validateRevertUacApproval - //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); + // was machen wir rückgängig? (schema - totalPromisedDataAmount, den Rest rückgängig machen) + // Absage - kein Upload - Absagegrund löschen + // Zusage - kein Upload + // Zusage unter Auflagen - Upload - und nur dann blob löschen // adds history item - addHistoryItemForRevertUacApproval(user, location); + // addHistoryItemForRevertUacApproval(user, location); + // addRevertLocationDecision(proposalId, user, revert); const saveResult = await toBeUpdated.save(); - await this.eventEngineService.handleProposalRevertUacApproval(saveResult, revert.value, user.miiLocation); + // await this.eventEngineService.handleProposalRevertUacApproval(saveResult, location, user.miiLocation); } async initContracting( diff --git a/src/modules/proposal/utils/__tests__/add-location-vote.util.spec.ts b/src/modules/proposal/utils/__tests__/add-location-vote.util.spec.ts index 0d2095e..18f9012 100644 --- a/src/modules/proposal/utils/__tests__/add-location-vote.util.spec.ts +++ b/src/modules/proposal/utils/__tests__/add-location-vote.util.spec.ts @@ -14,7 +14,7 @@ import { addUacApproval, addUacApprovalWithCondition, addUacConditionReview, -} from '../add-location-vote.util'; +} from '../handle-location-vote.util'; import { clearLocationsVotes } from '../location-flow.util'; jest.mock('../location-flow.util', () => ({ diff --git a/src/modules/proposal/utils/add-location-vote.util.ts b/src/modules/proposal/utils/handle-location-vote.util.ts similarity index 89% rename from src/modules/proposal/utils/add-location-vote.util.ts rename to src/modules/proposal/utils/handle-location-vote.util.ts index cecc7dc..aed2a28 100644 --- a/src/modules/proposal/utils/add-location-vote.util.ts +++ b/src/modules/proposal/utils/handle-location-vote.util.ts @@ -11,10 +11,11 @@ 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'; +import { RevertLocationDecisionDto } from '../dto/revert-location-decision.dto'; export const addDizApproval = (proposal: Proposal, user: IRequestUser, vote: SetDizApprovalDto) => { clearLocationsVotes(proposal, user.miiLocation); + if (vote.value === true) { proposal.dizApprovedLocations.push(user.miiLocation); } else { @@ -34,17 +35,22 @@ export const addDizApproval = (proposal: Proposal, user: IRequestUser, vote: Set export const addUacApproval = (proposal: Proposal, user: IRequestUser, vote: SetUacApprovalDto) => { clearLocationsVotes(proposal, user.miiLocation); + if (vote.value === true) { const uacApproval: Omit = { location: user.miiLocation, dataAmount: vote.dataAmount, isContractSigned: false, }; + // Flow: proposal.uacApprovedLocations.push(user.miiLocation); // Persistent: proposal.uacApprovals.push(uacApproval as UacApproval); + console.log('---------'); + console.log('_____BEFORE_______proposal.totalPromisedDataAmount ' + proposal.totalPromisedDataAmount); proposal.totalPromisedDataAmount = (proposal.totalPromisedDataAmount ?? 0) + (vote.dataAmount ?? 0); + console.log('_____AFTER_______proposal.totalPromisedDataAmount ' + proposal.totalPromisedDataAmount); const isDataAmountReached = proposal.totalPromisedDataAmount >= (proposal.requestedData.desiredDataAmount ?? 0); if (isDataAmountReached) { @@ -143,9 +149,16 @@ export const addUacConditionReview = ( } }; -export const addRevertUacApproval = (proposal: Proposal, user: IRequestUser, revert: RevertUacApprovalDto) => { - clearLocationsVotes(proposal, user.miiLocation); - if (revert.value) { - proposal.requestedButExcludedLocations.push(user.miiLocation); +export const addRevertLocationDecision = ( + proposal: Proposal, + location: MiiLocation, + revert: RevertLocationDecisionDto, +) => { + clearLocationsVotes(proposal, location); + if (revert) { + proposal.requestedButExcludedLocations.push(location); } }; + +// revert absage auch +// umbennen handle-location-vote diff --git a/src/modules/proposal/utils/location-flow.util.ts b/src/modules/proposal/utils/location-flow.util.ts index c7681a6..61b1b2e 100644 --- a/src/modules/proposal/utils/location-flow.util.ts +++ b/src/modules/proposal/utils/location-flow.util.ts @@ -12,9 +12,6 @@ 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, diff --git a/src/modules/proposal/utils/proposal-history.util.ts b/src/modules/proposal/utils/proposal-history.util.ts index 902607b..fee99c9 100644 --- a/src/modules/proposal/utils/proposal-history.util.ts +++ b/src/modules/proposal/utils/proposal-history.util.ts @@ -136,7 +136,7 @@ export const addHistoryItemForUnselectedLocation = ( export const addHistoryItemForRevertUacApproval = (user: IRequestUser, location: MiiLocation): void => { const type = HistoryEventType.ProposalUacApprovalReverted; - pushHistoryItem(user, type, location); + // pushHistoryItem(user, type, location); }; export const addHistoryItemForContractSign = ( diff --git a/src/modules/proposal/utils/validate-vote.util.ts b/src/modules/proposal/utils/validate-vote.util.ts index b74a7df..dc8a3cf 100644 --- a/src/modules/proposal/utils/validate-vote.util.ts +++ b/src/modules/proposal/utils/validate-vote.util.ts @@ -22,3 +22,5 @@ export const validateUacApproval = (proposal: Proposal, user: IRequestUser) => { throw new ForbiddenException('The location is not allowed to provide a vote. It might have already voted'); } }; + +// forbiddenexception ?