* chore: Centralize env parsing, defaults, deprecation * wip * test * test * tsc * docs, more validation * fix: Allow empty REDIS_URL (defaults to localhost) * test * fix: SLACK_MESSAGE_ACTIONS not bool * fix: Add SMTP port validation
47 lines
996 B
TypeScript
47 lines
996 B
TypeScript
import env from "@server/env";
|
|
import { User } from "@server/models";
|
|
|
|
type Options = {
|
|
includeDetails?: boolean;
|
|
};
|
|
|
|
type UserPresentation = {
|
|
id: string;
|
|
name: string;
|
|
avatarUrl: string | null | undefined;
|
|
createdAt: Date;
|
|
updatedAt: Date;
|
|
lastActiveAt: Date | null;
|
|
color: string;
|
|
isAdmin: boolean;
|
|
isSuspended: boolean;
|
|
isViewer: boolean;
|
|
email?: string | null;
|
|
language?: string;
|
|
};
|
|
|
|
export default (
|
|
user: User,
|
|
options: Options = {}
|
|
): UserPresentation | null | undefined => {
|
|
const userData: UserPresentation = {
|
|
id: user.id,
|
|
name: user.name,
|
|
avatarUrl: user.avatarUrl,
|
|
color: user.color,
|
|
isAdmin: user.isAdmin,
|
|
isSuspended: user.isSuspended,
|
|
isViewer: user.isViewer,
|
|
createdAt: user.createdAt,
|
|
updatedAt: user.updatedAt,
|
|
lastActiveAt: user.lastActiveAt,
|
|
};
|
|
|
|
if (options.includeDetails) {
|
|
userData.email = user.email;
|
|
userData.language = user.language || env.DEFAULT_LANGUAGE;
|
|
}
|
|
|
|
return userData;
|
|
};
|