|
|
@ -47,29 +47,59 @@ export class Group extends Model<Group> {
|
|
|
|
@HasMany(() => Event, "groupId")
|
|
|
|
@HasMany(() => Event, "groupId")
|
|
|
|
public rEvents: Event[];
|
|
|
|
public rEvents: Event[];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Returns the creator of the group
|
|
|
|
|
|
|
|
*/
|
|
|
|
public async creator(): Promise<User> {
|
|
|
|
public async creator(): Promise<User> {
|
|
|
|
return await this.$get("rCreator") as User;
|
|
|
|
return await this.$get("rCreator") as User;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Returns the list of admins with pagination
|
|
|
|
|
|
|
|
* @param first
|
|
|
|
|
|
|
|
* @param offset
|
|
|
|
|
|
|
|
*/
|
|
|
|
public async admins({first, offset}: { first: number, offset: number }): Promise<User[]> {
|
|
|
|
public async admins({first, offset}: { first: number, offset: number }): Promise<User[]> {
|
|
|
|
const limit = first ?? 10;
|
|
|
|
const limit = first ?? 10;
|
|
|
|
offset = offset ?? 0;
|
|
|
|
offset = offset ?? 0;
|
|
|
|
return await this.$get("rAdmins", {limit, offset}) as User[];
|
|
|
|
return await this.$get("rAdmins", {limit, offset}) as User[];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Returns the list of members with pagination
|
|
|
|
|
|
|
|
* @param first
|
|
|
|
|
|
|
|
* @param offset
|
|
|
|
|
|
|
|
*/
|
|
|
|
public async members({first, offset}: { first: number, offset: number }): Promise<User[]> {
|
|
|
|
public async members({first, offset}: { first: number, offset: number }): Promise<User[]> {
|
|
|
|
const limit = first ?? 10;
|
|
|
|
const limit = first ?? 10;
|
|
|
|
offset = offset ?? 0;
|
|
|
|
offset = offset ?? 0;
|
|
|
|
return await this.$get("rMembers", {limit, offset}) as User[];
|
|
|
|
return await this.$get("rMembers", {limit, offset}) as User[];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Returns the chat that belongs to the group
|
|
|
|
|
|
|
|
*/
|
|
|
|
public async chat(): Promise<ChatRoom> {
|
|
|
|
public async chat(): Promise<ChatRoom> {
|
|
|
|
return await this.$get("rChat") as ChatRoom;
|
|
|
|
return await this.$get("rChat") as ChatRoom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Returns all group events with pagination
|
|
|
|
|
|
|
|
* @param first
|
|
|
|
|
|
|
|
* @param offset
|
|
|
|
|
|
|
|
*/
|
|
|
|
public async events({first, offset}: { first: number, offset: number }): Promise<Event[]> {
|
|
|
|
public async events({first, offset}: { first: number, offset: number }): Promise<Event[]> {
|
|
|
|
const limit = first ?? 10;
|
|
|
|
const limit = first ?? 10;
|
|
|
|
offset = offset ?? 0;
|
|
|
|
offset = offset ?? 0;
|
|
|
|
return await this.$get("rEvents", {limit, offset}) as Event[];
|
|
|
|
return await this.$get("rEvents", {limit, offset}) as Event[];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Returns if a user has joined the group
|
|
|
|
|
|
|
|
* @param userId
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public async joined({userId}: {userId: number}): Promise<boolean> {
|
|
|
|
|
|
|
|
const members = await this.$get("rMembers", {where: {id: userId}}) as User[];
|
|
|
|
|
|
|
|
return members.length !== 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|