Skip to content

Commit

Permalink
#26 Camel-casing variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Jul 22, 2020
1 parent 22d6b1d commit c093251
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/pages/api/group/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import jwt from 'next-auth/jwt';
import middleware from '../../../middlewares/middleware';

const secret = process.env.AUTH_SECRET;
const fakeUserID = ObjectID('7b639ae33efb36eaf6447c55');
const fakeUserId = ObjectID('7b639ae33efb36eaf6447c55');

const handler = nc()
.use(middleware)
Expand Down Expand Up @@ -49,15 +49,15 @@ const handler = nc()
const token = await jwt.getJwt({ req, secret });
if (token && token.exp > 0) {
const memberQuery = (process.env.NODE_ENV === 'development')
? [{ 'members.id': ObjectID(token.user.id) }, { 'members.id': fakeUserID }]
? [{ 'members.id': ObjectID(token.user.id) }, { 'members.id': fakeUserId }]
: [{ 'members.id': ObjectID(token.user.id) }];
const nameToUpdate = req.body.name
? { name: req.body.name }
: {};
let documentToUpdate = {};
let documentByID = {};
let documentById = {};
if (req.body.updatedDocument) {
documentByID = { 'documents.id': ObjectID(req.body.updatedDocument.id) };
documentById = { 'documents.id': ObjectID(req.body.updatedDocument.id) };
documentToUpdate = {
'documents.$.slug': req.body.updatedDocument.slug,
'documents.$.name': req.body.updatedDocument.name,
Expand All @@ -66,22 +66,22 @@ const handler = nc()
const memberToPush = req.body.addedUser
? { members: req.body.addedUser }
: {};
const documentToPush = req.body.addedDoc
? { documents: req.body.addedDoc }
const documentToPush = req.body.addedDocument
? { documents: req.body.addedDocument }
: {};
const memberToPull = req.body.removedUserID
? { 'members.id': ObjectID(req.body.removedUserID) }
const memberToPull = req.body.removedUserId
? { 'members.id': ObjectID(req.body.removedUserId) }
: {};
const documentToPull = req.body.removedDocumentID
? { 'documents.id': ObjectID(req.body.removedDocumentID) }
const documentToPull = req.body.removedDocumentId
? { 'documents.id': ObjectID(req.body.removedDocumentId) }
: {};
await req.db
.collection('groups')
.findOneAndUpdate(
{
_id: ObjectID(req.query.id),
$or: memberQuery,
...documentByID,
...documentById,
},
{
$set: { ...nameToUpdate, ...documentToUpdate },
Expand Down

0 comments on commit c093251

Please sign in to comment.