Company organization migration (#1165)

Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
Denis Bykhov 2022-03-18 12:09:49 +06:00 committed by GitHub
parent 92c9732b52
commit c37d6b8e0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -163,6 +163,8 @@ export const recruitOperation: MigrateOperation = {
await createSpace(tx) await createSpace(tx)
await migrateCompany(tx)
await createOrUpdate( await createOrUpdate(
tx, tx,
tags.class.TagCategory, tags.class.TagCategory,
@ -209,6 +211,33 @@ export const recruitOperation: MigrateOperation = {
} }
} }
async function migrateCompany (tx: TxOperations): Promise<void> {
await migrateVacancyCompany(tx)
}
async function migrateVacancyCompany (tx: TxOperations): Promise<void> {
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<void> { async function createSpace (tx: TxOperations): Promise<void> {
const current = await tx.findOne(core.class.Space, { const current = await tx.findOne(core.class.Space, {
_id: recruit.space.CandidatesPublic _id: recruit.space.CandidatesPublic