Passed
Push — feature/azure-webapp-pipeline-... ( 53eaa8...7fdaeb )
by Grant
04:42
created

resources/assets/js/models/jobUtil.ts   A

Complexity

Total Complexity 4
Complexity/F 0

Size

Lines of Code 224
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 194
mnd 4
bc 4
fnc 0
dl 0
loc 224
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
/* eslint-disable camelcase */
2
import { MessageDescriptor } from "react-intl";
3
import {
4
  Job,
5
  JobPosterKeyTask,
6
  Criteria,
7
  Skill,
8
  Comment,
9
  JobPosterStatus,
10
} from "./types";
11
import { CriteriaTypeId, JobStatus, LocationId } from "./lookupConstants";
12
import { assetSkillName, skillLevelName } from "./localizedConstants";
13
import {
14
  jobBuilderDetails,
15
  jobBuilderEnv,
16
  jobBuilderImpact,
17
  jobBuilderSkills,
18
  jobBuilderReview,
19
  hrJobReview,
20
  hrScreeningPlan,
21
  managerScreeningPlan,
22
  hrJobSummary,
23
  hrJobPreview,
24
  jobBuilderTasks,
25
  managerJobPreview,
26
  hrJobApplications,
27
  managerJobApplications,
28
  managerJobSummary,
29
} from "../helpers/routes";
30
import { hasKey } from "../helpers/queries";
31
32
const pad = (n: number, width: number, z = "0"): string => {
33
  return (String(z).repeat(width) + String(n)).slice(String(n).length);
34
};
35
36
export const classificationString = (
37
  classificationKey: string,
38
  job: Job,
39
): string => {
40
  return classificationKey && job.classification_id && job.classification_level
41
    ? `${classificationKey}-${pad(job.classification_level, 2)}`
42
    : "";
43
};
44
45
export const emptyJob = (): Job => {
46
  return {
47
    id: 0,
48
    manager_id: 0,
49
    chosen_lang: null,
50
    term_qty: null,
51
    open_date_time: null,
52
    close_date_time: null,
53
    start_date_time: null,
54
    department_id: null,
55
    job_poster_status_id: 1,
56
    province_id: null,
57
    salary_min: null,
58
    salary_max: null,
59
    noc: null,
60
    classification_id: null,
61
    classification_level: null,
62
    security_clearance_id: null,
63
    language_requirement_id: null,
64
    remote_work_allowed: true,
65
    submitted_applications_count: null,
66
    team_size: null,
67
    work_env_features: null,
68
    fast_vs_steady: null,
69
    horizontal_vs_vertical: null,
70
    experimental_vs_ongoing: null,
71
    citizen_facing_vs_back_office: null,
72
    collaborative_vs_independent: null,
73
    telework_allowed_frequency_id: null,
74
    flexible_hours_frequency_id: null,
75
    travel_requirement_id: null,
76
    overtime_requirement_id: null,
77
    created_at: new Date(),
78
    city: {
79
      en: "",
80
      fr: "",
81
    },
82
    title: {
83
      en: "",
84
      fr: "",
85
    },
86
    dept_impact: {
87
      en: "",
88
      fr: "",
89
    },
90
    team_impact: {
91
      en: "",
92
      fr: "",
93
    },
94
    hire_impact: {
95
      en: "",
96
      fr: "",
97
    },
98
    division: {
99
      en: "",
100
      fr: "",
101
    },
102
    education: {
103
      en: "",
104
      fr: "",
105
    },
106
    work_env_description: {
107
      en: "",
108
      fr: "",
109
    },
110
    culture_summary: {
111
      en: "",
112
      fr: "",
113
    },
114
    culture_special: {
115
      en: "",
116
      fr: "",
117
    },
118
  };
119
};
120
121
export const emptyTasks = (): JobPosterKeyTask[] => [
122
  {
123
    id: 0,
124
    job_poster_id: 0,
125
    description: {
126
      en: "",
127
      fr: "",
128
    },
129
  },
130
];
131
132
export const getSkillLevelName = (
133
  { skill_level_id, criteria_type_id }: Criteria,
134
  { skill_type_id }: Skill,
135
): MessageDescriptor => {
136
  if (criteria_type_id === CriteriaTypeId.Asset) {
137
    return assetSkillName();
138
  }
139
  return skillLevelName(skill_level_id, skill_type_id);
140
};
141
142
export const emptyComment = (): Comment => ({
143
  id: 0,
144
  job_poster_id: 0,
145
  user_id: 0,
146
  comment: "",
147
  location: "",
148
  type_id: null,
149
  created_at: new Date(),
150
});
151
152
export const emptyJobPosterStatus = (): JobPosterStatus => ({
153
  id: 1,
154
  key: JobStatus.Draft,
155
  name: { en: "Draft", fr: "Provisoire" },
156
  description: {
157
    en: "This is a draft.",
158
    fr: "Il s'agit d'un premier projet.",
159
  },
160
});
161
162
export const activityLocationUrl = (
163
  isHrAdvisor: boolean,
164
  location: string,
165
  jobId: number,
166
  locale: string,
167
): string => {
168
  const hrAdvisorUrls = {
169
    /* Job Poster Review Page */
170
    [LocationId.jobGeneric]: hrJobReview(locale, jobId),
171
    [LocationId.heading]: hrJobReview(locale, jobId),
172
    [LocationId.basicInfo]: hrJobReview(locale, jobId),
173
    [LocationId.impact]: hrJobReview(locale, jobId),
174
    [LocationId.tasks]: hrJobReview(locale, jobId),
175
    [LocationId.skills]: hrJobReview(locale, jobId),
176
    [LocationId.langRequirements]: hrJobReview(locale, jobId),
177
    [LocationId.environment]: hrJobReview(locale, jobId),
178
179
    /* Applicant Review Page */
180
    [LocationId.applicantsGeneric]: hrJobApplications(locale, jobId),
181
    [LocationId.underConsideration]: hrJobApplications(locale, jobId),
182
    [LocationId.optionalConsideration]: hrJobApplications(locale, jobId),
183
    [LocationId.notUnderConsideration]: hrJobApplications(locale, jobId),
184
185
    /* Screening Plan Builder */
186
    [LocationId.screeningPlan]: hrScreeningPlan(locale, jobId),
187
    [LocationId.screeningPlanBuilder]: hrScreeningPlan(locale, jobId),
188
    [LocationId.screeningPlanSummary]: hrScreeningPlan(locale, jobId),
189
    [LocationId.screeningPlanRatings]: hrScreeningPlan(locale, jobId),
190
191
    [LocationId.summary]: hrJobSummary(locale, jobId),
192
    [LocationId.preview]: hrJobPreview(locale, jobId),
193
  };
194
  const managerUrls = {
195
    /* Job Poster Review Page */
196
    [LocationId.jobGeneric]: jobBuilderReview(locale, jobId),
197
    [LocationId.heading]: jobBuilderDetails(locale, jobId),
198
    [LocationId.basicInfo]: jobBuilderDetails(locale, jobId),
199
    [LocationId.impact]: jobBuilderImpact(locale, jobId),
200
    [LocationId.tasks]: jobBuilderTasks(locale, jobId),
201
    [LocationId.skills]: jobBuilderSkills(locale, jobId),
202
    [LocationId.langRequirements]: jobBuilderDetails(locale, jobId),
203
    [LocationId.environment]: jobBuilderEnv(locale, jobId),
204
205
    /* Applicant Review Page */
206
    [LocationId.applicantsGeneric]: managerJobApplications(locale, jobId),
207
    [LocationId.underConsideration]: managerJobApplications(locale, jobId),
208
    [LocationId.optionalConsideration]: managerJobApplications(locale, jobId),
209
    [LocationId.notUnderConsideration]: managerJobApplications(locale, jobId),
210
211
    /* Screening Plan Builder */
212
    [LocationId.screeningPlan]: managerScreeningPlan(locale, jobId),
213
    [LocationId.screeningPlanBuilder]: managerScreeningPlan(locale, jobId),
214
    [LocationId.screeningPlanSummary]: managerScreeningPlan(locale, jobId),
215
    [LocationId.screeningPlanRatings]: managerScreeningPlan(locale, jobId),
216
217
    [LocationId.summary]: managerJobSummary(locale, jobId),
218
    [LocationId.preview]: managerJobPreview(locale, jobId),
219
  };
220
  const urlMap = isHrAdvisor ? hrAdvisorUrls : managerUrls;
221
  const backupUrl = "/";
222
  return hasKey(urlMap, location) ? urlMap[location] : backupUrl;
223
};
224