@ossy/consultancy 3.25.0 → 3.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/package.json +7 -5
- package/src/ConsultancyNav.jsx +6 -6
- package/src/CreateConsultancyButton.jsx +21 -7
- package/src/Forecast.jsx +38 -37
- package/src/RequestMatches.jsx +29 -19
- package/src/RequestStatsPanel.jsx +1 -1
- package/src/ResumeMatches.jsx +51 -0
- package/src/calendar-quarter-months.js +36 -0
- package/src/calendar-quarter-months.spec.js +22 -0
- package/src/create-company.flow.js +9 -9
- package/src/current-month.component.jsx +14 -25
- package/src/delete-company.flow.js +5 -5
- package/src/en.translations.json +17 -32
- package/src/extract-request.task.js +20 -13
- package/src/extract-request.task.spec.js +7 -3
- package/src/file-inbound-request.task.js +93 -0
- package/src/file-inbound-request.task.spec.js +118 -0
- package/src/forecast-figures.jsx +42 -0
- package/src/forecast-panels.jsx +31 -42
- package/src/index.js +0 -1
- package/src/intake-categories.js +6 -22
- package/src/kpi-trend.component.jsx +1 -1
- package/src/match-reasons.js +85 -0
- package/src/match-reasons.spec.js +73 -0
- package/src/match-resumes.js +12 -7
- package/src/match-resumes.spec.js +13 -8
- package/src/match-resumes.task.js +1 -22
- package/src/match-resumes.task.spec.js +19 -14
- package/src/{consultancy.page.jsx → overview.page.jsx} +7 -7
- package/src/refresh-matches.js +38 -0
- package/src/refresh-matches.spec.js +31 -1
- package/src/refresh-matches.task.js +322 -72
- package/src/refresh-matches.task.spec.js +229 -27
- package/src/request.schema.js +0 -1
- package/src/{resume-inbound-screening.task.js → resume-inbound-requests.task.js} +12 -14
- package/src/{resume-inbound-screening.task.spec.js → resume-inbound-requests.task.spec.js} +32 -18
- package/src/resumes.page.jsx +43 -12
- package/src/schema-ids.js +0 -1
- package/src/spend-for-month.js +72 -0
- package/src/spend-for-month.spec.js +49 -0
- package/src/spend-year.jsx +91 -0
- package/src/{org.page.jsx → spend.page.jsx} +14 -13
- package/src/sv.translations.json +17 -32
- package/src/use-chart-months.js +5 -2
- package/src/use-spend-by-month.js +52 -0
- package/src/utilization.component.jsx +1 -1
- package/src/view-forecasts.flow.js +3 -3
- package/src/year-totals.component.jsx +1 -1
- package/src/Overview.jsx +0 -91
- package/src/company-basic-info.schema.js +0 -25
- package/src/screen-inbound.task.js +0 -133
- package/src/screen-inbound.task.spec.js +0 -154
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { location as resumeLocation } from '@ossy/resumes/locations'
|
|
2
2
|
import { referenceId, referenceIds } from '@ossy/resumes/resume-links'
|
|
3
3
|
import { ResumesSchema } from '@ossy/resumes/schema-ids'
|
|
4
|
-
import { cosineSimilarity, getEmbedding,
|
|
4
|
+
import { cosineSimilarity, getEmbedding, searchEmbeddings, setEmbeddingKind } from '@ossy/platform/vector/vector-store'
|
|
5
5
|
import { ConsultancySchema } from './schema-ids.js'
|
|
6
6
|
import { location, matchesLocation } from './locations.js'
|
|
7
|
-
import { rankMatches, requestMatchText, resumeMatchText } from './match-resumes.js'
|
|
7
|
+
import { rankMatches, requestMatchText, resumeMatchText, resourceTags } from './match-resumes.js'
|
|
8
8
|
import {
|
|
9
|
+
MATCH_LIMIT,
|
|
9
10
|
PROFILE_SCHEMA,
|
|
11
|
+
caseInsensitiveTagFilter,
|
|
10
12
|
embeddingIsCurrent,
|
|
11
13
|
matchesEqual,
|
|
12
|
-
|
|
14
|
+
matchesToStore,
|
|
13
15
|
textHash,
|
|
14
16
|
} from './refresh-matches.js'
|
|
15
17
|
|
|
@@ -19,18 +21,25 @@ const CreateResource = { id: '@ossy/resources/actions/create' }
|
|
|
19
21
|
const UpdateContent = { id: '@ossy/resources/actions/update-content' }
|
|
20
22
|
const EmbedResource = { id: '@ossy/media-tasks/actions/embed-resource' }
|
|
21
23
|
|
|
24
|
+
const KIND_REQUEST = 'request'
|
|
25
|
+
const KIND_RESUME = 'resume'
|
|
26
|
+
const PAGE_SIZE = 50
|
|
27
|
+
|
|
22
28
|
export const metadata = {
|
|
23
29
|
id: '@ossy/consultancy/tasks/refresh-matches',
|
|
24
|
-
schedule: '*/5 * * * *',
|
|
25
30
|
triggers: [
|
|
26
31
|
{ type: ConsultancySchema.request, event: 'Created' },
|
|
27
32
|
{ type: ConsultancySchema.request, event: 'Updated' },
|
|
33
|
+
{ type: ConsultancySchema.request, event: 'Patched' },
|
|
28
34
|
{ type: ResumesSchema.resume, event: 'Created' },
|
|
29
35
|
{ type: ResumesSchema.resume, event: 'Updated' },
|
|
36
|
+
{ type: ResumesSchema.resume, event: 'Patched' },
|
|
30
37
|
{ type: PROFILE_SCHEMA, event: 'Created' },
|
|
31
38
|
{ type: PROFILE_SCHEMA, event: 'Updated' },
|
|
39
|
+
{ type: PROFILE_SCHEMA, event: 'Patched' },
|
|
32
40
|
{ type: ResumesSchema.resumeExperience, event: 'Created' },
|
|
33
41
|
{ type: ResumesSchema.resumeExperience, event: 'Updated' },
|
|
42
|
+
{ type: ResumesSchema.resumeExperience, event: 'Patched' },
|
|
34
43
|
],
|
|
35
44
|
}
|
|
36
45
|
|
|
@@ -51,6 +60,16 @@ function workspaceIdFrom ({ event, payload, req }) {
|
|
|
51
60
|
?? null
|
|
52
61
|
}
|
|
53
62
|
|
|
63
|
+
function mergeById (groups) {
|
|
64
|
+
const byId = new Map()
|
|
65
|
+
for (const group of groups) {
|
|
66
|
+
for (const item of group || []) {
|
|
67
|
+
if (item?.id) byId.set(item.id, item)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return [...byId.values()]
|
|
71
|
+
}
|
|
72
|
+
|
|
54
73
|
async function readLinked (sdk, resourceId) {
|
|
55
74
|
if (!resourceId) return null
|
|
56
75
|
try {
|
|
@@ -61,30 +80,96 @@ async function readLinked (sdk, resourceId) {
|
|
|
61
80
|
}
|
|
62
81
|
}
|
|
63
82
|
|
|
64
|
-
|
|
65
|
-
|
|
83
|
+
/**
|
|
84
|
+
* One filtered page. `query` is required so a caller cannot list a whole folder by accident.
|
|
85
|
+
*/
|
|
86
|
+
async function listMatching (sdk, { listLocation, workspaceId, type, query, limit = MATCH_LIMIT }) {
|
|
87
|
+
const result = await sdk.invoke(ListResources, {
|
|
88
|
+
location: listLocation,
|
|
89
|
+
workspaceId,
|
|
90
|
+
limit,
|
|
91
|
+
query: { type, ...query },
|
|
92
|
+
})
|
|
93
|
+
return asResourceList(result).filter((item) => item?.type === type)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Walk a filtered folder one page at a time. The page is discarded after `fn`.
|
|
98
|
+
*/
|
|
99
|
+
async function forEachPage (sdk, { listLocation, workspaceId, type, query = {} }, fn) {
|
|
100
|
+
const seen = new Set()
|
|
101
|
+
let offset = 0
|
|
102
|
+
for (;;) {
|
|
103
|
+
const result = await sdk.invoke(ListResources, {
|
|
104
|
+
location: listLocation,
|
|
105
|
+
workspaceId,
|
|
106
|
+
limit: PAGE_SIZE,
|
|
107
|
+
offset,
|
|
108
|
+
query: { type, ...query },
|
|
109
|
+
})
|
|
110
|
+
const page = asResourceList(result).filter((item) => item?.type === type)
|
|
111
|
+
const fresh = page.filter((item) => item?.id && !seen.has(item.id))
|
|
112
|
+
if (!fresh.length) break
|
|
113
|
+
for (const item of fresh) seen.add(item.id)
|
|
114
|
+
await fn(fresh)
|
|
115
|
+
if (page.length < PAGE_SIZE) break
|
|
116
|
+
offset += page.length
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Every resource matching a filter. Tag overlap must not stop at MATCH_LIMIT —
|
|
122
|
+
* ranking and matchesToStore decide which rows to keep.
|
|
123
|
+
*/
|
|
124
|
+
async function listAllMatching (sdk, { listLocation, workspaceId, type, query }) {
|
|
125
|
+
const items = []
|
|
126
|
+
await forEachPage(sdk, { listLocation, workspaceId, type, query }, async (page) => {
|
|
127
|
+
items.push(...page)
|
|
128
|
+
})
|
|
129
|
+
return items
|
|
66
130
|
}
|
|
67
131
|
|
|
68
132
|
/**
|
|
69
133
|
* Embed a request or resume when its text changed. Returns true when a new vector was written.
|
|
134
|
+
* `kind` is stored on the vector so a later search can ask for resumes or requests only.
|
|
70
135
|
*/
|
|
71
|
-
export async function ensureEmbedded (sdk, resource, workspaceId) {
|
|
136
|
+
export async function ensureEmbedded (sdk, resource, workspaceId, kind) {
|
|
72
137
|
const text = resource?.type === ConsultancySchema.request
|
|
73
138
|
? requestMatchText(resource)
|
|
74
139
|
: await resumeText(sdk, resource)
|
|
75
140
|
if (!text) return false
|
|
76
141
|
const hash = textHash(text)
|
|
77
142
|
const stored = await getEmbedding(resource.id)
|
|
143
|
+
if (stored && stored.kind !== kind) await setEmbeddingKind(resource.id, kind)
|
|
78
144
|
if (embeddingIsCurrent(stored, hash)) return false
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
145
|
+
try {
|
|
146
|
+
await sdk.invoke(EmbedResource, {
|
|
147
|
+
resourceId: resource.id,
|
|
148
|
+
text,
|
|
149
|
+
textHash: hash,
|
|
150
|
+
workspaceId,
|
|
151
|
+
kind,
|
|
152
|
+
})
|
|
153
|
+
} catch {
|
|
154
|
+
// Tag overlap still ranks when the embedder is missing, as in end-to-end.
|
|
155
|
+
return false
|
|
156
|
+
}
|
|
85
157
|
return true
|
|
86
158
|
}
|
|
87
159
|
|
|
160
|
+
/**
|
|
161
|
+
* A stored vector is enough on a full refresh. Re-reading the profile and
|
|
162
|
+
* every experience is reserved for a document that actually changed.
|
|
163
|
+
*/
|
|
164
|
+
async function embedIfMissing (sdk, resource, workspaceId, kind) {
|
|
165
|
+
const stored = await getEmbedding(resource.id)
|
|
166
|
+
if (stored?.textHash) {
|
|
167
|
+
if (stored.kind !== kind) await setEmbeddingKind(resource.id, kind)
|
|
168
|
+
return false
|
|
169
|
+
}
|
|
170
|
+
return ensureEmbedded(sdk, resource, workspaceId, kind)
|
|
171
|
+
}
|
|
172
|
+
|
|
88
173
|
async function resumeText (sdk, resume) {
|
|
89
174
|
const profile = await readLinked(sdk, referenceId(resume?.content?.profile))
|
|
90
175
|
const experiences = (await Promise.all(
|
|
@@ -93,23 +178,23 @@ async function resumeText (sdk, resume) {
|
|
|
93
178
|
return resumeMatchText(resume, { profile, experiences })
|
|
94
179
|
}
|
|
95
180
|
|
|
96
|
-
function
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
return
|
|
181
|
+
async function matchForRequest (sdk, workspaceId, requestId) {
|
|
182
|
+
const items = await listMatching(sdk, {
|
|
183
|
+
listLocation: matchesLocation,
|
|
184
|
+
workspaceId,
|
|
185
|
+
type: ConsultancySchema.requestMatches,
|
|
186
|
+
limit: 5,
|
|
187
|
+
query: { 'content.request.resourceId': requestId },
|
|
188
|
+
})
|
|
189
|
+
return items[0] || null
|
|
105
190
|
}
|
|
106
191
|
|
|
107
|
-
async function saveMatches (sdk, { workspaceId, request, matches
|
|
192
|
+
async function saveMatches (sdk, { workspaceId, request, matches }) {
|
|
108
193
|
const content = {
|
|
109
194
|
request: { resourceId: request.id },
|
|
110
195
|
matches,
|
|
111
196
|
}
|
|
112
|
-
const current =
|
|
197
|
+
const current = await matchForRequest(sdk, workspaceId, request.id)
|
|
113
198
|
if (current && matchesEqual(current.content?.matches, matches)) return current
|
|
114
199
|
if (current) {
|
|
115
200
|
return sdk.invoke(UpdateContent, { resourceId: current.id, workspaceId, content })
|
|
@@ -123,74 +208,239 @@ async function saveMatches (sdk, { workspaceId, request, matches, existing }) {
|
|
|
123
208
|
})
|
|
124
209
|
}
|
|
125
210
|
|
|
211
|
+
async function resourcesByIds (sdk, { listLocation, workspaceId, type, ids }) {
|
|
212
|
+
const unique = [...new Set((ids || []).filter(Boolean))]
|
|
213
|
+
const found = []
|
|
214
|
+
for (let index = 0; index < unique.length; index += MATCH_LIMIT) {
|
|
215
|
+
const chunk = unique.slice(index, index + MATCH_LIMIT)
|
|
216
|
+
found.push(...await listMatching(sdk, {
|
|
217
|
+
listLocation,
|
|
218
|
+
workspaceId,
|
|
219
|
+
type,
|
|
220
|
+
limit: chunk.length,
|
|
221
|
+
query: { id: { $in: chunk } },
|
|
222
|
+
}))
|
|
223
|
+
}
|
|
224
|
+
return found
|
|
225
|
+
}
|
|
226
|
+
|
|
126
227
|
/**
|
|
127
|
-
*
|
|
228
|
+
* Resumes that share a tag with the request, plus the nearest resume vectors.
|
|
229
|
+
* Tag hits outside the vector result still get a cosine when they have a vector.
|
|
128
230
|
*/
|
|
129
|
-
|
|
130
|
-
const stored = await
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
231
|
+
async function candidatesForRequest (sdk, workspaceId, request) {
|
|
232
|
+
const stored = await getEmbedding(request.id)
|
|
233
|
+
const queryVector = Array.isArray(stored?.vector) ? stored.vector : null
|
|
234
|
+
const similarities = queryVector?.length
|
|
235
|
+
? await searchEmbeddings({
|
|
236
|
+
workspaceId,
|
|
237
|
+
queryVector,
|
|
238
|
+
limit: MATCH_LIMIT,
|
|
239
|
+
kind: KIND_RESUME,
|
|
138
240
|
})
|
|
139
|
-
|
|
241
|
+
: []
|
|
242
|
+
const scoreById = new Map()
|
|
243
|
+
for (const hit of similarities) {
|
|
244
|
+
if (hit?.resourceId && Number.isFinite(hit.score)) scoreById.set(hit.resourceId, hit.score)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const tagQuery = caseInsensitiveTagFilter(resourceTags(request))
|
|
248
|
+
const [tagged, nearest] = await Promise.all([
|
|
249
|
+
tagQuery
|
|
250
|
+
? listAllMatching(sdk, {
|
|
251
|
+
listLocation: resumeLocation,
|
|
252
|
+
workspaceId,
|
|
253
|
+
type: ResumesSchema.resume,
|
|
254
|
+
query: tagQuery,
|
|
255
|
+
})
|
|
256
|
+
: [],
|
|
257
|
+
resourcesByIds(sdk, {
|
|
258
|
+
listLocation: resumeLocation,
|
|
259
|
+
workspaceId,
|
|
260
|
+
type: ResumesSchema.resume,
|
|
261
|
+
ids: similarities.map((hit) => hit.resourceId),
|
|
262
|
+
}),
|
|
263
|
+
])
|
|
264
|
+
|
|
265
|
+
if (queryVector?.length) {
|
|
266
|
+
for (const resume of tagged) {
|
|
267
|
+
if (!resume?.id || scoreById.has(resume.id)) continue
|
|
268
|
+
const resumeVector = await getEmbedding(resume.id)
|
|
269
|
+
if (resumeVector && resumeVector.kind !== KIND_RESUME) {
|
|
270
|
+
await setEmbeddingKind(resume.id, KIND_RESUME)
|
|
271
|
+
}
|
|
272
|
+
if (Array.isArray(resumeVector?.vector) && resumeVector.vector.length === queryVector.length) {
|
|
273
|
+
scoreById.set(resume.id, cosineSimilarity(queryVector, resumeVector.vector))
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
resumes: mergeById([tagged, nearest]),
|
|
280
|
+
similarities: [...scoreById].map(([resourceId, score]) => ({ resourceId, score })),
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Rank the given requests against a bounded set of resumes and save one match document each.
|
|
286
|
+
*/
|
|
287
|
+
export async function scoreRequests (sdk, { workspaceId, requests }) {
|
|
288
|
+
const saved = []
|
|
289
|
+
for (const request of requests || []) {
|
|
290
|
+
const { resumes, similarities } = await candidatesForRequest(sdk, workspaceId, request)
|
|
291
|
+
const matches = matchesToStore(rankMatches({ request, resumes, similarities }))
|
|
292
|
+
saved.push(await saveMatches(sdk, { workspaceId, request, matches }))
|
|
140
293
|
}
|
|
141
294
|
return saved
|
|
142
295
|
}
|
|
143
296
|
|
|
297
|
+
/**
|
|
298
|
+
* Requests to re-score after a resume change: nearest request vectors, requests
|
|
299
|
+
* that share a tag, and requests whose saved matches already include this resume
|
|
300
|
+
* so a resume that fell out of the ranking is removed.
|
|
301
|
+
*/
|
|
302
|
+
async function requestsAffectedByResume (sdk, workspaceId, resume) {
|
|
303
|
+
const stored = await getEmbedding(resume.id)
|
|
304
|
+
const queryVector = Array.isArray(stored?.vector) ? stored.vector : null
|
|
305
|
+
const nearestHits = queryVector?.length
|
|
306
|
+
? await searchEmbeddings({
|
|
307
|
+
workspaceId,
|
|
308
|
+
queryVector,
|
|
309
|
+
limit: MATCH_LIMIT,
|
|
310
|
+
kind: KIND_REQUEST,
|
|
311
|
+
})
|
|
312
|
+
: []
|
|
313
|
+
const tagQuery = caseInsensitiveTagFilter(resourceTags(resume))
|
|
314
|
+
const [tagged, nearest] = await Promise.all([
|
|
315
|
+
tagQuery
|
|
316
|
+
? listAllMatching(sdk, {
|
|
317
|
+
listLocation: location,
|
|
318
|
+
workspaceId,
|
|
319
|
+
type: ConsultancySchema.request,
|
|
320
|
+
query: tagQuery,
|
|
321
|
+
})
|
|
322
|
+
: [],
|
|
323
|
+
resourcesByIds(sdk, {
|
|
324
|
+
listLocation: location,
|
|
325
|
+
workspaceId,
|
|
326
|
+
type: ConsultancySchema.request,
|
|
327
|
+
ids: nearestHits.map((hit) => hit.resourceId),
|
|
328
|
+
}),
|
|
329
|
+
])
|
|
330
|
+
const existingMatches = []
|
|
331
|
+
await forEachPage(sdk, {
|
|
332
|
+
listLocation: matchesLocation,
|
|
333
|
+
workspaceId,
|
|
334
|
+
type: ConsultancySchema.requestMatches,
|
|
335
|
+
query: { 'content.matches.resourceId': resume.id },
|
|
336
|
+
}, async (page) => {
|
|
337
|
+
existingMatches.push(...page)
|
|
338
|
+
})
|
|
339
|
+
const known = mergeById([tagged, nearest])
|
|
340
|
+
const knownIds = new Set(known.map((item) => item.id))
|
|
341
|
+
const missingIds = existingMatches
|
|
342
|
+
.map((item) => referenceId(item?.content?.request))
|
|
343
|
+
.filter((id) => id && !knownIds.has(id))
|
|
344
|
+
const fromMatches = await resourcesByIds(sdk, {
|
|
345
|
+
listLocation: location,
|
|
346
|
+
workspaceId,
|
|
347
|
+
type: ConsultancySchema.request,
|
|
348
|
+
ids: missingIds,
|
|
349
|
+
})
|
|
350
|
+
return mergeById([known, fromMatches])
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
async function embedResumesLinking (sdk, workspaceId, resourceId) {
|
|
354
|
+
const requests = new Map()
|
|
355
|
+
let embedded = 0
|
|
356
|
+
await forEachPage(sdk, {
|
|
357
|
+
listLocation: resumeLocation,
|
|
358
|
+
workspaceId,
|
|
359
|
+
type: ResumesSchema.resume,
|
|
360
|
+
query: {
|
|
361
|
+
$or: [
|
|
362
|
+
{ 'content.profile.resourceId': resourceId },
|
|
363
|
+
{ 'content.experiences.resourceId': resourceId },
|
|
364
|
+
],
|
|
365
|
+
},
|
|
366
|
+
}, async (page) => {
|
|
367
|
+
for (const resume of page) {
|
|
368
|
+
if (await ensureEmbedded(sdk, resume, workspaceId, KIND_RESUME)) embedded += 1
|
|
369
|
+
for (const request of await requestsAffectedByResume(sdk, workspaceId, resume)) {
|
|
370
|
+
requests.set(request.id, request)
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
})
|
|
374
|
+
const saved = await scoreRequests(sdk, { workspaceId, requests: [...requests.values()] })
|
|
375
|
+
return { embedded, requests: saved.length }
|
|
376
|
+
}
|
|
377
|
+
|
|
144
378
|
/**
|
|
145
379
|
* Keep embeddings and saved matches current.
|
|
146
380
|
*
|
|
147
|
-
* A request
|
|
148
|
-
* change embeds
|
|
149
|
-
*
|
|
381
|
+
* A request change embeds that request and writes its one match document.
|
|
382
|
+
* A resume change embeds that resume and re-scores the requests it can affect.
|
|
383
|
+
* A profile or experience change does the same for the resumes that link it.
|
|
384
|
+
* A pass with no triggering document embeds only resources that have no vector,
|
|
385
|
+
* one page at a time, then scores each request against a bounded candidate set.
|
|
150
386
|
*/
|
|
151
387
|
export async function run ({ event, payload, req, sdk }) {
|
|
152
388
|
if (!sdk?.invoke) fail('sdk is required', 500)
|
|
153
389
|
const workspaceId = workspaceIdFrom({ event, payload, req })
|
|
154
390
|
if (!workspaceId) fail('workspaceId is required', 400)
|
|
155
391
|
|
|
156
|
-
const requests = (await listAt(sdk, location, workspaceId))
|
|
157
|
-
.filter((item) => item?.type === ConsultancySchema.request)
|
|
158
|
-
const resumes = (await listAt(sdk, resumeLocation, workspaceId))
|
|
159
|
-
.filter((item) => item?.type === ResumesSchema.resume)
|
|
160
|
-
const existing = (await listAt(sdk, matchesLocation, workspaceId))
|
|
161
|
-
.filter((item) => item?.type === ConsultancySchema.requestMatches)
|
|
162
|
-
|
|
163
392
|
const resourceId = event?.resourceId || null
|
|
164
393
|
const type = event?.type
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
394
|
+
const fullPass = !resourceId || type === 'scheduled'
|
|
395
|
+
|
|
396
|
+
if (fullPass) {
|
|
397
|
+
let embedded = 0
|
|
398
|
+
let requests = 0
|
|
399
|
+
await forEachPage(sdk, {
|
|
400
|
+
listLocation: resumeLocation,
|
|
401
|
+
workspaceId,
|
|
402
|
+
type: ResumesSchema.resume,
|
|
403
|
+
}, async (page) => {
|
|
404
|
+
for (const resume of page) {
|
|
405
|
+
if (await embedIfMissing(sdk, resume, workspaceId, KIND_RESUME)) embedded += 1
|
|
406
|
+
}
|
|
407
|
+
})
|
|
408
|
+
await forEachPage(sdk, {
|
|
409
|
+
listLocation: location,
|
|
410
|
+
workspaceId,
|
|
411
|
+
type: ConsultancySchema.request,
|
|
412
|
+
}, async (page) => {
|
|
413
|
+
for (const request of page) {
|
|
414
|
+
if (await embedIfMissing(sdk, request, workspaceId, KIND_REQUEST)) embedded += 1
|
|
415
|
+
}
|
|
416
|
+
const saved = await scoreRequests(sdk, { workspaceId, requests: page })
|
|
417
|
+
requests += saved.length
|
|
418
|
+
})
|
|
419
|
+
return { embedded, requests }
|
|
187
420
|
}
|
|
188
421
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (
|
|
422
|
+
if (type === ConsultancySchema.request) {
|
|
423
|
+
const request = await readLinked(sdk, resourceId)
|
|
424
|
+
if (request?.type !== ConsultancySchema.request) return { embedded: 0, requests: 0 }
|
|
425
|
+
if (request.belongsTo && request.belongsTo !== workspaceId) return { embedded: 0, requests: 0 }
|
|
426
|
+
const embedded = await ensureEmbedded(sdk, request, workspaceId, KIND_REQUEST) ? 1 : 0
|
|
427
|
+
const saved = await scoreRequests(sdk, { workspaceId, requests: [request] })
|
|
428
|
+
return { embedded, requests: saved.length }
|
|
192
429
|
}
|
|
193
430
|
|
|
194
|
-
|
|
195
|
-
|
|
431
|
+
if (type === ResumesSchema.resume) {
|
|
432
|
+
const resume = await readLinked(sdk, resourceId)
|
|
433
|
+
if (resume?.type !== ResumesSchema.resume) return { embedded: 0, requests: 0 }
|
|
434
|
+
if (resume.belongsTo && resume.belongsTo !== workspaceId) return { embedded: 0, requests: 0 }
|
|
435
|
+
const embedded = await ensureEmbedded(sdk, resume, workspaceId, KIND_RESUME) ? 1 : 0
|
|
436
|
+
const affected = await requestsAffectedByResume(sdk, workspaceId, resume)
|
|
437
|
+
const saved = await scoreRequests(sdk, { workspaceId, requests: affected })
|
|
438
|
+
return { embedded, requests: saved.length }
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (type === PROFILE_SCHEMA || type === ResumesSchema.resumeExperience) {
|
|
442
|
+
return embedResumesLinking(sdk, workspaceId, resourceId)
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
return { embedded: 0, requests: 0 }
|
|
196
446
|
}
|