mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 19:44:59 +03:00
Company organization migration (#1165)
Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
parent
92c9732b52
commit
c37d6b8e0e
@ -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<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> {
|
||||
const current = await tx.findOne(core.class.Space, {
|
||||
_id: recruit.space.CandidatesPublic
|
||||
|
Loading…
Reference in New Issue
Block a user