diff --git a/graphql/resolvers.js b/graphql/resolvers.js index dafc4e7..fc23e02 100644 --- a/graphql/resolvers.js +++ b/graphql/resolvers.js @@ -101,7 +101,7 @@ const resolvers = { createBeacon: async (_, { beacon }, { user }) => { console.log(beacon); - + if (beacon.startsAt > beacon.expiresAt) return Error("Beacon can not expire before it has started."); const beaconDoc = new Beacon({ leader: user.id, shortcode: nanoid(), @@ -115,13 +115,13 @@ const resolvers = { return newBeacon; }, - changeBeaconDuration: async (_, { newExpiresAt, beaconID }, { user }) => { + changeBeaconDuration: async (_, { newStartsAt, newExpiresAt, beaconID }, { user }) => { const beacon = await Beacon.findById(beaconID); if (!beacon) return new UserInputError("No beacon exists with that id."); if (beacon.leader != user.id) return new Error("Only the leader is allowed to change the beacon duration."); - if (beacon.startsAt.getTime() > newExpiresAt) return Error("Beacon can not expire before it has started."); - + if (newStartsAt > newExpiresAt) return Error("Beacon can not expire before it has started."); + beacon.startsAt = newStartsAt; beacon.expiresAt = newExpiresAt; await beacon.save(); diff --git a/graphql/schema.js b/graphql/schema.js index 4493dd5..1edd3a6 100644 --- a/graphql/schema.js +++ b/graphql/schema.js @@ -103,7 +103,7 @@ const typeDefs = gql` updateBeaconLocation(id: ID!, location: LocationInput!): Beacon! updateUserLocation(id: ID!, location: LocationInput!): User! changeLeader(beaconID: ID!, newLeaderID: ID!): Beacon! - changeBeaconDuration(newExpiresAt: Float!, beaconID: ID!): Beacon! + changeBeaconDuration(newStartsAt: Float!, newExpiresAt: Float!, beaconID: ID!): Beacon! } type Subscription {