Candidate mixins (#745)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2022-01-06 12:38:40 +01:00
committed by GitHub
parent c53647b7e8
commit 5d24970bf6
30 changed files with 645 additions and 292 deletions
+16 -11
View File
@@ -1,10 +1,10 @@
import contact, { Employee, EmployeeAccount } from '@anticrm/contact'
import contact, { Employee, EmployeeAccount, Person } from '@anticrm/contact'
import core, {
AttachedData,
Data,
generateId,
MeasureContext,
MeasureMetricsContext, metricsToString, Ref,
MeasureMetricsContext, metricsToString, MixinUpdate, Ref,
TxOperations
} from '@anticrm/core'
import recruit from '@anticrm/model-recruit'
@@ -160,7 +160,7 @@ async function genApplicant (
// Update or create candidate
await findOrUpdateAttached(ctx, client, vacancyId, recruit.class.Applicant, applicantId, applicant, {
attachedTo: candidateId,
attachedClass: recruit.class.Candidate,
attachedClass: recruit.mixin.Candidate,
collection: 'applications'
})
@@ -222,23 +222,28 @@ async function genCandidate (
minio.putObject(dbName, imgId, jpegImageData.data, jpegImageData.data.length, { 'Content-Type': 'image/jpeg' })
)
}
const candidate: Data<Candidate> = {
const candidate: Data<Person> = {
name: fName + ',' + lName,
city: faker.address.city(),
title: faker.name.title(),
channels: [{ provider: contact.channelProvider.Email, value: faker.internet.email(fName, lName) }],
avatar: imgId
}
const candidateMixin: MixinUpdate<Person, Candidate> = {
title: faker.name.title(),
onsite: faker.datatype.boolean(),
remote: faker.datatype.boolean(),
avatar: imgId,
source: faker.lorem.lines(1)
}
const candidateId = (options.random ? `candidate-${generateId()}-${i}` : `candidate-genid-${i}`) as Ref<Candidate>
candidates.push(candidateId)
// Update or create candidate
await ctx.with('find-update', {}, () =>
findOrUpdate(ctx, client, recruit.space.CandidatesPublic, recruit.class.Candidate, candidateId, candidate)
)
await ctx.with('find-update', {}, async () => {
await findOrUpdate(ctx, client, recruit.space.CandidatesPublic, contact.class.Person, candidateId, candidate)
await client.updateMixin(candidateId, contact.class.Person, recruit.space.CandidatesPublic, recruit.mixin.Candidate, candidateMixin)
})
await ctx.with('add-comment', {}, () =>
addComments(
@@ -246,7 +251,7 @@ async function genCandidate (
client,
recruit.space.CandidatesPublic,
candidateId,
recruit.class.Candidate,
contact.class.Person,
'comments'
)
)
@@ -260,7 +265,7 @@ async function genCandidate (
dbName,
recruit.space.CandidatesPublic,
candidateId,
recruit.class.Candidate,
contact.class.Person,
'attachments'
)
)
+3 -1
View File
@@ -1,11 +1,13 @@
import { AttachedData, AttachedDoc, Class, Data, Doc, DocumentUpdate, MeasureContext, Ref, Space, TxOperations } from '@anticrm/core'
export async function findOrUpdate<T extends Doc> (ctx: MeasureContext, client: TxOperations, space: Ref<Space>, _class: Ref<Class<T>>, objectId: Ref<T>, data: Data<T>): Promise<void> {
export async function findOrUpdate<T extends Doc> (ctx: MeasureContext, client: TxOperations, space: Ref<Space>, _class: Ref<Class<T>>, objectId: Ref<T>, data: Data<T>): Promise<boolean> {
const existingObj = await client.findOne<Doc>(_class, { _id: objectId, space })
if (existingObj !== undefined) {
await client.updateDoc(_class, space, objectId, data)
return false
} else {
await client.createDoc(_class, space, data, objectId)
return true
}
}
export async function findOrUpdateAttached<T extends AttachedDoc> (ctx: MeasureContext, client: TxOperations, space: Ref<Space>, _class: Ref<Class<T>>, objectId: Ref<T>, data: AttachedData<T>, attached: {attachedTo: Ref<Doc>, attachedClass: Ref<Class<Doc>>, collection: string}): Promise<void> {
+13 -9
View File
@@ -16,8 +16,8 @@
import attachment, { Attachment } from '@anticrm/attachment'
import chunter, { Comment } from '@anticrm/chunter'
import contact, { ChannelProvider } from '@anticrm/contact'
import core, { AttachedData, AttachedDoc, Class, Data, Doc, DocumentUpdate, Ref, SortingOrder, Space, TxOperations, TxResult } from '@anticrm/core'
import contact, { ChannelProvider, Person } from '@anticrm/contact'
import core, { AttachedData, AttachedDoc, Class, Data, Doc, DocumentUpdate, Ref, SortingOrder, Space, TxOperations, TxResult, MixinData } from '@anticrm/core'
import recruit from '@anticrm/model-recruit'
import { Applicant, Candidate, Vacancy } from '@anticrm/recruit'
import task, { calcRank, DoneState, genRanks, Kanban, State } from '@anticrm/task'
@@ -156,7 +156,7 @@ export async function importXml (
lastModified: stats.mtime.getTime()
}, {
attachedTo: candId,
attachedClass: recruit.class.Candidate,
attachedClass: contact.class.Person,
collection: 'attachments'
})
@@ -227,7 +227,7 @@ async function createApplicant (vacancyId: Ref<Vacancy>, candidateId: Ref<Candid
}
// Update or create candidate
await findOrUpdateAttached(client, vacancyId, recruit.class.Applicant, applicantId, applicant, { attachedTo: candidateId, attachedClass: recruit.class.Candidate, collection: 'applications' })
await findOrUpdateAttached(client, vacancyId, recruit.class.Applicant, applicantId, applicant, { attachedTo: candidateId, attachedClass: contact.class.Person, collection: 'applications' })
}
async function createUpdateVacancy (client: TxOperations, statuses: any): Promise<{states: Map<string, Ref<State>>, vacancyId: Ref<Vacancy>}> {
@@ -259,9 +259,13 @@ async function createCandidate (_name: string, pos: number, len: number, c: any,
const { sourceFields, telegram, linkedin, github } = parseSocials(c)
const data: Data<Candidate> = {
const data: Data<Person> = {
name: names.slice(1).join(' ') + ',' + names[0],
city: get(c, _.city) ?? '',
channels: []
}
const candidateData: MixinData<Person, Candidate> = {
title: [
get(c, _.vacancyKind),
get(c, _.area)
@@ -270,8 +274,7 @@ async function createCandidate (_name: string, pos: number, len: number, c: any,
get(c, _.socialContacted),
get(c, _.socialChannel),
sourceFields.filter(onlyUniq).join(', ')
].filter(p => p !== undefined && p.trim().length > 0).filter(onlyUniq).join('/'),
channels: []
].filter(p => p !== undefined && p.trim().length > 0).filter(onlyUniq).join('/')
}
pushChannel(c, data, _.email, contact.channelProvider.Email)
@@ -296,14 +299,15 @@ async function createCandidate (_name: string, pos: number, len: number, c: any,
if (github !== undefined) {
data.channels.push({ provider: contact.channelProvider.GitHub, value: github })
}
await findOrUpdate(client, recruit.space.CandidatesPublic, recruit.class.Candidate, candId, data)
await findOrUpdate(client, recruit.space.CandidatesPublic, contact.class.Person, candId, data)
await client.updateMixin(candId, contact.class.Person, recruit.space.CandidatesPublic, recruit.mixin.Candidate, candidateData)
const commentId = (candId + '.description.comment') as Ref<Comment>
if (commentData.length > 0) {
await findOrUpdateAttached(client, recruit.space.CandidatesPublic, chunter.class.Comment, commentId, {
message: commentData.join('\n<br/>')
}, { attachedTo: candId, attachedClass: recruit.class.Candidate, collection: 'comments' })
}, { attachedTo: candId, attachedClass: recruit.mixin.Candidate, collection: 'comments' })
}
}
+9 -1
View File
@@ -3,7 +3,7 @@ import {
DocumentQuery,
Domain,
FindOptions,
isOperator, SortingOrder
isOperator, Ref, SortingOrder
} from '@anticrm/core'
import { MigrationClient, MigrateUpdate, MigrationResult } from '@anticrm/model'
import { Db, Document, Filter, Sort, UpdateFilter } from 'mongodb'
@@ -87,4 +87,12 @@ export class MigrateClientImpl implements MigrationClient {
await this.db.collection(sourceDomain).deleteMany(q)
return result
}
async create <T extends Doc>(domain: Domain, doc: T): Promise<void> {
await this.db.collection(domain).insertOne(doc as Document)
}
async delete <T extends Doc>(domain: Domain, _id: Ref<T>): Promise<void> {
await this.db.collection(domain).deleteOne({ _id })
}
}