mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-14 12:25:17 +00:00
Fix model versioning
1. Using of package.json was wrong ides, so revert to bundled version value. 2. Do not duplicate record in accounts db and find EmployeeAccount Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
4dbb395472
commit
c95b493a33
@ -36,8 +36,6 @@ import { createModel as templatesModel } from '@anticrm/model-templates'
|
|||||||
import { createModel as textEditorModel } from '@anticrm/model-text-editor'
|
import { createModel as textEditorModel } from '@anticrm/model-text-editor'
|
||||||
import { createModel as viewModel } from '@anticrm/model-view'
|
import { createModel as viewModel } from '@anticrm/model-view'
|
||||||
import { createModel as workbenchModel } from '@anticrm/model-workbench'
|
import { createModel as workbenchModel } from '@anticrm/model-workbench'
|
||||||
import { readFileSync } from 'fs'
|
|
||||||
import { join } from 'path'
|
|
||||||
|
|
||||||
const builder = new Builder()
|
const builder = new Builder()
|
||||||
|
|
||||||
@ -70,14 +68,11 @@ const builders = [
|
|||||||
for (const b of builders) {
|
for (const b of builders) {
|
||||||
b(builder)
|
b(builder)
|
||||||
}
|
}
|
||||||
const packageFile = readFileSync(join(__dirname, '..', 'package.json')).toString()
|
|
||||||
const json = JSON.parse(packageFile)
|
|
||||||
const packageVersion = json.version.split('.')
|
|
||||||
|
|
||||||
export const version: Data<Version> = {
|
export const version: Data<Version> = {
|
||||||
major: parseInt(packageVersion[0]),
|
major: 0,
|
||||||
minor: parseInt(packageVersion[1]),
|
minor: 6,
|
||||||
patch: parseInt(packageVersion[2])
|
patch: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.createDoc(core.class.Version, core.space.Model, version, core.version.Model)
|
builder.createDoc(core.class.Version, core.space.Model, version, core.version.Model)
|
||||||
|
@ -391,10 +391,10 @@ async function getWorkspaceAndAccount (
|
|||||||
export async function assignWorkspace (db: Db, email: string, workspace: string): Promise<void> {
|
export async function assignWorkspace (db: Db, email: string, workspace: string): Promise<void> {
|
||||||
const { workspaceId, accountId } = await getWorkspaceAndAccount(db, email, workspace)
|
const { workspaceId, accountId } = await getWorkspaceAndAccount(db, email, workspace)
|
||||||
// Add account into workspace.
|
// Add account into workspace.
|
||||||
await db.collection(WORKSPACE_COLLECTION).updateOne({ _id: workspaceId }, { $push: { accounts: accountId } })
|
await db.collection(WORKSPACE_COLLECTION).updateOne({ _id: workspaceId }, { $addToSet: { accounts: accountId } })
|
||||||
|
|
||||||
// Add workspace to account
|
// Add workspace to account
|
||||||
await db.collection(ACCOUNT_COLLECTION).updateOne({ _id: accountId }, { $push: { workspaces: workspaceId } })
|
await db.collection(ACCOUNT_COLLECTION).updateOne({ _id: accountId }, { $addToSet: { workspaces: workspaceId } })
|
||||||
|
|
||||||
const account = await db.collection<Account>(ACCOUNT_COLLECTION).findOne({ _id: accountId })
|
const account = await db.collection<Account>(ACCOUNT_COLLECTION).findOne({ _id: accountId })
|
||||||
|
|
||||||
@ -408,17 +408,33 @@ async function createEmployeeAccount (account: Account, workspace: string): Prom
|
|||||||
|
|
||||||
const name = combineName(account.first, account.last)
|
const name = combineName(account.first, account.last)
|
||||||
|
|
||||||
const employee = await ops.createDoc(contact.class.Employee, contact.space.Employee, {
|
// Check if EmployeeAccoun is not exists
|
||||||
name,
|
const existingAccount = await ops.findOne(contact.class.EmployeeAccount, { email: account.email })
|
||||||
city: '',
|
|
||||||
channels: []
|
|
||||||
})
|
|
||||||
|
|
||||||
await ops.createDoc(contact.class.EmployeeAccount, core.space.Model, {
|
if (existingAccount === undefined) {
|
||||||
email: account.email,
|
const employee = await ops.createDoc(contact.class.Employee, contact.space.Employee, {
|
||||||
employee,
|
name,
|
||||||
name
|
city: '',
|
||||||
})
|
channels: []
|
||||||
|
})
|
||||||
|
|
||||||
|
await ops.createDoc(contact.class.EmployeeAccount, core.space.Model, {
|
||||||
|
email: account.email,
|
||||||
|
employee,
|
||||||
|
name
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
const employee = await ops.findOne(contact.class.Employee, { _id: existingAccount.employee })
|
||||||
|
if (employee === undefined) {
|
||||||
|
// Employee was deleted, let's restore it.
|
||||||
|
const employeeId = await ops.createDoc(contact.class.Employee, contact.space.Employee, {
|
||||||
|
name,
|
||||||
|
city: '',
|
||||||
|
channels: []
|
||||||
|
})
|
||||||
|
await ops.updateDoc(contact.class.EmployeeAccount, existingAccount.space, existingAccount._id, { employee: employeeId })
|
||||||
|
}
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
await connection.close()
|
await connection.close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user