2022-08-31 21:44:33 +02:00
|
|
|
import type { Static } from '@sinclair/typebox'
|
|
|
|
import { Type } from '@sinclair/typebox'
|
2021-10-24 06:09:43 +02:00
|
|
|
|
|
|
|
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' }),
|
2021-10-24 06:09:43 +02:00
|
|
|
password: Type.String({ minLength: 1 }),
|
2021-11-13 21:50:34 +01:00
|
|
|
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,
|
2022-04-07 16:54:05 +02:00
|
|
|
format: 'uri'
|
2021-11-13 21:50:34 +01:00
|
|
|
}),
|
|
|
|
Type.Null()
|
|
|
|
]),
|
2021-10-24 06:09:43 +02:00
|
|
|
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-24 06:09:43 +02:00
|
|
|
|
2021-10-26 16:38:55 +02:00
|
|
|
export const userPublicWithoutSettingsSchema = {
|
2021-10-24 06:09:43 +02:00
|
|
|
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,
|
2021-11-13 21:50:34 +01:00
|
|
|
website: userSchema.website,
|
2021-10-24 06:09:43 +02:00
|
|
|
isConfirmed: userSchema.isConfirmed,
|
|
|
|
createdAt: date.createdAt,
|
2021-10-26 16:38:55 +02:00
|
|
|
updatedAt: date.updatedAt
|
|
|
|
}
|
2022-01-01 20:42:25 +01:00
|
|
|
export const userPublicWithoutSettingsObjectSchema = Type.Object(
|
|
|
|
userPublicWithoutSettingsSchema
|
|
|
|
)
|
2021-10-26 16:38:55 +02:00
|
|
|
|
|
|
|
export const userPublicSchema = {
|
|
|
|
...userPublicWithoutSettingsSchema,
|
|
|
|
settings: Type.Object(userSettingsSchema)
|
2021-10-24 06:09:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export const userPublicObjectSchema = Type.Object(userPublicSchema)
|
|
|
|
|
|
|
|
export const userCurrentSchema = Type.Object({
|
2021-10-26 16:38:55 +02:00
|
|
|
...userPublicSchema,
|
2021-10-24 06:09:43 +02:00
|
|
|
currentStrategy: Type.Union([...strategiesTypebox]),
|
|
|
|
strategies: Type.Array(Type.Union([...strategiesTypebox]))
|
|
|
|
})
|
|
|
|
|
2021-10-26 16:38:55 +02:00
|
|
|
export type User = Static<typeof userObjectSchema>
|
2021-10-24 06:09:43 +02:00
|
|
|
export type UserPublic = Static<typeof userPublicObjectSchema>
|
2022-01-01 20:42:25 +01:00
|
|
|
export type UserPublicWithoutSettings = Static<
|
|
|
|
typeof userPublicWithoutSettingsObjectSchema
|
|
|
|
>
|
2021-10-24 06:09:43 +02:00
|
|
|
export type UserCurrent = Static<typeof userCurrentSchema>
|