Backend implementation of events
parent
e854dc2687
commit
72329f0ce8
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue