Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Edit Start Time of beacon #99

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion graphql/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down