2023-10-23 23:33:39 +02:00
|
|
|
import type { Static } from "@sinclair/typebox"
|
|
|
|
import { Type } from "@sinclair/typebox"
|
2021-10-24 06:09:43 +02:00
|
|
|
|
2023-10-23 23:33:39 +02:00
|
|
|
import { strategiesTypebox } from "./OAuth"
|
|
|
|
import { userSettingsSchema } from "./UserSettings"
|
|
|
|
import { date, id } from "./utils"
|
2021-10-24 06:09:43 +02:00
|
|
|
|
|
|
|
export const userSchema = {
|
|
|
|
id,
|
|
|
|
name: Type.String({ minLength: 1, maxLength: 30 }),
|
2023-10-23 23:33:39 +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([
|
2023-10-23 23:33:39 +02:00
|
|
|
Type.String({ minLength: 1, format: "uri-reference" }),
|
|
|
|
Type.Null(),
|
2021-11-13 21:50:34 +01:00
|
|
|
]),
|
|
|
|
status: Type.Union([
|
|
|
|
Type.String({ minLength: 1, maxLength: 50 }),
|
2023-10-23 23:33:39 +02:00
|
|
|
Type.Null(),
|
2021-11-13 21:50:34 +01:00
|
|
|
]),
|
|
|
|
biography: Type.Union([
|
|
|
|
Type.String({ minLength: 1, maxLength: 160 }),
|
2023-10-23 23:33:39 +02:00
|
|
|
Type.Null(),
|
2021-11-13 21:50:34 +01:00
|
|
|
]),
|
|
|
|
website: Type.Union([
|
|
|
|
Type.String({
|
|
|
|
minLength: 1,
|
|
|
|
maxLength: 255,
|
2023-10-23 23:33:39 +02:00
|
|
|
format: "uri",
|
2021-11-13 21:50:34 +01:00
|
|
|
}),
|
2023-10-23 23:33:39 +02:00
|
|
|
Type.Null(),
|
2021-11-13 21:50:34 +01:00
|
|
|
]),
|
2021-10-24 06:09:43 +02:00
|
|
|
isConfirmed: Type.Boolean({ default: false }),
|
|
|
|
temporaryToken: Type.String(),
|
2023-10-23 23:33:39 +02:00
|
|
|
temporaryExpirationToken: Type.String({ format: "date-time" }),
|
2021-10-24 06:09:43 +02:00
|
|
|
createdAt: date.createdAt,
|
2023-10-23 23:33:39 +02:00
|
|
|
updatedAt: date.updatedAt,
|
2021-10-24 06:09:43 +02:00
|
|
|
}
|
|
|
|
|
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,
|
2023-10-23 23:33:39 +02:00
|
|
|
updatedAt: date.updatedAt,
|
2021-10-26 16:38:55 +02:00
|
|
|
}
|
2022-01-01 20:42:25 +01:00
|
|
|
export const userPublicWithoutSettingsObjectSchema = Type.Object(
|
2023-10-23 23:33:39 +02:00
|
|
|
userPublicWithoutSettingsSchema,
|
2022-01-01 20:42:25 +01:00
|
|
|
)
|
2021-10-26 16:38:55 +02:00
|
|
|
|
|
|
|
export const userPublicSchema = {
|
|
|
|
...userPublicWithoutSettingsSchema,
|
2023-10-23 23:33:39 +02:00
|
|
|
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]),
|
2023-10-23 23:33:39 +02:00
|
|
|
strategies: Type.Array(Type.Union([...strategiesTypebox])),
|
2021-10-24 06:09:43 +02:00
|
|
|
})
|
|
|
|
|
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>
|