This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
website/models/User.ts

77 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

2022-08-31 21:44:33 +02:00
import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
import { strategiesTypebox } from './OAuth'
import { userSettingsSchema } from './UserSettings'
import { date, id } from './utils'
export const userSchema = {
id,
name: Type.String({ minLength: 1, maxLength: 30 }),
2021-10-26 16:38:55 +02:00
email: Type.String({ minLength: 1, maxLength: 254, format: 'email' }),
password: Type.String({ minLength: 1 }),
logo: Type.Union([
Type.String({ minLength: 1, format: 'uri-reference' }),
Type.Null()
]),
status: Type.Union([
Type.String({ minLength: 1, maxLength: 50 }),
Type.Null()
]),
biography: Type.Union([
Type.String({ minLength: 1, maxLength: 160 }),
Type.Null()
]),
website: Type.Union([
Type.String({
minLength: 1,
maxLength: 255,
format: 'uri'
}),
Type.Null()
]),
isConfirmed: Type.Boolean({ default: false }),
temporaryToken: Type.String(),
temporaryExpirationToken: Type.String({ format: 'date-time' }),
createdAt: date.createdAt,
updatedAt: date.updatedAt
}
2021-10-26 16:38:55 +02:00
export const userObjectSchema = Type.Object(userSchema)
2021-10-26 16:38:55 +02:00
export const userPublicWithoutSettingsSchema = {
id,
name: userSchema.name,
2021-10-26 16:38:55 +02:00
email: Type.Union([userSchema.email, Type.Null()]),
logo: userSchema.logo,
status: userSchema.status,
biography: userSchema.biography,
website: userSchema.website,
isConfirmed: userSchema.isConfirmed,
createdAt: date.createdAt,
2021-10-26 16:38:55 +02:00
updatedAt: date.updatedAt
}
export const userPublicWithoutSettingsObjectSchema = Type.Object(
userPublicWithoutSettingsSchema
)
2021-10-26 16:38:55 +02:00
export const userPublicSchema = {
...userPublicWithoutSettingsSchema,
settings: Type.Object(userSettingsSchema)
}
export const userPublicObjectSchema = Type.Object(userPublicSchema)
export const userCurrentSchema = Type.Object({
2021-10-26 16:38:55 +02:00
...userPublicSchema,
currentStrategy: Type.Union([...strategiesTypebox]),
strategies: Type.Array(Type.Union([...strategiesTypebox]))
})
2021-10-26 16:38:55 +02:00
export type User = Static<typeof userObjectSchema>
export type UserPublic = Static<typeof userPublicObjectSchema>
export type UserPublicWithoutSettings = Static<
typeof userPublicWithoutSettingsObjectSchema
>
export type UserCurrent = Static<typeof userCurrentSchema>