From 19c407fdf157575abe56ecc16e7f4c828b4ab419 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 12 Jan 2020 11:37:55 +0100 Subject: [PATCH 1/3] Add event and eventCount to User - Add event field to UserData API interface - Add eventCount field to UserData API interface --- CHANGELOG.md | 1 + src/graphql/schema.graphql | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd8da81..4e56d89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - getActivities field to receive all activities - createActivity mutation - activities table +- event and eventCount to UserData gql interface ### Removed diff --git a/src/graphql/schema.graphql b/src/graphql/schema.graphql index edfeabc..1d3e953 100644 --- a/src/graphql/schema.graphql +++ b/src/graphql/schema.graphql @@ -138,9 +138,15 @@ interface UserData { "The groups the user has joined" groups(first: Int=10, offset: Int=0): [Group] - "The numbef of groups the user has joined" + "The number of groups the user has joined" groupCount: Int! + "The events the user is participating in" + events(first: Int=10, offset: Int=0): [Event] + + "The number of events the user is participating in" + eventCount: Int! + "the points of the user" points: Int! @@ -189,6 +195,12 @@ type User implements UserData{ "The numbef of groups the user has joined" groupCount: Int! + "The events the user is participating in" + events(first: Int=10, offset: Int=0): [Event] + + "The number of events the user is participating in" + eventCount: Int! + "the levels of the user depending on the points" level: Int! } @@ -251,6 +263,12 @@ type Profile implements UserData { "The numbef of groups the user has joined" groupCount: Int! + "The events the user is participating in" + events(first: Int=10, offset: Int=0): [Event] + + "The number of events the user is participating in" + eventCount: Int! + "the points of the user" points: Int! From 2f2ee8e214ff15955d70351a48cb238f507ee00e Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 12 Jan 2020 11:47:34 +0100 Subject: [PATCH 2/3] 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 --- CHANGELOG.md | 1 + src/graphql/schema.graphql | 3 +++ src/lib/models/Event.ts | 17 +++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e56d89..8ed2ad1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - createActivity mutation - activities table - event and eventCount to UserData gql interface +- joined field to Event gql type ### Removed diff --git a/src/graphql/schema.graphql b/src/graphql/schema.graphql index 1d3e953..d7fb96e 100644 --- a/src/graphql/schema.graphql +++ b/src/graphql/schema.graphql @@ -405,6 +405,9 @@ type Event { "The participants of the event." 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." diff --git a/src/lib/models/Event.ts b/src/lib/models/Event.ts index efd069d..37858c8 100644 --- a/src/lib/models/Event.ts +++ b/src/lib/models/Event.ts @@ -24,13 +24,30 @@ export class Event extends Model { @BelongsToMany(() => User, () => EventParticipant) public rParticipants: User[]; + /** + * Returns the group the event belongs to + */ public async group(): Promise { 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 { const limit = first ?? 10; offset = offset ?? 0; 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 { + const participants = await this.$get("rParticipants", {where: {id: userId}}) as User[]; + return participants.length !== 0; + } } From ea8a97beb5bd620e747970174a9035dc23b93000 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 12 Jan 2020 11:53:13 +0100 Subject: [PATCH 3/3] Add joined field to Group api type - Add joined field to Group type which accepts a userId and returns if the user is a member of the group - Add joined function to Group model --- CHANGELOG.md | 1 + src/graphql/schema.graphql | 3 +++ src/lib/models/Group.ts | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ed2ad1..40fdbcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - activities table - event and eventCount to UserData gql interface - joined field to Event gql type +- joined field to Group gql type ### Removed diff --git a/src/graphql/schema.graphql b/src/graphql/schema.graphql index d7fb96e..b4c2162 100644 --- a/src/graphql/schema.graphql +++ b/src/graphql/schema.graphql @@ -388,6 +388,9 @@ type Group { "the events of the group" events(first: Int=10, offset: Int=0): [Event!]! + + "If the user with the specified id has joined the group" + joined(userId: Int!): Boolean } type Event { diff --git a/src/lib/models/Group.ts b/src/lib/models/Group.ts index 7bf801f..8b3fd7f 100644 --- a/src/lib/models/Group.ts +++ b/src/lib/models/Group.ts @@ -47,29 +47,59 @@ export class Group extends Model { @HasMany(() => Event, "groupId") public rEvents: Event[]; + /** + * Returns the creator of the group + */ public async creator(): Promise { 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 { const limit = first ?? 10; offset = offset ?? 0; 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 { const limit = first ?? 10; offset = offset ?? 0; return await this.$get("rMembers", {limit, offset}) as User[]; } + /** + * Returns the chat that belongs to the group + */ public async chat(): Promise { 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 { const limit = first ?? 10; offset = offset ?? 0; 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 { + const members = await this.$get("rMembers", {where: {id: userId}}) as User[]; + return members.length !== 0; + } }