Skip to content

Commit

Permalink
Developed the API for uploading user profile image (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjchirag7 authored Oct 16, 2020
1 parent 9f7c544 commit 0670154
Show file tree
Hide file tree
Showing 11 changed files with 965 additions and 5 deletions.
15 changes: 15 additions & 0 deletions server/config/cloudinary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const cloudinary = require('cloudinary').v2
const dotenv = require('dotenv')

const config = dotenv.config()
if (!config) {
console.log(config.error)
}

cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
})

module.exports = cloudinary
3 changes: 2 additions & 1 deletion server/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ CREATE TABLE `user` (
`verified` tinyint DEFAULT NULL,
`department` int NOT NULL,
`branch` int NOT NULL,
`bio` varchar(45) DEFAULT NULL,
`bio` varchar(110) DEFAULT NULL,
`profile_img` varchar(110) DEFAULT NULL,
PRIMARY KEY (`username`),
UNIQUE KEY `username_UNIQUE` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Expand Down
5 changes: 4 additions & 1 deletion server/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ MAIL_PORT = 587
OAUTH_CLIENT_ID = <oauth-client-id>
OAUTH_CLIENT_SECRET = <oauth-client-secret>
FRONTEND_HOST=localhost
FRONTEND_PORT=3000
FRONTEND_PORT=3000
CLOUDINARY_CLOUD_NAME=<cloudinary-cloud-name>
CLOUDINARY_API_KEY=<cloudinary-api-key>
CLOUDINARY_API_SECRET=<cloudinary-api-secret>
2 changes: 2 additions & 0 deletions server/models/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const updatePassword = require('./updatePassword')
const updateUser = require('./updateUser')
const verifyNewEmail = require('./verifyNewEmail')
const getUser = require('./getUser')
const uploadProfileImage = require('./uploadProfileImage')

module.exports = {
signup,
Expand All @@ -18,4 +19,5 @@ module.exports = {
updateUser,
verifyNewEmail,
getUser,
uploadProfileImage,
}
23 changes: 23 additions & 0 deletions server/models/auth/uploadProfileImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { pool } = require('../database')

function uploadProfileImage(req) {
return new Promise((resolve, reject) => {
if (!req.file) {
return reject('File not uploaded')
} else {
const results = { profileImg: req.file.path }
pool.query(
'UPDATE user SET profile_img=? WHERE username=?',
[results.profileImg, req.username],
(error) => {
if (error) {
return reject(error)
}
return resolve(results)
}
)
}
})
}

module.exports = uploadProfileImage
Loading

0 comments on commit 0670154

Please sign in to comment.