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

Chris osab #213

Open
wants to merge 5 commits into
base: osa-mentorb
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
3 changes: 2 additions & 1 deletion api/models/RideModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ var RideSchema = new Schema({
riders: [ { type: Schema.Types.ObjectId, ref: User } ],
notes: String, // notes section for personal message from ride creator
spots: { type: Number, default: 3 },
typeofcar: String
typeofcar: String,
receipt: {type: Buffer}
//cost: { type: Number },
//ownerDriving: { type: Boolean, default: false },
});
Expand Down
27 changes: 26 additions & 1 deletion api/schema/RideSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,31 @@ RideTC.addResolver({
})
},
})

RideTC.addResolver({
name: 'updateReceipt',
type: RideTC,
args: { base64: 'String!', rideID: 'ID!' },
resolve: async ({ source, args, context, info }) => {
const decode = new Promise((resolve, reject) => {
const decoded = atob(args.base64);
if (decoded) {
resolve(decoded);
} else {
reject(new Error("Decoding went wrong"));
}
});
decode
.then(async (decoded) => {
let updatedRide = await Ride.findByIdAndUpdate(args.rideID, {
receipt: decoded,
});
return updatedRide;
})
.catch((error) => {
console.log(error);
});
},
});
/**
* Used to update the draft sessions for a schedule
* Can either add or remove a session from their draft sessions
Expand Down Expand Up @@ -165,6 +189,7 @@ const RideMutation = {
return next(rp)
}
),
addReceipt: RideTC.getResolver('updateReceipt')
}

async function authMiddleware(resolve, source, args, context, info) {
Expand Down
Loading