Passed
Push — feature/data-request-hooks ( 562d87...7ed4d3 )
by Tristan
06:17
created

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

Complexity

Total Complexity 4
Complexity/F 0

Size

Lines of Code 230
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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