feat: design applications and first api calls
Co-authored-by: Walid <87608619+WalidKorchi@users.noreply.github.com>
This commit is contained in:
13
models/Channel.ts
Normal file
13
models/Channel.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { Type } from '@sinclair/typebox'
|
||||
|
||||
import { date, id } from './utils'
|
||||
|
||||
export const types = [Type.Literal('text')]
|
||||
|
||||
export const channelSchema = {
|
||||
id,
|
||||
name: Type.String({ maxLength: 255 }),
|
||||
createdAt: date.createdAt,
|
||||
updatedAt: date.updatedAt,
|
||||
guildId: id
|
||||
}
|
12
models/Guild.ts
Normal file
12
models/Guild.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { Type } from '@sinclair/typebox'
|
||||
|
||||
import { date, id } from './utils'
|
||||
|
||||
export const guildSchema = {
|
||||
id,
|
||||
name: Type.String({ minLength: 3, maxLength: 30 }),
|
||||
icon: Type.String({ format: 'uri-reference' }),
|
||||
description: Type.String({ maxLength: 160 }),
|
||||
createdAt: date.createdAt,
|
||||
updatedAt: date.updatedAt
|
||||
}
|
12
models/Member.ts
Normal file
12
models/Member.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { Type } from '@sinclair/typebox'
|
||||
|
||||
import { date, id } from './utils'
|
||||
|
||||
export const memberSchema = {
|
||||
id,
|
||||
isOwner: Type.Boolean({ default: false }),
|
||||
createdAt: date.createdAt,
|
||||
updatedAt: date.updatedAt,
|
||||
userId: id,
|
||||
guildId: id
|
||||
}
|
20
models/Message.ts
Normal file
20
models/Message.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { Type } from '@sinclair/typebox'
|
||||
|
||||
import { date, id } from './utils'
|
||||
|
||||
export const types = [Type.Literal('text'), Type.Literal('file')]
|
||||
|
||||
export const messageSchema = {
|
||||
id,
|
||||
value: Type.String(),
|
||||
type: Type.Union(types, { default: 'text' }),
|
||||
mimetype: Type.String({
|
||||
maxLength: 255,
|
||||
default: 'text/plain',
|
||||
format: 'mimetype'
|
||||
}),
|
||||
createdAt: date.createdAt,
|
||||
updatedAt: date.updatedAt,
|
||||
memberId: id,
|
||||
channelId: id
|
||||
}
|
25
models/OAuth.ts
Normal file
25
models/OAuth.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { Type } from '@sinclair/typebox'
|
||||
|
||||
import { date, id } from './utils'
|
||||
|
||||
export const providers = ['google', 'github', 'discord'] as const
|
||||
export const strategies = [...providers, 'local'] as const
|
||||
|
||||
export const strategiesTypebox = strategies.map((strategy) =>
|
||||
Type.Literal(strategy)
|
||||
)
|
||||
export const providersTypebox = providers.map((provider) =>
|
||||
Type.Literal(provider)
|
||||
)
|
||||
|
||||
export type ProviderOAuth = typeof providers[number]
|
||||
export type AuthenticationStrategy = typeof strategies[number]
|
||||
|
||||
export const oauthSchema = {
|
||||
id,
|
||||
providerId: Type.String(),
|
||||
provider: Type.Union([...providersTypebox]),
|
||||
createdAt: date.createdAt,
|
||||
updatedAt: date.updatedAt,
|
||||
userId: id
|
||||
}
|
11
models/RefreshToken.ts
Normal file
11
models/RefreshToken.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Type } from '@sinclair/typebox'
|
||||
|
||||
import { date, id } from './utils'
|
||||
|
||||
export const refreshTokensSchema = {
|
||||
id,
|
||||
token: Type.String(),
|
||||
createdAt: date.createdAt,
|
||||
updatedAt: date.updatedAt,
|
||||
userId: id
|
||||
}
|
51
models/User.ts
Normal file
51
models/User.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import { Static, 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 }),
|
||||
email: Type.String({ minLength: 1, maxLength: 255, format: 'email' }),
|
||||
password: Type.String({ minLength: 1 }),
|
||||
logo: Type.String({ format: 'uri-reference' }),
|
||||
status: Type.String({ maxLength: 255 }),
|
||||
biography: Type.String(),
|
||||
website: Type.String({ maxLength: 255, format: 'uri-reference' }),
|
||||
isConfirmed: Type.Boolean({ default: false }),
|
||||
temporaryToken: Type.String(),
|
||||
temporaryExpirationToken: Type.String({ format: 'date-time' }),
|
||||
createdAt: date.createdAt,
|
||||
updatedAt: date.updatedAt
|
||||
}
|
||||
|
||||
const userSchemaWithSettings = {
|
||||
...userSchema,
|
||||
settings: Type.Object(userSettingsSchema)
|
||||
}
|
||||
|
||||
export const userPublicSchema = {
|
||||
id,
|
||||
name: userSchema.name,
|
||||
email: Type.Optional(userSchema.email),
|
||||
logo: Type.Optional(userSchema.logo),
|
||||
status: Type.Optional(userSchema.status),
|
||||
biography: Type.Optional(userSchema.biography),
|
||||
website: Type.Optional(userSchema.website),
|
||||
isConfirmed: userSchema.isConfirmed,
|
||||
createdAt: date.createdAt,
|
||||
updatedAt: date.updatedAt,
|
||||
settings: Type.Optional(Type.Object(userSettingsSchema))
|
||||
}
|
||||
|
||||
export const userPublicObjectSchema = Type.Object(userPublicSchema)
|
||||
|
||||
export const userCurrentSchema = Type.Object({
|
||||
...userSchemaWithSettings,
|
||||
currentStrategy: Type.Union([...strategiesTypebox]),
|
||||
strategies: Type.Array(Type.Union([...strategiesTypebox]))
|
||||
})
|
||||
|
||||
export type UserPublic = Static<typeof userPublicObjectSchema>
|
||||
export type UserCurrent = Static<typeof userCurrentSchema>
|
24
models/UserSettings.ts
Normal file
24
models/UserSettings.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { Type, Static } from '@sinclair/typebox'
|
||||
|
||||
import { date, id } from './utils'
|
||||
|
||||
export const languages = [Type.Literal('fr'), Type.Literal('en')]
|
||||
export const themes = [Type.Literal('light'), Type.Literal('dark')]
|
||||
|
||||
export const userSettingsSchema = {
|
||||
id,
|
||||
language: Type.Union(languages, { default: 'en' }),
|
||||
theme: Type.Union(themes, { default: 'dark' }),
|
||||
isPublicEmail: Type.Boolean({ default: false }),
|
||||
isPublicGuilds: Type.Boolean({ default: false }),
|
||||
createdAt: date.createdAt,
|
||||
updatedAt: date.updatedAt,
|
||||
userId: id
|
||||
}
|
||||
|
||||
export const userSettingsSchemaType = Type.Object(userSettingsSchema)
|
||||
|
||||
export type Theme = Static<typeof userSettingsSchema.theme>
|
||||
export type Language = Static<typeof userSettingsSchema.language>
|
||||
|
||||
export type UserSettings = Static<typeof userSettingsSchemaType>
|
14
models/utils.ts
Normal file
14
models/utils.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { Type } from '@sinclair/typebox'
|
||||
|
||||
export const date = {
|
||||
createdAt: Type.String({
|
||||
format: 'date-time',
|
||||
description: 'Created date time'
|
||||
}),
|
||||
updatedAt: Type.String({
|
||||
format: 'date-time',
|
||||
description: 'Last updated date time'
|
||||
})
|
||||
}
|
||||
|
||||
export const id = Type.Integer({ minimum: 1, description: 'Unique identifier' })
|
Reference in New Issue
Block a user