-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
566848d
commit 6374c90
Showing
8 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import File from '../models/File'; | ||
|
||
class FileController { | ||
async store(req, res) { | ||
const { originalname: name, filename: path } = req.file; | ||
|
||
const file = await File.create({ | ||
name, | ||
path, | ||
}); | ||
|
||
return res.json(file); | ||
} | ||
} | ||
|
||
export default new FileController(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Sequelize, { Model } from 'sequelize'; | ||
|
||
class File extends Model { | ||
static init(sequelize) { | ||
super.init( | ||
{ | ||
name: Sequelize.STRING, | ||
path: Sequelize.STRING, | ||
}, | ||
{ | ||
sequelize, | ||
} | ||
); | ||
|
||
return this; | ||
} | ||
} | ||
|
||
export default File; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('files', { | ||
id: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
}, | ||
name: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
path: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
unique: true, | ||
}, | ||
created_at: { | ||
type: Sequelize.DATE, | ||
allowNull: false, | ||
}, | ||
updated_at: { | ||
type: Sequelize.DATE, | ||
allowNull: false, | ||
}, | ||
}); | ||
}, | ||
|
||
down: queryInterface => { | ||
return queryInterface.dropTable('users'); | ||
}, | ||
}; |
15 changes: 15 additions & 0 deletions
15
src/database/migrations/20190724151158-add-avatar-field-to-users.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.addColumn('users', 'avatar_id', { | ||
type: Sequelize.INTEGER, | ||
references: { model: 'files', key: 'id' }, | ||
onUpdate: 'CASCADE', | ||
onDelete: 'SET NULL', | ||
allowNull: true, | ||
}); | ||
}, | ||
|
||
down: queryInterface => { | ||
return queryInterface.removeColumn('users', 'avatar_id'); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.