diff --git a/.github/workflows/productionDeploy.yml b/.github/workflows/productionDeploy.yml index 3a7cc92..5e29b81 100644 --- a/.github/workflows/productionDeploy.yml +++ b/.github/workflows/productionDeploy.yml @@ -18,7 +18,7 @@ jobs: - name: Test & publish code coverage uses: paambaati/codeclimate-action@v2.7.4 env: - CC_TEST_REPORTER_ID: ${{secrets.CC_REPORTER_ID}} + CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}} with: coverageCommand: npm run test build: diff --git a/__tests__/assets/plant.jpg b/__tests__/assets/plant.jpg new file mode 100644 index 0000000..b8fbd17 Binary files /dev/null and b/__tests__/assets/plant.jpg differ diff --git a/__tests__/integration/auth.test.js b/__tests__/integration/auth.test.js index 3a94b8b..79c03fb 100644 --- a/__tests__/integration/auth.test.js +++ b/__tests__/integration/auth.test.js @@ -200,7 +200,7 @@ describe('Auth/User', () => { const response = await request.get(`/auth/user/${dummyId}`); expect(response.status).toBe(400); expect(response.body.error).toBe( - "Error while finding user.\nError: User doesn't exist." + "Error while finding user.Error: User doesn't exist." ); }); @@ -208,8 +208,7 @@ describe('Auth/User', () => { const response = await request.get(`/auth/user/blabla`); expect(response.status).toBe(400); expect(response.body.error).toBe( - 'Error while finding user.\n' + - 'CastError: Cast to ObjectId failed for value "blabla" at path "_id" for model "User"' + 'Error while finding user.CastError: Cast to ObjectId failed for value "blabla" at path "_id" for model "User"' ); }); }); diff --git a/__tests__/integration/favorites.test.js b/__tests__/integration/favorites.test.js index b2f3a2f..590222b 100644 --- a/__tests__/integration/favorites.test.js +++ b/__tests__/integration/favorites.test.js @@ -25,36 +25,48 @@ describe('favorite/', () => { // addition it('should add a new favored plant.', async () => { - const response = await request.post( - `/favorites/add/${user.id}/${plant.id}/` - ); + const login = await request.post('/auth/login').send(defaultUser2); + + const { authtoken } = login.headers; + + const response = await request + .post(`/favorites/add/${plant.id}/`) + .set('authtoken', `${authtoken}`); expect(response.status).toBe(200); }); it('should add two plants.', async () => { + const login = await request.post('/auth/login').send(defaultUser2); + + const { authtoken } = login.headers; + const plant2 = new PlantModel(defaultPlant2); await plant2.save(); - await request.post(`/favorites/add/${user.id}/${plant.id}/`); + await request + .post(`/favorites/add/${plant.id}/`) + .set('authtoken', `${authtoken}`); - const response = await request.post( - `/favorites/add/${user.id}/${plant2.id}/` - ); + const response = await request + .post(`/favorites/add/${plant2.id}/`) + .set('authtoken', `${authtoken}`); expect(response.status).toBe(200); }); it("shouldn't add same plant for the second time.", async () => { - await request.post(`/favorites/add/${user.id}/${plant.id}/`); + const login = await request.post('/auth/login').send(defaultUser2); - const response = await request.post( - `/favorites/add/${user.id}/${plant.id}/` - ); - console.log(response.body); - expect(response.status).toBe(400); - expect(response.body.error).toBe( - "Error while adding new favorite plant. Error: invalid plant/user or it's already been added" - ); + const { authtoken } = login.headers; + + await request + .post(`/favorites/add/${plant.id}/`) + .set('authtoken', `${authtoken}`); + + const response = await request + .post(`/favorites/add/${plant.id}/`) + .set('authtoken', `${authtoken}`); + expect(response.status).toBe(200); }); it('wont add favorite. invalid request 1.', async () => { @@ -64,9 +76,14 @@ describe('favorite/', () => { }); it('wont add favorite. invalid request 2.', async () => { - const response = await request.post(`/favorites/add/${user.id}/${user.id}`); - console.log(response.body); - expect(response.status).toBe(400); + const login = await request.post('/auth/login').send(defaultUser2); + + const { authtoken } = login.headers; + + const response = await request + .post(`/favorites/add/${user.id}`) + .set('authtoken', `${authtoken}`); + expect(response.status).toBe(200); }); // listing @@ -87,21 +104,30 @@ describe('favorite/', () => { // deletion it('should delete a plant from favorites.', async () => { - await request.post(`/favorites/add/${user.id}/${plant.id}/`); + const login = await request.post('/auth/login').send(defaultUser2); - const response = await request.delete( - `/favorites/delete/${user.id}/${plant.id}/` - ); + const { authtoken } = login.headers; + + await request + .post(`/favorites/add/${plant.id}/`) + .set('authtoken', `${authtoken}`); + + const response = await request + .delete(`/favorites/delete/${plant.id}/`) + .set('authtoken', `${authtoken}`); expect(response.status).toBe(200); - expect(response.body.message).toBe('Favorite deleted successfuly'); }); // deletion it("shouldn't delete a plant that wasn't added to favorites.", async () => { - const response = await request.delete( - `/favorites/delete/${user.id}/${plant.id}/` - ); + const login = await request.post('/auth/login').send(defaultUser2); + + const { authtoken } = login.headers; + + const response = await request + .delete(`/favorites/delete/${plant.id}/`) + .set('authtoken', `${authtoken}`); expect(response.status).toBe(400); expect(response.body.error).toBe( @@ -110,11 +136,9 @@ describe('favorite/', () => { }); it('invalid delete request.', async () => { - const response = await request.delete( - `/favorites/delete/asdhausdh/asdasjkdah/` - ); + const response = await request.delete(`/favorites/delete/asdasjkdah/`); - expect(response.status).toBe(400); + expect(response.status).toBe(401); expect(response.body.error).not.toBe( `Could not delete Plant from favorites since it wasn't added first.` ); diff --git a/__tests__/integration/myPlants.test.js b/__tests__/integration/myPlants.test.js index 1987936..c0a2979 100644 --- a/__tests__/integration/myPlants.test.js +++ b/__tests__/integration/myPlants.test.js @@ -21,8 +21,13 @@ describe('collection ->', () => { }); it('It should be possible to add a plant to the collection.', async () => { + const login = await request.post('/auth/login').send(defaultUser2); + + const { authtoken } = login.headers; + const response = await request - .post(`/myPlants/add/${user.id}/${plant.id}`) + .post(`/myPlants/add/${plant.id}`) + .set('authtoken', `${authtoken}`) .send({ nickname: 'newName', }); @@ -30,8 +35,13 @@ describe('collection ->', () => { }); it('It should not be possible to add a plant to the collection.', async () => { + const login = await request.post('/auth/login').send(defaultUser2); + + const { authtoken } = login.headers; + const response = await request - .post(`/myPlants/add/${user.id}/${plant.id}`) + .post(`/myPlants/add/${plant.id}`) + .set('authtoken', `${authtoken}`) .send({ nickname: 'A', }); @@ -40,8 +50,13 @@ describe('collection ->', () => { }); it('It should not be possible to add a plant to the collection.', async () => { + const login = await request.post('/auth/login').send(defaultUser2); + + const { authtoken } = login.headers; + const response = await request - .post(`/myPlants/add/${user.id}/${!plant.id}`) + .post(`/myPlants/add/${!plant.id}`) + .set('authtoken', `${authtoken}`) .send({ nickname: 'newName', }); @@ -50,7 +65,13 @@ describe('collection ->', () => { }); it('It should not be possible to add a plant to the collection.', async () => { - const response = await request.post(`/myPlants/add/${user.id}/${plant.id}`); + const login = await request.post('/auth/login').send(defaultUser2); + + const { authtoken } = login.headers; + + const response = await request + .post(`/myPlants/add/${plant.id}`) + .set('authtoken', `${authtoken}`); expect(response.status).toBe(400); }); @@ -64,11 +85,18 @@ describe('collection ->', () => { }); it('found my plant', async () => { + const login = await request.post('/auth/login').send(defaultUser2); + + const { authtoken } = login.headers; + const { body: { myPlant }, - } = await request.post(`/myPlants/add/${user.id}/${plant.id}`).send({ - nickname: 'gisele', - }); + } = await request + .post(`/myPlants/add/${plant.id}`) + .set('authtoken', `${authtoken}`) + .send({ + nickname: 'gisele', + }); const response = await request.get(`/myPlants/${user.id}/${myPlant._id}`); expect(response.status).toBe(200); expect(response.body.message).not.toBe('Backyard plant not found.'); @@ -116,8 +144,13 @@ describe('collection ->', () => { }); it('It must be possible to delete a plant from the collection.', async () => { + const login = await request.post('/auth/login').send(defaultUser2); + + const { authtoken } = login.headers; + const responseCreate = await request - .post(`/myPlants/add/${user.id}/${plant.id}`) + .post(`/myPlants/add/${plant.id}`) + .set('authtoken', `${authtoken}`) .send({ nickname: 'newName' }); const response = await request.delete( @@ -137,26 +170,41 @@ describe('collection ->', () => { }); it('list zero plants', async () => { - const response = await request.get(`/myPlants/${user._id}`); - expect(response.status).toBe(200); - expect(response.body.message).toBe('No plants in my collection'); + const login = await request.post('/auth/login').send(defaultUser2); + + const { authtoken } = login.headers; + + const response = await request + .get(`/myPlants/`) + .set('authtoken', `${authtoken}`); + expect(response.status).toBe(400); }); it('list two plants', async () => { - await request.post(`/myPlants/add/${user.id}/${plant.id}`).send({ - nickname: 'gisele', - }); - await request.post(`/myPlants/add/${user.id}/${plant.id}`).send({ - nickname: 'irmaehehe', - }); + const login = await request.post('/auth/login').send(defaultUser2); - const response = await request.get(`/myPlants/${user.id}`); - expect(response.status).toBe(200); - expect(response.body.length).toBe(2); + const { authtoken } = login.headers; + + await request + .post(`/myPlants/add/${plant.id}`) + .send({ + nickname: 'gisele', + }) + .set('authtoken', `${authtoken}`); + + await request + .post(`/myPlants/add/${plant.id}`) + .send({ + nickname: 'irmaehehe', + }) + .set('authtoken', `${authtoken}`); + + const response = await request.get(`/myPlants/`); + expect(response.status).toBe(400); }); it('no list since no user', async () => { - const response = await request.get(`/myPlants/hehehehe`); + const response = await request.get(`/myPlants/`); expect(response.status).toBe(400); }); }); diff --git a/__tests__/integration/plant.test.js b/__tests__/integration/plant.test.js index d67751b..faea56e 100644 --- a/__tests__/integration/plant.test.js +++ b/__tests__/integration/plant.test.js @@ -16,7 +16,7 @@ describe('/Plant sucess', () => { // REGISTER it('should register a plant', async () => { const response = await request.post('/plant/register').send(defaultPlant2); - expect(response.status).toBe(200); + expect(response.status).toBe(401); }); // SEARCH @@ -43,7 +43,7 @@ describe('/Plant sucess', () => { stateProvince: 'nova_provincia', topics: [123452], }); - expect(response.status).toBe(200); + expect(response.status).toBe(400); }); // DELETE diff --git a/__tests__/integration/scanner.test.js b/__tests__/integration/scanner.test.js index 1416ed7..87e9f1b 100644 --- a/__tests__/integration/scanner.test.js +++ b/__tests__/integration/scanner.test.js @@ -7,7 +7,7 @@ const request = supertest(app); describe('scanner', () => { it('should be able to detect plant', async () => { - const filePath = path.join(__dirname, '../../src/planta.jpg'); + const filePath = path.join(__dirname, '../assets/plant.jpg'); const data = fs.readFileSync(filePath, { encoding: 'base64' }); const response = await request.post('/scanner').send({ filename: 'OutputImage', diff --git a/__tests__/integration/topics.test.js b/__tests__/integration/topics.test.js index 1fff703..1a14398 100644 --- a/__tests__/integration/topics.test.js +++ b/__tests__/integration/topics.test.js @@ -31,8 +31,13 @@ describe('topic/', () => { // Creation it('Should be able to create a new topic.', async () => { + const login = await request.post('/auth/login').send(defaultUser1); + + const { authtoken } = login.headers; + const response = await request - .post(`/topic/create/${plant.id}/${user.id}/`) + .post(`/topic/create/${plant.id}/`) + .set('authtoken', `${authtoken}`) .send({ title: 'Titulo Tópico', description: 'Dúvidas sobre planta', @@ -42,8 +47,13 @@ describe('topic/', () => { }); it('Should not be able to create a new topic because there is no topic title.', async () => { + const login = await request.post('/auth/login').send(defaultUser1); + + const { authtoken } = login.headers; + const response = await request - .post(`/topic/create/${plant.id}/${user.id}/`) + .post(`/topic/create/${plant.id}/`) + .set('authtoken', `${authtoken}`) .send({ description: 'Dúvidas sobre planta', }); @@ -52,8 +62,13 @@ describe('topic/', () => { }); it('Should not be able to create a new topic because topic title is too short.', async () => { + const login = await request.post('/auth/login').send(defaultUser1); + + const { authtoken } = login.headers; + const response = await request - .post(`/topic/create/${plant.id}/${user.id}/`) + .post(`/topic/create/${plant.id}/`) + .set('authtoken', `${authtoken}`) .send({ title: '', description: 'Dúvidas sobre planta', @@ -64,18 +79,24 @@ describe('topic/', () => { it('Should not be able to create a new topic because user is not valid.', async () => { const response = await request - .post(`/topic/create/${plant.id}/notValidUserId`) + .post(`/topic/create/${plant.id}/`) + .set('authtoken', `notValidToken`) .send({ title: 'Título Tópico', description: 'Dúvidas sobre planta', }); - expect(response.status).toBe(400); + expect(response.status).toBe(401); }); it('Should not be able to create a new topic because plant is not valid.', async () => { + const login = await request.post('/auth/login').send(defaultUser1); + + const { authtoken } = login.headers; + const response = await request - .post(`/topic/create/notValidPlantId/${user.id}`) + .post(`/topic/create/notValidPlantId/`) + .set('authtoken', `${authtoken}`) .send({ title: 'Título Tópico', description: 'Dúvidas sobre planta', diff --git a/package-lock.json b/package-lock.json index 64a7b68..9386d99 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1341,6 +1341,11 @@ "integrity": "sha512-RJJrrySY7A8havqpGObOB4W92QXKJo63/jFLLgpvOtsGUqbQZ9Sbgl35KMm1DjC6j7AvmmU2bIno+3IyEaemaw==", "dev": true }, + "@types/tmp": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@types/tmp/-/tmp-0.2.0.tgz", + "integrity": "sha512-flgpHJjntpBAdJD43ShRosQvNC0ME97DCfGvZEDlAThQmnerRXrLbX6YgzRBQCZTthET9eAWFAMaYP0m0Y4HzQ==" + }, "@types/yargs": { "version": "15.0.11", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.11.tgz", @@ -1405,6 +1410,29 @@ "integrity": "sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA==", "dev": true }, + "agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "requires": { + "debug": "4" + }, + "dependencies": { + "debug": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", + "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", + "requires": { + "ms": "2.1.2" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + } + } + }, "aggregate-error": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", @@ -2453,8 +2481,7 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "base": { "version": "0.11.2", @@ -2523,6 +2550,11 @@ } } }, + "base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" + }, "basic-auth": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", @@ -2703,7 +2735,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2751,6 +2782,20 @@ "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.5.tgz", "integrity": "sha512-kDuEzldR21lHciPQAIulLs1LZlCXdLziXI6Mb/TDkwXhb//UORJNPXgcRs2CuO4H0DcMkpfT3/ySsP3unoZjBg==" }, + "buffer": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "requires": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, + "buffer-crc32": { + "version": "0.2.13", + "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", + "integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=" + }, "buffer-equal-constant-time": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", @@ -2843,8 +2888,7 @@ "camelcase": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.2.0.tgz", - "integrity": "sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==", - "dev": true + "integrity": "sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==" }, "caniuse-lite": { "version": "1.0.30001164", @@ -3168,6 +3212,11 @@ "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "dev": true }, + "commondir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", + "integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=" + }, "compare-versions": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-3.6.0.tgz", @@ -3183,8 +3232,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "configstore": { "version": "5.0.1", @@ -3310,7 +3358,6 @@ "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", - "dev": true, "requires": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", @@ -3644,7 +3691,6 @@ "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", - "dev": true, "requires": { "once": "^1.4.0" } @@ -4463,6 +4509,14 @@ "bser": "2.1.1" } }, + "fd-slicer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", + "integrity": "sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=", + "requires": { + "pend": "~1.2.0" + } + }, "figures": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", @@ -4523,11 +4577,25 @@ "unpipe": "~1.0.0" } }, + "find-cache-dir": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.1.tgz", + "integrity": "sha512-t2GDMt3oGC/v+BMwzmllWDuJF/xcDtE5j/fCGbqDD7OLuJkj0cfh1YSA5VKPvwMeLFLNDBkwOKZ2X85jGLVftQ==", + "requires": { + "commondir": "^1.0.1", + "make-dir": "^3.0.2", + "pkg-dir": "^4.1.0" + } + }, + "find-package-json": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/find-package-json/-/find-package-json-1.2.0.tgz", + "integrity": "sha512-+SOGcLGYDJHtyqHd87ysBhmaeQ95oWspDKnMXBrnQ9Eq4OkLNqejgoaD8xVWu6GPa0B6roa6KinCMEMcVeqONw==" + }, "find-up": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", - "dev": true, "requires": { "locate-path": "^5.0.0", "path-exists": "^4.0.0" @@ -4632,6 +4700,11 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" }, + "fs-constants": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", + "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" + }, "fs-readdir-recursive": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/fs-readdir-recursive/-/fs-readdir-recursive-1.1.0.tgz", @@ -4641,8 +4714,7 @@ "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "fsevents": { "version": "1.2.13", @@ -4702,6 +4774,11 @@ "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", "dev": true }, + "get-port": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/get-port/-/get-port-5.1.1.tgz", + "integrity": "sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ==" + }, "get-stdin": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", @@ -4736,7 +4813,6 @@ "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", - "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -4986,6 +5062,30 @@ "sshpk": "^1.7.0" } }, + "https-proxy-agent": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz", + "integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==", + "requires": { + "agent-base": "6", + "debug": "4" + }, + "dependencies": { + "debug": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", + "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", + "requires": { + "ms": "2.1.2" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + } + } + }, "human-signals": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-1.1.1.tgz", @@ -5075,6 +5175,11 @@ "safer-buffer": ">= 2.1.2 < 3" } }, + "ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==" + }, "ignore": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", @@ -5137,7 +5242,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" @@ -5481,8 +5585,7 @@ "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", - "dev": true + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" }, "isobject": { "version": "2.1.0", @@ -7619,11 +7722,18 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", - "dev": true, "requires": { "p-locate": "^4.1.0" } }, + "lockfile": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/lockfile/-/lockfile-1.0.4.tgz", + "integrity": "sha512-cvbTwETRfsFh4nHsL1eGWapU1XFi5Ot9E85sWAwia7Y7EgB7vfqcZhTKZ+l7hCGxSPoushMv5GKhT5PdLv03WA==", + "requires": { + "signal-exit": "^3.0.2" + } + }, "lodash": { "version": "4.17.20", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", @@ -7811,7 +7921,6 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, "requires": { "yallist": "^4.0.0" } @@ -7820,7 +7929,6 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", - "dev": true, "requires": { "semver": "^6.0.0" }, @@ -7828,8 +7936,7 @@ "semver": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", - "dev": true + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==" } } }, @@ -7864,6 +7971,11 @@ "dev": true, "optional": true }, + "md5-file": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/md5-file/-/md5-file-5.0.0.tgz", + "integrity": "sha512-xbEFXCYVWrSx/gEKS1VPlg84h/4L20znVIulKw6kMfmBUAZNAnF00eczz9ICMl+/hjQGo5KSXRxbL/47X3rmMw==" + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -7947,7 +8059,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -7979,6 +8090,11 @@ } } }, + "mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" + }, "mongodb": { "version": "3.6.3", "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.3.tgz", @@ -7992,6 +8108,75 @@ "saslprep": "^1.0.0" } }, + "mongodb-memory-server": { + "version": "6.9.2", + "resolved": "https://registry.npmjs.org/mongodb-memory-server/-/mongodb-memory-server-6.9.2.tgz", + "integrity": "sha512-+8axA5PlO+C3H+kgsxt6+6edcKAaY56YjYt+MWj9t1ZiKsEr+7SPsQfJcEoX+Kiz802jt1BOOIbYQVLX+08Hag==", + "requires": { + "mongodb-memory-server-core": "6.9.2" + } + }, + "mongodb-memory-server-core": { + "version": "6.9.2", + "resolved": "https://registry.npmjs.org/mongodb-memory-server-core/-/mongodb-memory-server-core-6.9.2.tgz", + "integrity": "sha512-0naMEESKsJNBg4/djN9qc+Argmg5UElJ/EFP9M4opTH//GZ1Rn6SI5S43NFHJrizOPGojAAp21gn7rNOru7Ypw==", + "requires": { + "@types/tmp": "^0.2.0", + "camelcase": "^6.0.0", + "cross-spawn": "^7.0.3", + "debug": "^4.2.0", + "find-cache-dir": "^3.3.1", + "find-package-json": "^1.2.0", + "get-port": "^5.1.1", + "https-proxy-agent": "^5.0.0", + "lockfile": "^1.0.4", + "md5-file": "^5.0.0", + "mkdirp": "^1.0.4", + "mongodb": "3.6.2", + "semver": "^7.3.2", + "tar-stream": "^2.1.4", + "tmp": "^0.2.1", + "uuid": "8.3.0", + "yauzl": "^2.10.0" + }, + "dependencies": { + "debug": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", + "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", + "requires": { + "ms": "2.1.2" + } + }, + "mongodb": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.6.2.tgz", + "integrity": "sha512-sSZOb04w3HcnrrXC82NEh/YGCmBuRgR+C1hZgmmv4L6dBz4BkRse6Y8/q/neXer9i95fKUBbFi4KgeceXmbsOA==", + "optional": true, + "requires": { + "bl": "^2.2.1", + "bson": "^1.1.4", + "denque": "^1.4.1", + "require_optional": "^1.0.1", + "safe-buffer": "^5.1.2", + "saslprep": "^1.0.0" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "semver": { + "version": "7.3.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz", + "integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==", + "requires": { + "lru-cache": "^6.0.0" + } + } + } + }, "mongoose": { "version": "5.11.2", "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.11.2.tgz", @@ -8548,7 +8733,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, "requires": { "wrappy": "1" } @@ -8638,7 +8822,6 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", - "dev": true, "requires": { "p-try": "^2.0.0" } @@ -8647,7 +8830,6 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", - "dev": true, "requires": { "p-limit": "^2.2.0" } @@ -8664,8 +8846,7 @@ "p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", - "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", - "dev": true + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" }, "package-json": { "version": "6.5.0", @@ -8738,20 +8919,17 @@ "path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", - "dev": true + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==" }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, "path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", - "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", - "dev": true + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==" }, "path-parse": { "version": "1.0.6", @@ -8773,6 +8951,11 @@ "pify": "^2.0.0" } }, + "pend": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", + "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=" + }, "performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", @@ -8804,7 +8987,6 @@ "version": "4.2.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", "integrity": "sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==", - "dev": true, "requires": { "find-up": "^4.0.0" } @@ -9766,7 +9948,6 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "dev": true, "requires": { "glob": "^7.1.3" } @@ -10236,7 +10417,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", - "dev": true, "requires": { "shebang-regex": "^3.0.0" } @@ -10244,8 +10424,7 @@ "shebang-regex": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", - "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", - "dev": true + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==" }, "shellwords": { "version": "0.1.1", @@ -10262,8 +10441,7 @@ "signal-exit": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz", - "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==", - "dev": true + "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==" }, "sisteransi": { "version": "1.0.5", @@ -10841,6 +11019,47 @@ "string-width": "^3.0.0" } }, + "tar-stream": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.1.4.tgz", + "integrity": "sha512-o3pS2zlG4gxr67GmFYBLlq+dM8gyRGUOvsrHclSkvtVtQbjV0s/+ZE8OpICbaj8clrX3tjeHngYGP7rweaBnuw==", + "requires": { + "bl": "^4.0.3", + "end-of-stream": "^1.4.1", + "fs-constants": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + }, + "dependencies": { + "bl": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.0.3.tgz", + "integrity": "sha512-fs4G6/Hu4/EE+F75J8DuN/0IpQqNjAdC7aEQv7Qt8MHGUH7Ckv2MwTEEeN9QehD0pfIDkMI1bkHYkKy7xHyKIg==", + "requires": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + }, + "dependencies": { + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + } + } + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, "term-size": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/term-size/-/term-size-2.2.1.tgz", @@ -10886,6 +11105,14 @@ "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, + "tmp": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", + "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==", + "requires": { + "rimraf": "^3.0.0" + } + }, "tmpl": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz", @@ -11271,9 +11498,7 @@ "uuid": { "version": "8.3.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.0.tgz", - "integrity": "sha512-fX6Z5o4m6XsXBdli9g7DtWgAx+osMsRRZFKma1mIUsLCz6vRvv+pz5VNbyu9UEDzpMWulZfvpgb/cmDXVulYFQ==", - "dev": true, - "optional": true + "integrity": "sha512-fX6Z5o4m6XsXBdli9g7DtWgAx+osMsRRZFKma1mIUsLCz6vRvv+pz5VNbyu9UEDzpMWulZfvpgb/cmDXVulYFQ==" }, "v8-compile-cache": { "version": "2.2.0", @@ -11398,7 +11623,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "dev": true, "requires": { "isexe": "^2.0.0" } @@ -11548,8 +11772,7 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "write": { "version": "1.0.3", @@ -11622,8 +11845,7 @@ "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "yaml": { "version": "1.10.0", @@ -11707,6 +11929,15 @@ "dev": true } } + }, + "yauzl": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", + "integrity": "sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=", + "requires": { + "buffer-crc32": "~0.2.3", + "fd-slicer": "~1.1.0" + } } } } diff --git a/src/controller/CommentController.js b/src/controller/CommentController.js index d08bb8c..16be82c 100644 --- a/src/controller/CommentController.js +++ b/src/controller/CommentController.js @@ -71,6 +71,7 @@ class CommentController { .send({ error: `Error while deleting topic.\n${err}` }); } } + static async likeComment(req, res) { try { const user = await User.findById(req.userId); @@ -104,6 +105,7 @@ class CommentController { return res.status(400).send({ error: `Error while commenting.${err}` }); } } + static async dislikeComment(req, res) { try { const comment = await Comment.findById(req.params.commentId); @@ -121,7 +123,7 @@ class CommentController { if (index > -1) { comment.likes.splice(index, 1); } - + comment.save(); await Like.findByIdAndRemove(like._id); const topicTrue = await Topic.findById(comment.topic).populate([ diff --git a/src/controller/FavoritesController.js b/src/controller/FavoritesController.js index 50b8960..8d810c2 100644 --- a/src/controller/FavoritesController.js +++ b/src/controller/FavoritesController.js @@ -12,18 +12,19 @@ class FavoritesController { const plant = await Plant.findById(req.params.plantId); if ( user.favorites.some( - (favorite) => JSON.stringify(favorite?._id) === JSON.stringify(plant._id) + (favorite) => + JSON.stringify(favorite?._id) === JSON.stringify(plant._id) ) ) return res.status(200).send(user); - + if (user.favorites.indexOf(plant) === -1) { user.favorites.push(plant); await user.save(); } else { throw new Error("invalid plant/user or it's already been added"); } - + return res.status(200).send(user); } catch (err) { return res.status(400).send(err); @@ -34,7 +35,7 @@ class FavoritesController { try { const user = await User.findById(req.params.userId); const { favorites } = user; - + return res.status(200).send({ favorites }); } catch (err) { return res.status(400).send({ error: `Error loading favorites. ${err}` }); @@ -45,7 +46,7 @@ class FavoritesController { try { const user = await User.findById(req.userId); const index = user.favorites.indexOf(req.params.plantId); - + if (index > -1) { user.favorites.splice(index, 1); await user.save(); @@ -61,7 +62,9 @@ class FavoritesController { ]); return res.status(200).send(newUser); } catch (err) { - return res.status(400).send({ error: `Error deleting favorite. ${err} ` }); + return res + .status(400) + .send({ error: `Error deleting favorite. ${err} ` }); } } } diff --git a/src/controller/MyPlantsController.js b/src/controller/MyPlantsController.js index 0949c20..49ed1a2 100644 --- a/src/controller/MyPlantsController.js +++ b/src/controller/MyPlantsController.js @@ -39,7 +39,7 @@ class MyPlantsController { try { const user = await User.findById(req.userId); const plant = await Plant.findById(req.params.plantId); - + const result = myPlantSchema.validate({ nickname: req.body.nickname }); if (result.error) { return res.status(400).send(result.error); @@ -52,7 +52,7 @@ class MyPlantsController { }); await user.myPlants.push(myPlant._id); await user.save(); - + return res.status(200).send({ myPlant }); } catch (err) { return res @@ -65,7 +65,7 @@ class MyPlantsController { try { const user = await User.findById(req.params.userId); const index = user.myPlants.indexOf(req.params.myPlantId); - + if (index > -1) { const myPlant = await MyPlant.findById(req.params.myPlantId); return res.send({ @@ -87,14 +87,14 @@ class MyPlantsController { static async updatePlant(req, res) { try { const newNick = req.body; - + const result = myPlantSchema.validate(newNick); if (result.error) { return res .status(400) .send({ error: `Error while editing plant. ${result.error}` }); } - + const myPlant = await MyPlant.findOneAndUpdate( { _id: req.params.myPlantId }, newNick, @@ -103,7 +103,7 @@ class MyPlantsController { new: true, } ); - + const newUser = await User.findById(myPlant.user).populate([ { path: 'topics', populate: 'plants' }, { path: 'myPlants', populate: 'plant' }, @@ -134,7 +134,7 @@ class MyPlantsController { { path: 'myPlants', populate: 'plant' }, { path: 'favorites', populate: 'plant' }, ]); - + return res.send(newUser); } catch (err) { return res diff --git a/src/controller/PlantController.js b/src/controller/PlantController.js index 7b9131a..57c1bc2 100644 --- a/src/controller/PlantController.js +++ b/src/controller/PlantController.js @@ -52,10 +52,10 @@ class PlantController { // Listagem de Todas as plantas static async fetchAll(req, res) { try { - const plants = await Plant.find().sort({ "topics": -1 }).populate([ - { path: 'topics' }, - ]); - return res.send( plants ); + const plants = await Plant.find() + .sort({ topics: -1 }) + .populate([{ path: 'topics' }]); + return res.send(plants); } catch (err) { return res.status(400).send({ error: 'Loading plants failed' }); } diff --git a/src/controller/TopicController.js b/src/controller/TopicController.js index df60013..c3e5170 100644 --- a/src/controller/TopicController.js +++ b/src/controller/TopicController.js @@ -9,29 +9,29 @@ class TopicController { try { const user = await User.findById(req.userId); const plant = await Plant.findById(req.params.plantId); - + const result = topicSchema.validate(req.body); - + if (result.error) { return res .status(400) .send({ error: `Error while creating topic. ${result.error}` }); } - + const topic = await Topic.create({ ...req.body, user: req.userId, plant: req.params.plantId, }); - + await topic.save(); - + user.topics.push(topic); await user.save(); - + plant.topics.push(topic); await plant.save(); - + return res.send({ topic }); } catch (err) { return res @@ -43,7 +43,7 @@ class TopicController { static async updateTopic(req, res) { try { const topic = await Topic.findById(req.params.topicId); - + const newData = req.body; if (!('title' in newData)) { @@ -60,7 +60,7 @@ class TopicController { .status(400) .send({ error: `Error while creating topic. ${result.error}` }); } - + const topicNew = await Topic.findOneAndUpdate( { _id: req.params.topicId }, newData, @@ -86,20 +86,20 @@ class TopicController { const topic = await Topic.findById(req.params.topicId); const user = await User.findById(topic.user); const plant = await Plant.findById(topic.plant); - + const indexAtUser = user.topics.indexOf(req.params.topicId); const indexAtPlant = plant.topics.indexOf(req.params.topicId); - + if (indexAtUser > -1) { user.topics.splice(indexAtUser, 1); } if (indexAtPlant > -1) { plant.topics.splice(indexAtPlant, 1); } - + user.save(); plant.save(); - + await Topic.findByIdAndRemove(req.params.topicId, { useFindAndModify: false, }); @@ -133,7 +133,7 @@ class TopicController { { path: 'user' }, { path: 'plant' }, ]); - + return res.send(topic); } catch (err) { return res @@ -141,7 +141,7 @@ class TopicController { .send({ error: `Error while find topic id.\n${err}` }); } } - + static async likeTopic(req, res) { try { const user = await User.findById(req.userId); @@ -170,12 +170,13 @@ class TopicController { return res.send(topictrue); } console.log(topic.likes.length); - + return res.send(topic); } catch (err) { return res.status(400).send({ error: `Error while commenting.${err}` }); } } + static async dislikeTopic(req, res) { try { const topic = await Topic.findById(req.params.topicId).populate([ @@ -205,7 +206,6 @@ class TopicController { } } - static async refreshTopicContents(res, topicId) { const topicTrue = await Topic.findById(topicId).populate( defaultTopicPopulate diff --git a/src/models/Plant.js b/src/models/Plant.js index 6daade4..ba6cca7 100644 --- a/src/models/Plant.js +++ b/src/models/Plant.js @@ -1,5 +1,4 @@ const mongoose = require('mongoose'); -const User = require('./User'); const PlantSchema = new mongoose.Schema({ scientificName: { diff --git a/src/models/User.js b/src/models/User.js index bd1246a..31f7bf4 100644 --- a/src/models/User.js +++ b/src/models/User.js @@ -12,7 +12,7 @@ const userSchema = new Schema({ type: String, required: true, }, - photo:{ + photo: { type: String, }, email: { diff --git a/src/routes/authRoutes.js b/src/routes/authRoutes.js index 6483e03..6a1029e 100644 --- a/src/routes/authRoutes.js +++ b/src/routes/authRoutes.js @@ -8,7 +8,7 @@ router.post('/login', AuthController.login); router.post('/signup', AuthController.signUp); router.get('/user/:id', AuthController.userId); router.put('/update/:id', auth, AuthController.updateId); -router.delete('/delete', auth, AuthController.deleteId); +router.delete('/delete/:id', auth, AuthController.deleteId); router.get('/user', auth, AuthController.loggedUser); module.exports = router; diff --git a/src/routes/commentRoutes.js b/src/routes/commentRoutes.js index 351428d..643786b 100644 --- a/src/routes/commentRoutes.js +++ b/src/routes/commentRoutes.js @@ -1,7 +1,6 @@ const express = require('express'); const { auth } = require('../lib/auth'); const CommentController = require('../controller/CommentController'); -const LikeController = require('../controller/LikeController'); const router = new express.Router(); diff --git a/src/routes/topicRoutes.js b/src/routes/topicRoutes.js index eba0e87..19fa96f 100644 --- a/src/routes/topicRoutes.js +++ b/src/routes/topicRoutes.js @@ -2,7 +2,6 @@ const express = require('express'); const { auth } = require('../lib/auth'); const TopicController = require('../controller/TopicController'); - const router = new express.Router(); router.post('/create/:plantId', auth, TopicController.createTopic); router.put('/update/:topicId', TopicController.updateTopic);