|
@@ -12,8 +12,6 @@ const s3 = require('../helpers/aws');
|
|
|
const client = require('../helpers/twilio');
|
|
|
const phoneToken = require('generate-sms-verification-code');
|
|
|
const SECRET_KEY = process.env.JWT_SECRET;
|
|
|
-const DIR_STATIC = process.env.DIR_STATIC;
|
|
|
-const DIR_UPLOAD = process.env.DIR_UPLOAD;
|
|
|
const AWS_BUCKET_NAME = process.env.AWS_BUCKET_NAME;
|
|
|
|
|
|
const createNewUser = async (req, res, next) => {
|
|
@@ -57,7 +55,7 @@ const logIn = async (req, res, next) => {
|
|
|
const payload = { id };
|
|
|
const token = jwt.sign(payload, SECRET_KEY, { expiresIn: '24h' });
|
|
|
let registered = true;
|
|
|
- if (!user.name || !user.lastName || !user.avatarUrl) registered = false;
|
|
|
+ if (!user.originalName || !user.originalLastName) registered = false;
|
|
|
const online = true;
|
|
|
await UserModel.updateUser(id, { token, code: '', online });
|
|
|
await ChatModel.updateCompanionsChat(id, { online });
|
|
@@ -148,7 +146,7 @@ const getCurrent = async (req, res, next) => {
|
|
|
|
|
|
const updateCredentials = async (req, res, next) => {
|
|
|
try {
|
|
|
- const { id } = req.user;
|
|
|
+ const { id, token } = req.user;
|
|
|
const { name, lastName, originalName, originalLastName } = req.body;
|
|
|
await UserModel.updateUser(id, req.body);
|
|
|
await ChatModel.updateCompanionsChat(id, {
|
|
@@ -160,7 +158,9 @@ const updateCredentials = async (req, res, next) => {
|
|
|
{ name, lastName }
|
|
|
);
|
|
|
return res.status(200).json({
|
|
|
- data: {},
|
|
|
+ data: {
|
|
|
+ token,
|
|
|
+ },
|
|
|
});
|
|
|
} catch (e) {
|
|
|
next(e);
|
|
@@ -218,12 +218,11 @@ const removeAvatar = async (req, res, next) => {
|
|
|
|
|
|
const updateAvatar = async (req, res, next) => {
|
|
|
try {
|
|
|
- const token = req.user.token;
|
|
|
const userId = req.user.id;
|
|
|
const userNumber = req.user.number;
|
|
|
const pathToFile = req.file.path;
|
|
|
const originalName = req.file.originalname;
|
|
|
- const newFileName = `${Math.round(
|
|
|
+ const avatarUrl = `${Math.round(
|
|
|
Date.now() / 1000
|
|
|
)}${userId}${originalName}`;
|
|
|
const cropImg = await Jimp.read(pathToFile);
|
|
@@ -238,13 +237,12 @@ const updateAvatar = async (req, res, next) => {
|
|
|
const fileContent = await fs.readFile(pathToFile);
|
|
|
const params = {
|
|
|
Bucket: AWS_BUCKET_NAME,
|
|
|
- Key: `${newFileName}`,
|
|
|
+ Key: `${avatarUrl}`,
|
|
|
Body: fileContent,
|
|
|
};
|
|
|
- s3.upload(params, async (err, data) => {
|
|
|
+ s3.upload(params, async (err, _data) => {
|
|
|
if (err) throw err;
|
|
|
fs.unlink(pathToFile);
|
|
|
- const avatarUrl = data.Location;
|
|
|
const avatarsArr = [
|
|
|
{ avatarUrl, updatedAt: new Date() },
|
|
|
...req.user.avatarsArr,
|
|
@@ -259,9 +257,7 @@ const updateAvatar = async (req, res, next) => {
|
|
|
return res.status(200).json({
|
|
|
status: 'success',
|
|
|
code: 200,
|
|
|
- data: {
|
|
|
- token,
|
|
|
- },
|
|
|
+ data: {},
|
|
|
});
|
|
|
});
|
|
|
} catch (e) {
|