Backend implementation of events

pull/2/head
Trivernis 5 years ago
parent e854dc2687
commit 72329f0ce8

@ -40,6 +40,8 @@ namespace dataaccess {
models.Group,
models.GroupAdmin,
models.GroupMember,
models.EventParticipant,
models.Event,
]);
} catch (err) {
globals.logger.error(err.message);

@ -0,0 +1,34 @@
import {BelongsTo, BelongsToMany, Column, ForeignKey, Model, NotNull, Table} from "sequelize-typescript";
import {EventParticipant} from "./EventParticipant";
import {Group} from "./Group";
import {User} from "./User";
@Table({underscored: true})
export class Event extends Model<Event> {
@NotNull
@Column({allowNull: false})
public name: string;
@NotNull
@Column({allowNull: false})
public dueDate: Date;
@NotNull
@ForeignKey(() => Group)
@Column({allowNull: false})
public groupId: number;
@BelongsTo(() => Group, "groupId")
public rGroup: Group;
@BelongsToMany(() => User, () => EventParticipant)
public rParticipants: User[];
public async group(): Promise<Group> {
return await this.$get("rGroup") as Group;
}
public async participants({first, offset}: {first: number, offset: number}): Promise<User[]> {
return await this.$get("rParticipants") as User[];
}
}

@ -0,0 +1,16 @@
import {BelongsTo, BelongsToMany, Column, ForeignKey, Model, NotNull, Table} from "sequelize-typescript";
import {Event} from "./Event";
import {User} from "./User";
@Table({underscored: true})
export class EventParticipant extends Model<EventParticipant> {
@NotNull
@ForeignKey(() => User)
@Column({allowNull: false})
public userId: number;
@NotNull
@ForeignKey(() => Event)
@Column({allowNull: false})
public eventId: number;
}

@ -1,5 +1,6 @@
import {BelongsTo, BelongsToMany, Column, ForeignKey, Model, NotNull, Table,} from "sequelize-typescript";
import {BelongsTo, BelongsToMany, Column, ForeignKey, HasMany, Model, NotNull, Table} from "sequelize-typescript";
import {ChatRoom} from "./ChatRoom";
import {Event} from "./Event";
import {GroupAdmin} from "./GroupAdmin";
import {GroupMember} from "./GroupMember";
import {User} from "./User";
@ -32,6 +33,9 @@ export class Group extends Model<Group> {
@BelongsTo(() => ChatRoom)
public rChat: ChatRoom;
@HasMany(() => Event, "groupId")
public rEvents: Event[];
public async creator(): Promise<User> {
return await this.$get("rCreator") as User;
}
@ -49,4 +53,8 @@ export class Group extends Model<Group> {
public async chat(): Promise<ChatRoom> {
return await this.$get("rChat") as ChatRoom;
}
public async events(): Promise<Event[]> {
return await this.$get("rEvents") as Event[];
}
}

@ -14,6 +14,8 @@ import {RequestNotFoundError} from "../errors/RequestNotFoundError";
import {ChatMember} from "./ChatMember";
import {ChatMessage} from "./ChatMessage";
import {ChatRoom} from "./ChatRoom";
import {Event} from "./Event";
import {EventParticipant} from "./EventParticipant";
import {Friendship} from "./Friendship";
import {Group} from "./Group";
import {GroupAdmin} from "./GroupAdmin";
@ -58,6 +60,9 @@ export class User extends Model<User> {
@BelongsToMany(() => Group, () => GroupAdmin)
public rAdministratedGroups: Group[];
@BelongsToMany(() => Event, () => EventParticipant)
public rEvents: Event[];
@BelongsToMany(() => Group, () => GroupMember)
public rGroups: Group[];
@ -134,6 +139,10 @@ export class User extends Model<User> {
return await this.$get("rGroups") as Group[];
}
public async events(): Promise<Event[]> {
return await this.$get("rEvents") as Event[];
}
public async denyRequest(sender: number, type: RequestType) {
const request = await this.$get("rReceivedRequests",
{where: {senderId: sender, requestType: type}}) as Request[];

@ -9,3 +9,5 @@ export {User} from "./User";
export {Group} from "./Group";
export {GroupAdmin} from "./GroupAdmin";
export {GroupMember} from "./GroupMember";
export {Event} from "./Event";
export {EventParticipant} from "./EventParticipant";

Loading…
Cancel
Save