Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
64 lines
1.3 KiB
TypeScript
64 lines
1.3 KiB
TypeScript
import { DataTypes, InferAttributes, InferCreationAttributes, Model } from "sequelize";
|
|
import { dbConection } from "./db.js";
|
|
|
|
export const modelName = "wg_peer";
|
|
export type Peer = InferAttributes<wgPeer, { omit: never; }>
|
|
export class wgPeer extends Model<InferAttributes<wgPeer>, InferCreationAttributes<wgPeer>> {
|
|
declare id?: number;
|
|
interfaceOwner: number;
|
|
owner: number;
|
|
privateKey: string;
|
|
presharedKey?: string;
|
|
uploadStats: number;
|
|
downloadStats: number;
|
|
IPv4?: string;
|
|
IPv6?: string;
|
|
};
|
|
|
|
wgPeer.init({
|
|
id: {
|
|
type: DataTypes.INTEGER,
|
|
autoIncrement: true,
|
|
primaryKey: true
|
|
},
|
|
interfaceOwner: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false,
|
|
},
|
|
owner: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false,
|
|
},
|
|
privateKey: {
|
|
type: DataTypes.CHAR(44),
|
|
allowNull: false,
|
|
unique: true
|
|
},
|
|
presharedKey: {
|
|
type: DataTypes.CHAR(44),
|
|
allowNull: true,
|
|
unique: true
|
|
},
|
|
uploadStats: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false,
|
|
defaultValue: 0,
|
|
},
|
|
downloadStats: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: false,
|
|
defaultValue: 0,
|
|
},
|
|
IPv4: {
|
|
type: DataTypes.CHAR,
|
|
unique: true,
|
|
},
|
|
IPv6: {
|
|
type: DataTypes.CHAR,
|
|
unique: true,
|
|
},
|
|
}, { sequelize: dbConection, modelName });
|
|
|
|
wgPeer.sync().then(async () => {
|
|
if (await wgPeer.count() === 0) {}
|
|
}); |