Skip to content

Commit

Permalink
[ADD] rename uac approval to location decision
Browse files Browse the repository at this point in the history
  • Loading branch information
af-ofr committed Apr 11, 2024
1 parent 7ee0993 commit f2c9681
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<void> {
return await this.proposalContractingService.revertUacApproval(id, vote, user, location);
return await this.proposalContractingService.revertLocationDecision(id, vote, user);
}

@Auth(Role.FdpgMember)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/modules/proposal/schema/proposal.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ export class Proposal {
@Prop([String])
uacApprovedLocations: MiiLocation[];

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 13 additions & 15 deletions src/modules/proposal/services/proposal-contracting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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<void> {
// 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<UacApproval, '_id' | 'createdAt' | 'signedAt' | 'signedByOwnerId'> = {
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) {
Expand Down Expand Up @@ -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
3 changes: 0 additions & 3 deletions src/modules/proposal/utils/location-flow.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/proposal/utils/proposal-history.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
2 changes: 2 additions & 0 deletions src/modules/proposal/utils/validate-vote.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?

0 comments on commit f2c9681

Please sign in to comment.