Add joined field to Event api type

- Add joined field which accepts a userId and returns if the user has joined the event
- Add joined function to Event model
pull/4/head
trivernis 5 years ago
parent 19c407fdf1
commit 2f2ee8e214

@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- createActivity mutation - createActivity mutation
- activities table - activities table
- event and eventCount to UserData gql interface - event and eventCount to UserData gql interface
- joined field to Event gql type
### Removed ### Removed

@ -405,6 +405,9 @@ type Event {
"The participants of the event." "The participants of the event."
participants(first: Int=10, offset: Int=0): [User!]! participants(first: Int=10, offset: Int=0): [User!]!
"Returns if the user with the specified id has joined the event"
joined(userId: Int!): Boolean
} }
"respresents an access token entry with the value as the acutal token and expires as the date the token expires." "respresents an access token entry with the value as the acutal token and expires as the date the token expires."

@ -24,13 +24,30 @@ export class Event extends Model<Event> {
@BelongsToMany(() => User, () => EventParticipant) @BelongsToMany(() => User, () => EventParticipant)
public rParticipants: User[]; public rParticipants: User[];
/**
* Returns the group the event belongs to
*/
public async group(): Promise<Group> { public async group(): Promise<Group> {
return await this.$get("rGroup") as Group; return await this.$get("rGroup") as Group;
} }
/**
* Returns the participants of the event
* @param first
* @param offset
*/
public async participants({first, offset}: {first: number, offset: number}): Promise<User[]> { public async participants({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("rParticipants", {limit, offset}) as User[]; return await this.$get("rParticipants", {limit, offset}) as User[];
} }
/**
* Returns if the specified user has joined the event
* @param userId
*/
public async joined({userId}: {userId: number}): Promise<boolean> {
const participants = await this.$get("rParticipants", {where: {id: userId}}) as User[];
return participants.length !== 0;
}
} }

Loading…
Cancel
Save