mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-30 21:45:01 +02:00
+10
-31
@@ -1,12 +1,12 @@
|
||||
import { MeasureContext, Ref, TxOperations } from '@hcengineering/core'
|
||||
import task, { DoneState, genRanks, Kanban, SpaceWithStates, State } from '@hcengineering/task'
|
||||
import task, { DoneState, SpaceWithStates, State } from '@hcengineering/task'
|
||||
import { findOrUpdate } from './utils'
|
||||
|
||||
export async function createUpdateSpaceKanban (
|
||||
ctx: MeasureContext,
|
||||
spaceId: Ref<SpaceWithStates>,
|
||||
client: TxOperations
|
||||
): Promise<Ref<State>[]> {
|
||||
): Promise<[Ref<State>[], Ref<DoneState>[]]> {
|
||||
const rawStates = [
|
||||
{ color: 9, name: 'Initial' },
|
||||
{ color: 10, name: 'Intermidiate' },
|
||||
@@ -15,55 +15,34 @@ export async function createUpdateSpaceKanban (
|
||||
{ color: 11, name: 'Invalid' }
|
||||
]
|
||||
const states: Array<Ref<State>> = []
|
||||
const stateRanks = genRanks(rawStates.length)
|
||||
for (const st of rawStates) {
|
||||
const rank = stateRanks.next().value
|
||||
|
||||
if (rank === undefined) {
|
||||
console.error('Failed to generate rank')
|
||||
break
|
||||
}
|
||||
|
||||
const sid = ('generated-' + spaceId + '.state.' + st.name.toLowerCase().replace(' ', '_')) as Ref<State>
|
||||
|
||||
await ctx.with('find-or-update', {}, (ctx) =>
|
||||
findOrUpdate(ctx, client, spaceId, task.class.State, sid, {
|
||||
findOrUpdate(ctx, client, task.space.Statuses, task.class.State, sid, {
|
||||
ofAttribute: task.attribute.State,
|
||||
name: st.name,
|
||||
color: st.color,
|
||||
rank
|
||||
color: st.color
|
||||
})
|
||||
)
|
||||
states.push(sid)
|
||||
}
|
||||
|
||||
const done: Array<Ref<DoneState>> = []
|
||||
|
||||
const doneStates = [
|
||||
{ class: task.class.WonState, name: 'Won' },
|
||||
{ class: task.class.LostState, name: 'Lost' }
|
||||
]
|
||||
const doneStateRanks = genRanks(doneStates.length)
|
||||
for (const st of doneStates) {
|
||||
const rank = doneStateRanks.next().value
|
||||
|
||||
if (rank === undefined) {
|
||||
console.error('Failed to generate rank')
|
||||
break
|
||||
}
|
||||
|
||||
const sid = `generated-${spaceId}.done-state.${st.name.toLowerCase().replace(' ', '_')}` as Ref<DoneState>
|
||||
await ctx.with('gen-done-state', {}, (ctx) =>
|
||||
findOrUpdate(ctx, client, spaceId, st.class, sid, {
|
||||
findOrUpdate(ctx, client, task.space.Statuses, st.class, sid, {
|
||||
ofAttribute: task.attribute.DoneState,
|
||||
name: st.name,
|
||||
rank
|
||||
name: st.name
|
||||
})
|
||||
)
|
||||
done.push(sid)
|
||||
}
|
||||
|
||||
await ctx.with('create-kanban', {}, (ctx) =>
|
||||
findOrUpdate(ctx, client, spaceId, task.class.Kanban, ('generated-' + spaceId + '.kanban') as Ref<Kanban>, {
|
||||
attachedTo: spaceId
|
||||
})
|
||||
)
|
||||
return states
|
||||
return [states, done]
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import contact, { Channel, PersonAccount, Person, Employee } from '@hcengineering/contact'
|
||||
import contact, { Channel, Employee, Person, PersonAccount } from '@hcengineering/contact'
|
||||
import core, {
|
||||
AttachedData,
|
||||
Data,
|
||||
@@ -87,6 +87,10 @@ async function genVacansyApplicants (
|
||||
candidates: Ref<Candidate>[],
|
||||
emoloyeeIds: Ref<Employee>[]
|
||||
): Promise<void> {
|
||||
const [states, doneStates] = await ctx.with('create-kanbad', {}, (ctx) =>
|
||||
createUpdateSpaceKanban(ctx, vacancyId, client)
|
||||
)
|
||||
|
||||
const vacancy: Data<Vacancy> = {
|
||||
name: faker.company.companyName(),
|
||||
description: faker.lorem.sentences(2),
|
||||
@@ -95,7 +99,9 @@ async function genVacansyApplicants (
|
||||
members: accountIds,
|
||||
number: faker.datatype.number(),
|
||||
private: false,
|
||||
archived: false
|
||||
archived: false,
|
||||
states,
|
||||
doneStates
|
||||
}
|
||||
const vacancyId = (options.random ? `vacancy-${generateId()}-${i}` : `vacancy-genid-${i}`) as Ref<Vacancy>
|
||||
|
||||
@@ -125,10 +131,6 @@ async function genVacansyApplicants (
|
||||
|
||||
console.log('Vacancy attachments generated', vacancy.name)
|
||||
|
||||
const states = await ctx.with('create-kanbad', {}, (ctx) => createUpdateSpaceKanban(ctx, vacancyId, client))
|
||||
|
||||
console.log('States generated', vacancy.name)
|
||||
|
||||
const applicantsForCount = options.applicants.min + faker.datatype.number(options.applicants.max)
|
||||
|
||||
const applicantsFor = faker.random.arrayElements(candidates, applicantsForCount)
|
||||
|
||||
Reference in New Issue
Block a user