@@ -19,12 +19,16 @@ export class UserVarsService<
19
19
workspaceId ?: string ;
20
20
key : Extract < K , string > ;
21
21
} ) : Promise < KeyValueTypesMap [ K ] > {
22
- const userVarWorkspaceLevel = await this . keyValuePairService . get ( {
23
- type : KeyValuePairType . USER_VAR ,
24
- userId : null ,
25
- workspaceId,
26
- key,
27
- } ) ;
22
+ let userVarWorkspaceLevel : any [ ] = [ ] ;
23
+
24
+ if ( workspaceId ) {
25
+ userVarWorkspaceLevel = await this . keyValuePairService . get ( {
26
+ type : KeyValuePairType . USER_VAR ,
27
+ userId : null ,
28
+ workspaceId,
29
+ key,
30
+ } ) ;
31
+ }
28
32
29
33
if ( userVarWorkspaceLevel . length > 1 ) {
30
34
throw new Error (
@@ -38,6 +42,7 @@ export class UserVarsService<
38
42
userVarUserLevel = await this . keyValuePairService . get ( {
39
43
type : KeyValuePairType . USER_VAR ,
40
44
userId,
45
+ workspaceId : null ,
41
46
key,
42
47
} ) ;
43
48
}
@@ -46,9 +51,28 @@ export class UserVarsService<
46
51
throw new Error ( `Multiple values found for key ${ key } at user level` ) ;
47
52
}
48
53
49
- return mergeUserVars ( [ ...userVarUserLevel , ...userVarWorkspaceLevel ] ) . get (
50
- key ,
51
- ) as KeyValueTypesMap [ K ] ;
54
+ let userVarWorkspaceAndUserLevel : any [ ] = [ ] ;
55
+
56
+ if ( userId && workspaceId ) {
57
+ userVarWorkspaceAndUserLevel = await this . keyValuePairService . get ( {
58
+ type : KeyValuePairType . USER_VAR ,
59
+ userId,
60
+ workspaceId,
61
+ key,
62
+ } ) ;
63
+ }
64
+
65
+ if ( userVarWorkspaceAndUserLevel . length > 1 ) {
66
+ throw new Error (
67
+ `Multiple values found for key ${ key } at workspace and user level` ,
68
+ ) ;
69
+ }
70
+
71
+ return mergeUserVars ( [
72
+ ...userVarUserLevel ,
73
+ ...userVarWorkspaceLevel ,
74
+ ...userVarWorkspaceAndUserLevel ,
75
+ ] ) . get ( key ) as KeyValueTypesMap [ K ] ;
52
76
}
53
77
54
78
public async getAll ( {
0 commit comments