eletrotupi / tcc/ api/src/lib/serializers/user.tsff12ba99add07246bdaf39737d2c64072be1cfbf
953 B | 32 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
  onboardingSeenAt: true,
16
} satisfies Prisma.UserSelect;
17

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