Adding id to events
This commit is contained in:
parent
7df7f1053b
commit
908125d847
@ -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
976
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 });
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user