Fix incorrect fetch of userVars when userId is not specified

This commit is contained in:
Charles Bochet 2024-07-28 11:30:14 +02:00
parent 75e0e1434a
commit dcb8c7c03a

View File

@ -32,11 +32,15 @@ export class UserVarsService<
);
}
const userVarUserLevel = await this.keyValuePairService.get({
type: KeyValuePairType.USER_VAR,
userId,
key,
});
let userVarUserLevel: any[] = [];
if (userId) {
userVarUserLevel = await this.keyValuePairService.get({
type: KeyValuePairType.USER_VAR,
userId,
key,
});
}
if (userVarUserLevel.length > 1) {
throw new Error(`Multiple values found for key ${key} at user level`);
@ -60,10 +64,14 @@ export class UserVarsService<
workspaceId,
});
const userVarsUserLevel = await this.keyValuePairService.get({
type: KeyValuePairType.USER_VAR,
userId,
});
let userVarsUserLevel: any[] = [];
if (userId) {
userVarsUserLevel = await this.keyValuePairService.get({
type: KeyValuePairType.USER_VAR,
userId,
});
}
return mergeUserVars<Extract<keyof KeyValueTypesMap, string>>([
...userVarsWorkspaceLevel,