Skip to content

Commit 9a70800

Browse files
committed
lint fix
1 parent 58d0b88 commit 9a70800

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

api/main_endpoints/models/PermissionRequest.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ const PermissionRequestSchema = new Schema(
2323
);
2424

2525
// Compound unique index prevents duplicate active requests per user+type
26-
PermissionRequestSchema.index({ userId: 1, type: 1 }, { unique: true,
27-
partialFilterExpression: { deletedAt: null } });
26+
PermissionRequestSchema.index({ userId: 1, type: 1 }, { unique: true, partialFilterExpression: { deletedAt: null }});
2827

2928
module.exports = mongoose.model('PermissionRequest', PermissionRequestSchema);
3029

api/main_endpoints/routes/PermissionRequest.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ router.get('/get', async (req, res) => {
3939
try {
4040
const query = { deletedAt: null };
4141

42-
// If no userId provided, return all (officer+ only)
42+
// If theres no userId, return all for officers and admins
4343
if (!queryUserId) {
4444
if (!isOfficer) {
4545
return res.sendStatus(UNAUTHORIZED);
4646
}
4747
} else {
48-
// If userId provided, check permissions
48+
// If there is a userId, check their perms
4949
if (!isOfficer && queryUserId !== decoded.token._id.toString()) {
5050
return res.sendStatus(FORBIDDEN);
5151
}
5252
query.userId = queryUserId;
5353
}
5454

55-
// Optional type filter
55+
// If there is a type, filter by it
5656
if (type && Object.keys(PermissionRequestTypes).includes(type)) {
5757
query.type = type;
5858
}
@@ -79,7 +79,6 @@ router.post('/delete', async (req, res) => {
7979

8080
try {
8181
let request;
82-
8382
// Officers or admins can delete any request by id
8483
if (decoded.token.accessLevel >= membershipState.OFFICER && _id) {
8584
request = await PermissionRequest.findOne({

test/api/PermissionRequest.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,22 @@ describe('PermissionRequest', () => {
6363
});
6464

6565
describe('/GET get', () => {
66-
it('Should return 404 when request does not exist', async () => {
66+
it('Should return empty array when request does not exist', async () => {
6767
const userId = new mongoose.Types.ObjectId();
6868
setTokenStatus(true, { _id: userId, email: 'test@test.com', accessLevel: 'MEMBER' });
69-
const res = await test.sendGetRequest('/api/PermissionRequest/get?type=' + PermissionRequestTypes.LED_SIGN);
70-
expect(res).to.have.status(NOT_FOUND);
69+
const res = await test.sendGetRequest('/api/PermissionRequest/get?userId=' + userId + '&type=' + PermissionRequestTypes.LED_SIGN);
70+
expect(res).to.have.status(OK);
71+
expect(res.body).to.be.an('array').that.is.empty;
7172
});
7273

7374
it('Should return permission request when it exists', async () => {
7475
const userId = new mongoose.Types.ObjectId();
7576
setTokenStatus(true, { _id: userId, email: 'test@test.com', accessLevel: 'MEMBER' });
7677
await new PermissionRequest({ userId, type: PermissionRequestTypes.LED_SIGN }).save();
77-
const res = await test.sendGetRequest('/api/PermissionRequest/get?type=' + PermissionRequestTypes.LED_SIGN);
78+
const res = await test.sendGetRequest('/api/PermissionRequest/get?userId=' + userId + '&type=' + PermissionRequestTypes.LED_SIGN);
7879
expect(res).to.have.status(OK);
79-
expect(res.body.type).to.equal(PermissionRequestTypes.LED_SIGN);
80+
expect(res.body).to.be.an('array').with.length(1);
81+
expect(res.body[0].type).to.equal(PermissionRequestTypes.LED_SIGN);
8082
});
8183
});
8284

0 commit comments

Comments
 (0)