From c37d6b8e0ecd260907810e249a46b881e93dde6c Mon Sep 17 00:00:00 2001 From: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> Date: Fri, 18 Mar 2022 12:09:49 +0600 Subject: [PATCH] Company organization migration (#1165) Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> --- models/recruit/src/migration.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/models/recruit/src/migration.ts b/models/recruit/src/migration.ts index ce64bb78d2..d61bf47478 100644 --- a/models/recruit/src/migration.ts +++ b/models/recruit/src/migration.ts @@ -163,6 +163,8 @@ export const recruitOperation: MigrateOperation = { await createSpace(tx) + await migrateCompany(tx) + await createOrUpdate( tx, tags.class.TagCategory, @@ -209,6 +211,33 @@ export const recruitOperation: MigrateOperation = { } } +async function migrateCompany (tx: TxOperations): Promise { + await migrateVacancyCompany(tx) +} + +async function migrateVacancyCompany (tx: TxOperations): Promise { + const vacancies = await tx.findAll(recruit.class.Vacancy, {}) + for (const vacancy of vacancies) { + if (vacancy.company === undefined) continue + const current = await tx.findOne(contact.class.Organization, { _id: vacancy.company }) + if (current !== undefined) continue + const same = await tx.findOne(contact.class.Organization, { name: vacancy.company }) + if (same !== undefined) { + await tx.update(vacancy, { + company: same._id + }) + } else { + const id = await tx.createDoc(contact.class.Organization, contact.space.Contacts, { + name: vacancy.company, + city: '' + }) + await tx.update(vacancy, { + company: id + }) + } + } +} + async function createSpace (tx: TxOperations): Promise { const current = await tx.findOne(core.class.Space, { _id: recruit.space.CandidatesPublic