Skip to content

Commit

Permalink
when user upload file, also update the database
Browse files Browse the repository at this point in the history
  • Loading branch information
blueBlue0102 committed May 12, 2021
1 parent 38ad7e1 commit 2e1ee9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions routers/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ module.exports = async function (req, res) {
else {
const user = await sequelize.models.User.findByPk(req.user.id);
if (user === null) {
// create account
sequelize.models.User.create({
google_id: req.user.id,
display_name: req.user.displayName,
last_login_date: Date.now(),
});
} else {
// update account
sequelize.models.User.update(
{ last_login_date: Date.now() },
{
Expand Down
7 changes: 7 additions & 0 deletions routers/upload.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const formidable = require("formidable");
const path = require("path");
const winston = require("winston");
const sequelize = require("../models/index");

const FORMIDABLE_CONFIG = {
uploadDir: path.join(
Expand Down Expand Up @@ -63,6 +64,12 @@ module.exports = async (req, res, next) => {
ip: req.ip,
});

sequelize.models.File.create({
google_id: req.user.id,
file_name: files.file.newFilename,
expiration_date: null,
});

res.status(200).json({
imageName: files.file.newFilename,
imagePath: path.join(
Expand Down

0 comments on commit 2e1ee9f

Please sign in to comment.