Skip to content

Commit 687b276

Browse files
authored
Feat: New mutation allowing leader of the beacon to change duration. (#84)
* feat: new mutation allowing leader to change the duration of beacon. * rfrac: ran prettier. * used strict inequality. * Revert "used strict inequality." This reverts commit 6b99d9a.
1 parent 025aa11 commit 687b276

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

graphql/resolvers.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ const resolvers = {
113113
return newBeacon;
114114
},
115115

116+
changeBeaconDuration: async (_, { newExpiresAt, beaconID }, { user }) => {
117+
const beacon = await Beacon.findById(beaconID).populate("leader");
118+
119+
if (!beacon) return new UserInputError("No beacon exists with that id.");
120+
if (beacon.leader.id != user.id)
121+
return new Error("Only the leader is allowed to change the beacon duration.");
122+
if (beacon.startsAt.getTime() > newExpiresAt) return Error("Beacon can not expire before it has started.");
123+
124+
beacon.expiresAt = newExpiresAt;
125+
await beacon.save();
126+
127+
return beacon;
128+
},
129+
116130
joinBeacon: async (_, { shortcode }, { user, pubsub }) => {
117131
const beacon = await Beacon.findOne({ shortcode });
118132

graphql/schema.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ const typeDefs = gql`
103103
updateBeaconLocation(id: ID!, location: LocationInput!): Beacon!
104104
updateUserLocation(id: ID!, location: LocationInput!): User!
105105
changeLeader(beaconID: ID!, newLeaderID: ID!): Beacon!
106+
changeBeaconDuration(newExpiresAt: Float!, beaconID: ID!): Beacon!
106107
}
107108
108109
type Subscription {

0 commit comments

Comments
 (0)