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