Centralize default user and team preferences. (#5172
Passing the fallback at each callpoint was dumb
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
AllowNull,
|
||||
AfterUpdate,
|
||||
} from "sequelize-typescript";
|
||||
import { TeamPreferenceDefaults } from "@shared/constants";
|
||||
import {
|
||||
CollectionPermission,
|
||||
TeamPreference,
|
||||
@@ -196,14 +197,15 @@ class Team extends ParanoidModel {
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the passed preference value
|
||||
* Returns the value of the given preference.
|
||||
*
|
||||
* @param preference The user preference to retrieve
|
||||
* @param fallback An optional fallback value, defaults to false.
|
||||
* @returns The preference value if set, else undefined
|
||||
* @param preference The team preference to retrieve
|
||||
* @returns The preference value if set, else the default value
|
||||
*/
|
||||
public getPreference = (preference: TeamPreference, fallback = false) =>
|
||||
this.preferences?.[preference] ?? fallback;
|
||||
public getPreference = (preference: TeamPreference) =>
|
||||
this.preferences?.[preference] ??
|
||||
TeamPreferenceDefaults[preference] ??
|
||||
false;
|
||||
|
||||
provisionFirstCollection = async (userId: string) => {
|
||||
await this.sequelize!.transaction(async (transaction) => {
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
AllowNull,
|
||||
AfterUpdate,
|
||||
} from "sequelize-typescript";
|
||||
import { UserPreferenceDefaults } from "@shared/constants";
|
||||
import { languages } from "@shared/i18n";
|
||||
import type { NotificationSettings } from "@shared/types";
|
||||
import {
|
||||
@@ -354,14 +355,15 @@ class User extends ParanoidModel {
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the passed preference value
|
||||
* Returns the value of the givem preference
|
||||
*
|
||||
* @param preference The user preference to retrieve
|
||||
* @param fallback An optional fallback value, defaults to false.
|
||||
* @returns The preference value if set, else undefined
|
||||
* @returns The preference value if set, else the default value.
|
||||
*/
|
||||
public getPreference = (preference: UserPreference, fallback = false) =>
|
||||
this.preferences?.[preference] ?? fallback;
|
||||
public getPreference = (preference: UserPreference) =>
|
||||
this.preferences?.[preference] ??
|
||||
UserPreferenceDefaults[preference] ??
|
||||
false;
|
||||
|
||||
collectionIds = async (options = {}) => {
|
||||
const collectionStubs = await Collection.scope({
|
||||
|
||||
Reference in New Issue
Block a user