Nareshkumar Rao
3 years ago
12 changed files with 177 additions and 148 deletions
@ -0,0 +1,53 @@ |
|||
import { TelegramID, UserRowID, VerificationString } from "../../types"; |
|||
import { User, UserInstance } from "./User"; |
|||
|
|||
export function getUserByTelegramID( |
|||
telegramID: TelegramID, |
|||
callback: (user?: UserInstance, message?: string) => void |
|||
): void { |
|||
User.findOne({ |
|||
where: { |
|||
telegram: telegramID, |
|||
}, |
|||
}) |
|||
.then((result) => { |
|||
callback(!!result ? result : undefined); |
|||
}) |
|||
.catch(() => { |
|||
callback(undefined); |
|||
}); |
|||
} |
|||
|
|||
export function getUserByRowID( |
|||
rowID: UserRowID, |
|||
callback: (user?: UserInstance, message?: string) => void |
|||
): void { |
|||
User.findOne({ |
|||
where: { |
|||
id: rowID, |
|||
}, |
|||
}) |
|||
.then((result) => { |
|||
callback(!!result ? result : undefined); |
|||
}) |
|||
.catch(() => { |
|||
callback(undefined); |
|||
}); |
|||
} |
|||
|
|||
export function getUserByVerification( |
|||
verification: VerificationString, |
|||
callback: (user?: UserInstance, message?: string) => void |
|||
): void { |
|||
User.findOne({ |
|||
where: { |
|||
verification: verification, |
|||
}, |
|||
}) |
|||
.then((result) => { |
|||
callback(!!result ? result : undefined); |
|||
}) |
|||
.catch(() => { |
|||
callback(undefined); |
|||
}); |
|||
} |
@ -1,11 +1,14 @@ |
|||
export type UserRowID = number; |
|||
export type TelegramID = number; |
|||
export type VerificationString = string; |
|||
/* |
|||
* Branding allows to use nominal typing and avoid errors |
|||
*/ |
|||
export type UserRowID = number & { __userRowIDBrand: any }; |
|||
export type TelegramID = number & { __telegramIDBrand: any }; |
|||
export type VerificationString = string & { __verificationStringBrand: any }; |
|||
|
|||
declare module "express-session" { |
|||
interface Session { |
|||
verified: boolean; |
|||
verifiedBy: UserRowID; |
|||
user: TelegramID; |
|||
isVerified: boolean; |
|||
verifiedByTelegramID: TelegramID; |
|||
userTelegramID: TelegramID; |
|||
} |
|||
} |
|||
|
Loading…
Reference in new issue