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> {