Files
outline/server/presenters/user.ts
Tom Moor 15b1069bcc chore: Move to Typescript (#2783)
This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously.

closes #1282
2021-11-29 06:40:55 -08:00

54 lines
2.3 KiB
TypeScript

import { User } from "@server/models";
type Options = {
includeDetails?: boolean;
};
type UserPresentation = {
id: string;
name: string;
avatarUrl: string | null | undefined;
email?: string;
color: string;
isAdmin: boolean;
isSuspended: boolean;
isViewer: boolean;
language: string;
};
export default (
// @ts-expect-error ts-migrate(2749) FIXME: 'User' refers to a value, but is being used as a t... Remove this comment to see the full error message
user: User,
options: Options = {}
): UserPresentation | null | undefined => {
const userData = {};
// @ts-expect-error ts-migrate(2339) FIXME: Property 'id' does not exist on type '{}'.
userData.id = user.id;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'createdAt' does not exist on type '{}'.
userData.createdAt = user.createdAt;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'name' does not exist on type '{}'.
userData.name = user.name;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'color' does not exist on type '{}'.
userData.color = user.color;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'isAdmin' does not exist on type '{}'.
userData.isAdmin = user.isAdmin;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'isViewer' does not exist on type '{}'.
userData.isViewer = user.isViewer;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'isSuspended' does not exist on type '{}'... Remove this comment to see the full error message
userData.isSuspended = user.isSuspended;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'avatarUrl' does not exist on type '{}'.
userData.avatarUrl = user.avatarUrl;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'lastActiveAt' does not exist on type '{}... Remove this comment to see the full error message
userData.lastActiveAt = user.lastActiveAt;
if (options.includeDetails) {
// @ts-expect-error ts-migrate(2339) FIXME: Property 'email' does not exist on type '{}'.
userData.email = user.email;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'language' does not exist on type '{}'.
userData.language =
user.language || process.env.DEFAULT_LANGUAGE || "en_US";
}
// @ts-expect-error ts-migrate(2740) FIXME: Type '{}' is missing the following properties from... Remove this comment to see the full error message
return userData;
};