-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.js
51 lines (45 loc) · 1.39 KB
/
controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const User = require('./utils/user');
const logger = require('./utils/logger');
const essThree = require('./utils/s3');
const { detectFace } = require('./utils/face');
// const userSchema = require('./user');
// const mongoose = require('mongoose');
// // const User = userSchema.model;
// const User = mongoose.model('User', userSchema);
module.exports = {
getUser: (id) => {
return { id: id };
},
loginUser: () => {
return true;
},
registerUser: ({ image, userName, password }) => {
logger.info('registering user');
logger.info('userName:' + userName);
logger.info('password:' + password);
// create user in Mongo
User({
username: userName,
password: password,
faceId: ''
}).save().then(() => {
// const userId = user._id;
let fileName = image.originalname;
const upload = Buffer.from(image.buffer);
essThree.putObject(fileName, upload).then(() => {
detectFace(`https://s3.amazonaws.com/boaty-faces/${fileName}`).then((response) => {
const faceId = response.data[0].faceId;
User.findOne({ username: userName }).exec().then((res) => {
res.faceId = faceId;
return res.save();
});
});
}).catch((err) => {
logger.error(err);
});
});
// with returned user, get ID and send image to S3
// update Mongo with faceID
return true;
}
};