implemented groups and password hashing
- added Groups with creator, admins, members, groupChats, name - implemented hashing before storing the password in the databasepull/2/head
parent
ba828da18a
commit
97ed21e469
@ -0,0 +1,65 @@
|
||||
import * as sqz from "sequelize";
|
||||
import {
|
||||
BelongsTo,
|
||||
BelongsToMany,
|
||||
Column,
|
||||
CreatedAt, ForeignKey,
|
||||
HasMany,
|
||||
Model,
|
||||
NotNull,
|
||||
Table,
|
||||
Unique,
|
||||
UpdatedAt,
|
||||
} from "sequelize-typescript";
|
||||
import {ChatMessage} from "./ChatMessage";
|
||||
import {ChatRoom} from "./ChatRoom";
|
||||
import {GroupAdmin} from "./GroupAdmin";
|
||||
import {GroupMember} from "./GroupMember";
|
||||
import {User} from "./User";
|
||||
|
||||
@Table({underscored: true})
|
||||
export class Group extends Model<Group> {
|
||||
@NotNull
|
||||
@Column( {allowNull: false})
|
||||
public name: string;
|
||||
|
||||
@NotNull
|
||||
@ForeignKey(() => User)
|
||||
@Column({allowNull: false})
|
||||
public creatorId: number;
|
||||
|
||||
@NotNull
|
||||
@ForeignKey(() => ChatRoom)
|
||||
@Column({allowNull: false})
|
||||
public chatId: number;
|
||||
|
||||
@BelongsTo(() => User, "creatorId")
|
||||
public rCreator: User;
|
||||
|
||||
@BelongsToMany(() => User, () => GroupAdmin)
|
||||
public rAdmins: User[];
|
||||
|
||||
@BelongsToMany(() => User, () => GroupMember)
|
||||
public rMembers: User[];
|
||||
|
||||
@BelongsTo(() => ChatRoom)
|
||||
public rChat: ChatRoom;
|
||||
|
||||
public async creator(): Promise<User> {
|
||||
return await this.$get("rCreator") as User;
|
||||
}
|
||||
|
||||
public async admins(): Promise<User[]> {
|
||||
return await this.$get("rAdmins") as User[];
|
||||
}
|
||||
|
||||
public async members({first, offset}: {first: number, offset: number}): Promise<User[]> {
|
||||
const limit = first || 10;
|
||||
offset = offset || 0;
|
||||
return await this.$get("rMembers", {limit, offset}) as User[];
|
||||
}
|
||||
|
||||
public async chat(): Promise<ChatRoom> {
|
||||
return await this.$get("rChat") as ChatRoom;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
import * as sqz from "sequelize";
|
||||
import {
|
||||
BelongsTo,
|
||||
BelongsToMany,
|
||||
Column,
|
||||
CreatedAt, ForeignKey,
|
||||
HasMany,
|
||||
Model, Not,
|
||||
NotNull,
|
||||
Table,
|
||||
Unique,
|
||||
UpdatedAt,
|
||||
} from "sequelize-typescript";
|
||||
import {Group} from "./Group";
|
||||
import {User} from "./User";
|
||||
|
||||
@Table({underscored: true})
|
||||
export class GroupAdmin extends Model<GroupAdmin> {
|
||||
@NotNull
|
||||
@ForeignKey(() => User)
|
||||
@Column({allowNull: false})
|
||||
public userId: number;
|
||||
|
||||
@NotNull
|
||||
@ForeignKey(() => Group)
|
||||
@Column({allowNull: false})
|
||||
public groupId: number;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
import * as sqz from "sequelize";
|
||||
import {
|
||||
BelongsTo,
|
||||
BelongsToMany,
|
||||
Column,
|
||||
CreatedAt, ForeignKey,
|
||||
HasMany,
|
||||
Model, Not,
|
||||
NotNull,
|
||||
Table,
|
||||
Unique,
|
||||
UpdatedAt,
|
||||
} from "sequelize-typescript";
|
||||
import {Group} from "./Group";
|
||||
import {User} from "./User";
|
||||
|
||||
@Table({underscored: true})
|
||||
export class GroupMember extends Model<GroupMember> {
|
||||
@NotNull
|
||||
@ForeignKey(() => User)
|
||||
@Column({allowNull: false})
|
||||
public userId: number;
|
||||
|
||||
@NotNull
|
||||
@ForeignKey(() => Group)
|
||||
@Column({allowNull: false})
|
||||
public groupId: number;
|
||||
}
|
Loading…
Reference in New Issue