@@ -10,7 +10,7 @@ import {
10
10
EventsHandler ,
11
11
IEventHandler ,
12
12
} from '../../../core' ;
13
- import { Project , ProjectStep } from '../dto' ;
13
+ import { Project , ProjectStep , ProjectType } from '../dto' ;
14
14
import { ProjectUpdatedEvent } from '../events' ;
15
15
16
16
type SubscribedEvent = ProjectUpdatedEvent ;
@@ -55,7 +55,17 @@ export class SetDepartmentId implements IEventHandler<SubscribedEvent> {
55
55
}
56
56
57
57
private async assignDepartmentIdForProject ( project : UnsecuredDto < Project > ) {
58
- const departmentIdPrefix = await this . getFundingAccountNumber ( project ) ;
58
+ const info =
59
+ project . type === ProjectType . MultiplicationTranslation
60
+ ? {
61
+ departmentIdPrefix : '8' ,
62
+ startingOffset : 201 ,
63
+ }
64
+ : {
65
+ departmentIdPrefix : await this . getFundingAccountNumber ( project ) ,
66
+ startingOffset : 11 ,
67
+ } ;
68
+
59
69
const res = await this . db
60
70
. query ( )
61
71
. raw (
@@ -64,7 +74,7 @@ export class SetDepartmentId implements IEventHandler<SubscribedEvent> {
64
74
MATCH ()-[:departmentId]-(departmentIdPropertyNode:Property)
65
75
WHERE departmentIdPropertyNode.value STARTS WITH $departmentIdPrefix
66
76
WITH collect(distinct(toInteger(right(departmentIdPropertyNode.value, 4)))) as listOfDepartmentIds
67
- WITH [n IN range(11 , 9999) WHERE NOT n IN listOfDepartmentIds] as listOfUnusedDepartmentIds
77
+ WITH [n IN range($startingOffset , 9999) WHERE NOT n IN listOfDepartmentIds] as listOfUnusedDepartmentIds
68
78
WITH apoc.coll.shuffle(listOfUnusedDepartmentIds) AS randomizedIds
69
79
WITH toString(randomizedIds[0]) AS nextIdBase
70
80
WITH $departmentIdPrefix + substring("0000", 1, 4 - size(nextIdBase)) + nextIdBase as nextId
@@ -75,7 +85,7 @@ export class SetDepartmentId implements IEventHandler<SubscribedEvent> {
75
85
CREATE (project)-[newDepartmentIdRelationship:departmentId { active: true, createdAt: datetime() }]->(:Property { createdAt: datetime(), value: departmentId })
76
86
RETURN departmentId
77
87
` ,
78
- { departmentIdPrefix : departmentIdPrefix , projectId : project . id } ,
88
+ { ... info , projectId : project . id } ,
79
89
)
80
90
. asResult < { departmentId : ID } > ( )
81
91
. first ( ) ;
0 commit comments