File tree Expand file tree Collapse file tree 3 files changed +61
-2
lines changed
src/components/project/handlers Expand file tree Collapse file tree 3 files changed +61
-2
lines changed Original file line number Diff line number Diff line change
1
+ CREATE MIGRATION m1ydhle3dwjru34saeiidf5dyepbesugdwttrvnsyxhezpme5bfqga
2
+ ONTO m13bndkbclxwviy3uj4eskx56bd2chw2xbvfn5pae557oslmbz2ssa
3
+ {
4
+ ALTER TYPE default :: Project {
5
+ ALTER PROPERTY departmentId {
6
+ CREATE REWRITE
7
+ UPDATE
8
+ USING ((IF ((NOT (EXISTS (.departmentId)) AND (.status <= Project:: Status.Active)) AND (.step >= Project:: Step.PendingFinanceConfirmation)) THEN (WITH
9
+ fa :=
10
+ std :: assert_exists (__subject__ .primaryLocation.fundingAccount, message := ' Project must have a primary location' )
11
+ ,
12
+ existing :=
13
+ (SELECT
14
+ (DETACHED default :: Project).departmentId
15
+ FILTER
16
+ (default :: Project.primaryLocation.fundingAccount = fa)
17
+ )
18
+ ,
19
+ available :=
20
+ (std :: range_unpack (std :: range (((fa.accountNumber * 10000 ) + 11 ), ((fa.accountNumber * 10000 ) + 9999 ))) EXCEPT existing)
21
+ SELECT
22
+ std :: min (available)
23
+ ) ELSE .departmentId));
24
+ };
25
+ };
26
+ };
Original file line number Diff line number Diff line change @@ -14,6 +14,27 @@ module default {
14
14
constraint exclusive ;
15
15
constraint min_value (10000 );
16
16
constraint max_value (99999 );
17
+ rewrite update using (
18
+ if (
19
+ not exists .departmentId and
20
+ .status <= Project:: Status.Active and
21
+ .step >= Project:: Step.PendingFinanceConfirmation
22
+ ) then ((
23
+ with
24
+ fa := assert_exists (
25
+ __subject__ .primaryLocation.fundingAccount,
26
+ message := " Project must have a primary location"
27
+ ),
28
+ existing := (
29
+ select detached Project.departmentId filter Project.primaryLocation.fundingAccount = fa
30
+ ),
31
+ available := (
32
+ range_unpack (range (fa.accountNumber * 10000 + 11 , fa.accountNumber * 10000 + 9999 ))
33
+ except existing
34
+ )
35
+ select min (available)
36
+ )) else .departmentId
37
+ );
17
38
};
18
39
19
40
required step: Project:: Step {
Original file line number Diff line number Diff line change @@ -4,17 +4,29 @@ import {
4
4
ServerException ,
5
5
UnsecuredDto ,
6
6
} from '../../../common' ;
7
- import { DatabaseService , EventsHandler , IEventHandler } from '../../../core' ;
7
+ import {
8
+ ConfigService ,
9
+ DatabaseService ,
10
+ EventsHandler ,
11
+ IEventHandler ,
12
+ } from '../../../core' ;
8
13
import { Project , ProjectStep } from '../dto' ;
9
14
import { ProjectUpdatedEvent } from '../events' ;
10
15
11
16
type SubscribedEvent = ProjectUpdatedEvent ;
12
17
13
18
@EventsHandler ( ProjectUpdatedEvent )
14
19
export class SetDepartmentId implements IEventHandler < SubscribedEvent > {
15
- constructor ( private readonly db : DatabaseService ) { }
20
+ constructor (
21
+ private readonly db : DatabaseService ,
22
+ private readonly config : ConfigService ,
23
+ ) { }
16
24
17
25
async handle ( event : SubscribedEvent ) {
26
+ if ( this . config . databaseEngine === 'edgedb' ) {
27
+ return ;
28
+ }
29
+
18
30
const shouldSetDepartmentId =
19
31
event . updates . step === ProjectStep . PendingFinanceConfirmation &&
20
32
! event . updated . departmentId ;
You can’t perform that action at this time.
0 commit comments