Nareshkumar Rao
3 years ago
10 changed files with 114 additions and 108 deletions
@ -0,0 +1,23 @@ |
|||||
|
import { DataTypes, Model } from "sequelize"; |
||||
|
import { UserRowID } from "../../types"; |
||||
|
import { sequelize } from "../db"; |
||||
|
|
||||
|
interface ContactAttributes { |
||||
|
user: UserRowID; |
||||
|
with: UserRowID; |
||||
|
} |
||||
|
export interface ContactInterface |
||||
|
extends Model<ContactAttributes, ContactAttributes>, |
||||
|
ContactAttributes {} |
||||
|
export const Contact = sequelize.define<ContactInterface>("Contact", { |
||||
|
user: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: false, |
||||
|
}, |
||||
|
with: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: false, |
||||
|
}, |
||||
|
}); |
||||
|
|
||||
|
Contact.sync(); |
@ -0,0 +1,45 @@ |
|||||
|
import { DataTypes, Model } from "sequelize"; |
||||
|
import { TelegramID, UserRowID, VerificationString } from "../../types"; |
||||
|
import { sequelize } from "../db"; |
||||
|
|
||||
|
interface UserAttributes { |
||||
|
id: UserRowID; |
||||
|
telegram: TelegramID; |
||||
|
verification: VerificationString; |
||||
|
isInfected: boolean; |
||||
|
} |
||||
|
interface UserCreationAttributes { |
||||
|
telegram: TelegramID; |
||||
|
} |
||||
|
export interface UserInstance |
||||
|
extends Model<UserAttributes, UserCreationAttributes>, |
||||
|
UserAttributes {} |
||||
|
|
||||
|
export const User = sequelize.define<UserInstance>("User", { |
||||
|
id: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
autoIncrement: true, |
||||
|
primaryKey: true, |
||||
|
}, |
||||
|
telegram: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: false, |
||||
|
unique: true, |
||||
|
}, |
||||
|
verification: { |
||||
|
type: DataTypes.STRING, |
||||
|
}, |
||||
|
isInfected: { |
||||
|
type: DataTypes.BOOLEAN, |
||||
|
}, |
||||
|
}); |
||||
|
|
||||
|
User.sync().then(() => { |
||||
|
if (process.env.ADMIN_USERNAME && process.env.ADMIN_PASSWORD) { |
||||
|
User.create({ |
||||
|
telegram: 12345, |
||||
|
}).catch(() => { |
||||
|
console.log("Couldn't create admin account. Probably exists."); |
||||
|
}); |
||||
|
} |
||||
|
}); |
@ -0,0 +1,11 @@ |
|||||
|
export type UserRowID = number; |
||||
|
export type TelegramID = number; |
||||
|
export type VerificationString = string; |
||||
|
|
||||
|
declare module "express-session" { |
||||
|
interface Session { |
||||
|
verified: boolean; |
||||
|
verifiedBy: UserRowID; |
||||
|
user: TelegramID; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue