This commit is contained in:
2025-05-04 22:22:20 +03:00
parent cda54b1e95
commit ebd77a3e66
54 changed files with 1194 additions and 2580 deletions

18
src/types/Chats.ts Normal file
View File

@@ -0,0 +1,18 @@
interface Chat {
id: number
project_id: number
telegram_id: number
name: string
is_channel: boolean
bot_can_ban: boolean
user_count: number
last_update_time: number
description?: string
logo?: string
owner_id: number
[key: string]: unknown
}
export type {
Chat
}

21
src/types/Company.ts Normal file
View File

@@ -0,0 +1,21 @@
interface User {
id: number
project_id: number
telegram_id: number
firstname?: string
lastname?: string
username?: string
photo: string
phone: string
settings?: {
language?: string
fontSize?: number
timezone: number
}
[key: string]: unknown
}
export type {
Company,
CompanyParams
}

38
src/types/Project.ts Normal file
View File

@@ -0,0 +1,38 @@
interface ProjectParams {
name: string
description?: string
logo?: string
is_logo_bg: boolean
[key: string]: unknown
}
interface Project extends ProjectParams {
id: number
is_archived: boolean
chat_count: number
user_count: number
[key: string]: unknown
}
interface RawProjectParams {
name: string
description?: string
logo?: string
is_logo_bg: number
[key: string]: unknown
}
interface RawProject extends RawProjectParams{
id: number
is_archived: number
chat_count: number
user_count: number
[key: string]: unknown
}
export type {
Project,
ProjectParams,
RawProject,
RawProjectParams
}

20
src/types/Users.ts Normal file
View File

@@ -0,0 +1,20 @@
interface User {
id: number
project_id: number
telegram_id: number
firstname?: string
lastname?: string
username?: string
photo: string
phone: string
settings?: {
language?: string
fontSize?: number
timezone: number
}
[key: string]: unknown
}
export type {
User
}

View File

@@ -0,0 +1,38 @@
export function clientConverter<TClient, TServer extends Record<string, unknown>>(
data: TServer | null | undefined,
booleanFields: Array<keyof TClient>
): TClient {
if (!data) {
throw new Error("Invalid data: null or undefined");
}
return Object.entries(data).reduce((acc, [key, value]) => {
const typedKey = key as keyof TClient;
return {
...acc,
[typedKey]: booleanFields.includes(typedKey)
? Boolean(value)
: value
};
}, {} as TClient);
}
export function serverConverter<TClient, TServer extends Record<string, unknown>>(
data: TClient | null | undefined,
booleanFields: Array<keyof TClient>
): TServer {
if (!data) {
throw new Error("Invalid data: null or undefined");
}
return Object.entries(data).reduce((acc, [key, value]) => {
const typedKey = key as keyof TClient;
return {
...acc,
[key]: booleanFields.includes(typedKey)
? value ? 1 : 0
: value
};
}, {} as TServer);
}