Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
af-egr committed Jan 21, 2025
1 parent a3cd07d commit 05865ca
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 23 deletions.
10 changes: 8 additions & 2 deletions src/modules/proposal/dto/proposal/conditional-approval.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ export class ConditionalApprovalGetDto {
@Expose()
isAccepted: boolean;

@Expose()
isDizAccepted: boolean;

@Expose()
isContractSigned?: boolean;

@Expose()
dataAmount: number;

@Expose({ groups: [Role.FdpgMember] })
uploadId: string;
@Expose({ groups: [Role.FdpgMember, Role.DizMember] })
uploadId?: string;

@Expose()
conditionalReasoning?: string;

@ExposeId()
_id: string;
Expand Down
5 changes: 4 additions & 1 deletion src/modules/proposal/dto/proposal/proposal.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ export class ProposalGetDto extends ProposalBaseDto {
@Expose({ groups: [Role.FdpgMember, Role.Researcher] })
uacApprovedLocations: MiiLocation[];

@Expose({ groups: [Role.FdpgMember, Role.Researcher] })
dizConditionApprovedLocations: MiiLocation[];

@Expose({ groups: [Role.FdpgMember, Role.Researcher] })
requestedButExcludedLocations: MiiLocation[];

Expand All @@ -218,7 +221,7 @@ export class ProposalGetDto extends ProposalBaseDto {

// Conditional and UAC approval are stored additionally to the "flow-arrays" and are persistent

@Expose({ groups: [Role.FdpgMember, Role.Researcher] })
@Expose({ groups: [Role.FdpgMember, Role.Researcher, Role.DizMember] })
@Type(() => ConditionalApprovalGetDto)
conditionalApprovals: ConditionalApprovalGetDto[];

Expand Down
4 changes: 4 additions & 0 deletions src/modules/proposal/dto/set-uac-approval.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class SetUacApprovalDto {
})
dataAmount?: number;

@Expose()
@MaxLength(10_000)
conditionReasoning?: string;

@Expose()
@ValidateIf((obj: SetUacApprovalDto) => obj.value === false)
@IsNotEmptyString()
Expand Down
1 change: 1 addition & 0 deletions src/modules/proposal/enums/location-state.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum LocationState {
IsDizCheck = 'DIZ_CHECK',
DizApproved = 'DIZ_APPROVED',
UacApproved = 'UAC_APPROVED',
DizConditionApproved = 'DIZ_CONDITION_APPROVED',
SignedContract = 'SIGNED_CONTRACT',
SignedContractAndContractingDone = 'SIGNED_CONTRACT_AND_CONTRACTING_DONE',
RequestedButExcluded = 'REQUESTED_BUT_EXCLUDED',
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])
dizConditionApprovedLocations: MiiLocation[];

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,26 @@ export class ConditionalApproval {
})
isAccepted: boolean;

@Prop({
type: Boolean,
default: false,
})
isDizAccepted: boolean;

@Prop()
isContractSigned: boolean;

@Prop()
dataAmount: number;

@Prop()
uploadId: string;
uploadId?: string;

@Prop()
conditionalReasoning?: string;

@Prop()
fdpgTaskId: string;
fdpgTaskId?: string;

_id: string;

Expand Down
22 changes: 16 additions & 6 deletions src/modules/proposal/services/proposal-contracting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,24 @@ export class ProposalContractingService {
const toBeUpdated = await this.proposalCrudService.findDocument(proposalId, user, undefined, true);

validateUacApproval(toBeUpdated, user);
const hasCondition = !!file?.buffer && vote.value;
const hasCondition = vote.value && (!!file?.buffer || !!vote.conditionReasoning);

if (hasCondition) {
const blobName = getBlobName(toBeUpdated.id, UseCaseUpload.ContractCondition);
await this.storageService.uploadFile(blobName, file, user);
const upload = new UploadDto(blobName, file, UseCaseUpload.ContractCondition, user);
addUpload(toBeUpdated, upload);
addUacApprovalWithCondition(toBeUpdated, user.miiLocation, upload, vote);
const upload: UploadDto | undefined = await (async () => {
if (!!file?.buffer) {
const blobName = getBlobName(toBeUpdated.id, UseCaseUpload.ContractCondition);
await this.storageService.uploadFile(blobName, file, user);
const upload = new UploadDto(blobName, file, UseCaseUpload.ContractCondition, user);
addUpload(toBeUpdated, upload);
return upload;
} else {
return;
}
})();

console.log({ upload });

addUacApprovalWithCondition(toBeUpdated, user.miiLocation, vote, upload, vote.conditionReasoning);
} else {
addUacApproval(toBeUpdated, user, vote);
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/proposal/services/status-change.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class StatusChangeService {

proposalAfterChanges.statusChangeToLocationCheckAt = new Date();

scheduleTypesToRemove.push(ScheduleType.ReminderFdpgCheck);
//scheduleTypesToRemove.push(ScheduleType.ReminderFdpgCheck);
scheduleTypesToAdd.push(
ScheduleType.ReminderLocationCheck1,
ScheduleType.ReminderLocationCheck2,
Expand Down
23 changes: 15 additions & 8 deletions src/modules/proposal/utils/add-location-vote.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ export const addUacApproval = (proposal: Proposal, user: IRequestUser, vote: Set
proposal.uacApprovals.push(uacApproval as UacApproval);
proposal.totalPromisedDataAmount = (proposal.totalPromisedDataAmount ?? 0) + (vote.dataAmount ?? 0);

/*
const isDataAmountReached = proposal.totalPromisedDataAmount >= (proposal.requestedData.desiredDataAmount ?? 0);
if (isDataAmountReached) {
addFdpgTaskAndReturnId(proposal, FdpgTaskType.DataAmountReached);
}
*/
} else {
proposal.requestedButExcludedLocations.push(user.miiLocation);
proposal.declineReasons = [
Expand All @@ -78,10 +80,11 @@ export const addUacApproval = (proposal: Proposal, user: IRequestUser, vote: Set
export const addUacApprovalWithCondition = (
proposal: Proposal,
location: MiiLocation,
upload: UploadDto,
vote: SetUacApprovalDto,
upload?: UploadDto,
conditionalReasoning?: string,
) => {
const fdpgTaskId = addFdpgTaskAndReturnId(proposal, FdpgTaskType.ConditionApproval);
//const fdpgTaskId = addFdpgTaskAndReturnId(proposal, FdpgTaskType.ConditionApproval);

const conditionalApproval: Omit<
ConditionalApproval,
Expand All @@ -92,9 +95,13 @@ export const addUacApprovalWithCondition = (
uploadId: upload._id,
dataAmount: vote.dataAmount,
isContractSigned: false,
fdpgTaskId,
conditionalReasoning: conditionalReasoning,
isDizAccepted: false,
//fdpgTaskId,
};

console.log({ conditionalApproval });

if (proposal.conditionalApprovals) {
proposal.conditionalApprovals.push(conditionalApproval as ConditionalApproval);
} else {
Expand All @@ -111,12 +118,12 @@ export const addUacApprovalWithCondition = (
proposal.requestedButExcludedLocations.push(location);
}

const isUacApprovalComplete =
/*const isUacApprovalComplete =
proposal.uacApprovedLocations.length + proposal.requestedButExcludedLocations.length ===
proposal.numberOfRequestedLocations;
if (isUacApprovalComplete) {
addFdpgTaskAndReturnId(proposal, FdpgTaskType.UacApprovalComplete);
}
}*/
};

export const addUacConditionReview = (
Expand All @@ -129,18 +136,18 @@ export const addUacConditionReview = (
condition.reviewedAt = new Date();
condition.reviewedByOwnerId = user.userId;

removeFdpgTask(proposal, condition.fdpgTaskId);
//removeFdpgTask(proposal, condition.fdpgTaskId);

clearLocationsVotes(proposal, condition.location);
if (vote === true) {
proposal.totalPromisedDataAmount = (proposal.totalPromisedDataAmount ?? 0) + (condition.dataAmount ?? 0);
// Flow
proposal.uacApprovedLocations.push(condition.location);

const isDataAmountReached = proposal.totalPromisedDataAmount >= (proposal.requestedData.desiredDataAmount ?? 0);
/*const isDataAmountReached = proposal.totalPromisedDataAmount >= (proposal.requestedData.desiredDataAmount ?? 0);
if (isDataAmountReached) {
addFdpgTaskAndReturnId(proposal, FdpgTaskType.DataAmountReached);
}
} */
} else {
// Flow
proposal.requestedButExcludedLocations.push(condition.location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ export const getFilterForDiz = (panelQuery: PanelQuery, user: IRequestUser): Fil

const getFilterForRequested = (user: IRequestUser): FilterQuery<Proposal> => {
return {
status: ProposalStatus.LocationCheck,
openDizChecks: user.miiLocation,
$and: [
{
status: ProposalStatus.LocationCheck,
},
{
$or: [{ openDizChecks: user.miiLocation }, { uacApprovedLocations: user.miiLocation }],
},
],
};
};

Expand All @@ -47,7 +53,7 @@ const getFilterForPending = (user: IRequestUser): FilterQuery<Proposal> => {
$in: [ProposalStatus.LocationCheck, ProposalStatus.Contracting],
},
},
{ $or: [{ dizApprovedLocations: user.miiLocation }, { uacApprovedLocations: user.miiLocation }] },
{ $or: [{ dizApprovedLocations: user.miiLocation }] },
],
};
};
Expand Down

0 comments on commit 05865ca

Please sign in to comment.