eletrotupi / tcc/ api/src/lib/serializers/user.ts6b62f4dcf96987b8b2e55bd210139a3ac9f0d976
1.0 KB | 34 lines Raw
1
import { Prisma, User } from '@prisma/client';
2

3
// DB-level projection of the allow-list below — keep the two in sync.
4
export const publicUserSelect = {
5
  id: true,
6
  email: true,
7
  firstName: true,
8
  lastName: true,
9
  updatedAt: true,
10
  avatarKey: true,
11
  avatarURL: true,
12
  active: true,
13
  notificationsEnabled: true,
14
  dailyReminderTime: true,
15
  weeklyResumeEnabled: true,
16
  onboardingSeenAt: true,
17
} satisfies Prisma.UserSelect;
18

19
// The only shape a user leaves the API in. Everything not listed here
20
// (encryptedPassword, reset secrets, activation code, pushToken) stays server-side.
21
export const publicUser = (user: User) => ({
22
  id: user.id,
23
  email: user.email,
24
  firstName: user.firstName,
25
  lastName: user.lastName,
26
  updatedAt: user.updatedAt,
27
  avatarKey: user.avatarKey,
28
  avatarURL: user.avatarURL,
29
  active: user.active,
30
  notificationsEnabled: user.notificationsEnabled,
31
  dailyReminderTime: user.dailyReminderTime,
32
  weeklyResumeEnabled: user.weeklyResumeEnabled,
33
  onboardingSeenAt: user.onboardingSeenAt,
34
});