Adding id to events

This commit is contained in:
Selim Mustafaev 2020-09-10 10:50:16 +03:00
parent 7df7f1053b
commit 908125d847
4 changed files with 629 additions and 363 deletions

View File

@ -1,12 +1,12 @@
const crypto = require('crypto'); const crypto = require('crypto');
const uuid = require('uuid/v4'); const { v4: uuidv4 } = require('uuid');
const hash = Symbol(); const hash = Symbol();
const sha256 = text => crypto.createHash('sha256').update(text).digest('base64'); const sha256 = text => crypto.createHash('sha256').update(text).digest('base64');
class User { class User {
constructor(email = '', password = '') { constructor(email = '', password = '') {
this._id = uuid(); this._id = uuidv4();
this.email = email; this.email = email;
this[hash] = sha256(password); this[hash] = sha256(password);
} }

976
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -15,13 +15,13 @@
"express": "^4.17.1", "express": "^4.17.1",
"express-bearer-token": "^2.4.0", "express-bearer-token": "^2.4.0",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"mongodb": "^3.5.7", "mongodb": "^3.6.1",
"node-fetch": "^2.6.0", "node-fetch": "^2.6.1",
"pubnub": "^4.27.6", "pubnub": "^4.29.6",
"uuid": "^3.4.0" "uuid": "^8.3.0"
}, },
"devDependencies": { "devDependencies": {
"babel-eslint": "^10.1.0", "babel-eslint": "^10.1.0",
"eslint": "^6.8.0" "eslint": "^7.8.1"
} }
} }

View File

@ -1,5 +1,6 @@
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const { v4: uuidv4 } = require('uuid');
const makeError = error => ({ success: false, error }); const makeError = error => ({ success: false, error });
@ -7,6 +8,7 @@ router.post('/', async (req, res) => {
const { number, event } = req.body; const { number, event } = req.body;
try { try {
event.id = uuidv4();
let collection = req.db.collection('vehicles'); let collection = req.db.collection('vehicles');
await collection.updateOne({ number }, { $push: { events: event } }); await collection.updateOne({ number }, { $push: { events: event } });
let vehicle = await collection.findOne({ number }); let vehicle = await collection.findOne({ number });