120 lines
3.1 KiB
JavaScript
120 lines
3.1 KiB
JavaScript
const {
|
|
getAvailableRepresentationTypes
|
|
} = require("../../../../lib/domain/representation-type-policy/getAvailableRepresentationTypes");
|
|
|
|
export const APPEAL_TYPES = {
|
|
SIPS: 846040002,
|
|
DNS: 846040011,
|
|
HOUSEHOLDER: 846040004,
|
|
ADVERT: 846040018,
|
|
EXCLUDE_QUESTIONNAIRE_1: 846040019,
|
|
EXCLUDE_QUESTIONNAIRE_2: 846040015,
|
|
EXCLUDE_QUESTIONNAIRE_3: 846040016
|
|
};
|
|
|
|
export const SPECIALIST_PROCESS = {
|
|
WRITTEN_REPS: 846040000,
|
|
HEARING: 846040001
|
|
};
|
|
|
|
export const INVOLVEMENT_TYPES = {
|
|
LPA: 846040012
|
|
};
|
|
|
|
export const REPRESENTATION_OPTIONS = {
|
|
QUESTIONNAIRE: "Questionnaire",
|
|
STATEMENT: "Statement",
|
|
FINAL_COMMENTS: "Final comments",
|
|
CONSULTATION_RESPONSE: "Consultation Response",
|
|
LOCAL_IMPACT_REPORT: "Local Impact Report",
|
|
MARINE_IMPACT_REPORT: "Marine Impact Report"
|
|
};
|
|
|
|
const isValidDate = (date) =>
|
|
date instanceof Date && !Number.isNaN(date.getTime());
|
|
|
|
const toDateOrNull = (value) => {
|
|
const date = new Date(value);
|
|
return isValidDate(date) ? date : null;
|
|
};
|
|
|
|
const endOfDay = (date) => {
|
|
if (!isValidDate(date)) return null;
|
|
const next = new Date(date);
|
|
next.setHours(23, 59, 59, 999);
|
|
return next;
|
|
};
|
|
|
|
const isWithinWindow = (now, start, end) => {
|
|
if (!isValidDate(now) || !isValidDate(start) || !isValidDate(end)) {
|
|
return false;
|
|
}
|
|
return now >= start && now <= end;
|
|
};
|
|
|
|
const normalizeCapacity = (value) =>
|
|
(value || "")
|
|
.toString()
|
|
.toLowerCase()
|
|
.replace(/(\band|[\s\-\+\(\)\,\&])/g, "");
|
|
|
|
export const buildRepresentationContext = ({
|
|
detailsObj = {},
|
|
appealType,
|
|
specialistProcess,
|
|
involvementType,
|
|
selectedCapacity,
|
|
isCaseOwner,
|
|
isNRW,
|
|
now = new Date()
|
|
}) => {
|
|
const isDNS = appealType === APPEAL_TYPES.DNS;
|
|
|
|
const startDate = toDateOrNull(
|
|
isDNS
|
|
? detailsObj.pinswg_applicationacceptedasvalid
|
|
: detailsObj.pinswg_startdate || detailsObj.pinswg_startdates
|
|
);
|
|
|
|
const statementDueDate = endOfDay(
|
|
toDateOrNull(
|
|
isDNS
|
|
? detailsObj.pinswg_endofrepresentationperiod
|
|
: detailsObj.pinswg_statementduedate ||
|
|
detailsObj.pinswg_statementsduedate
|
|
)
|
|
);
|
|
|
|
const finalCommentsDueDate = endOfDay(
|
|
toDateOrNull(
|
|
isDNS
|
|
? detailsObj.pinswg_endofrepresentationperiod
|
|
: detailsObj.pinswg_finalcommentsduedate
|
|
)
|
|
);
|
|
|
|
const capacity = normalizeCapacity(selectedCapacity);
|
|
const isLPA = involvementType === INVOLVEMENT_TYPES.LPA;
|
|
|
|
return {
|
|
appealType,
|
|
specialistProcess,
|
|
isDNS,
|
|
isSIPS: appealType === APPEAL_TYPES.SIPS,
|
|
isLPA,
|
|
isNRW: !!isNRW,
|
|
isCaseOwner: !!isCaseOwner,
|
|
isSelectedAppellant: capacity === "appellant",
|
|
isSelectedAgent: capacity === "agent",
|
|
isSelectedInterestedParty: capacity === "interestedparty",
|
|
now,
|
|
startDate,
|
|
statementDueDate,
|
|
finalCommentsDueDate
|
|
};
|
|
};
|
|
|
|
export const buildRepsArrFromContext = (ctx) => {
|
|
return getAvailableRepresentationTypes(ctx);
|
|
};
|