This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/server/models/Attachment.js
Tom Moor 8e5a5a57a9
feat: Store image uploads as attachments in database (#1144)
* First pass

* Documentation

* Added optional documentId relationship

* name -> key

* cleanup: No need for separate documentId prop
2020-01-16 09:42:42 -08:00

54 lines
1.0 KiB
JavaScript

// @flow
import path from 'path';
import { DataTypes, sequelize } from '../sequelize';
const Attachment = sequelize.define(
'attachment',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
key: {
type: DataTypes.STRING,
allowNull: false,
},
url: {
type: DataTypes.STRING,
allowNull: false,
},
contentType: {
type: DataTypes.STRING,
allowNull: false,
},
size: {
type: DataTypes.BIGINT,
allowNull: false,
},
acl: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 'public-read',
validate: {
isIn: [['private', 'public-read']],
},
},
},
{
getterMethods: {
name: function() {
return path.parse(this.key).base;
},
},
}
);
Attachment.associate = models => {
Attachment.belongsTo(models.Team);
Attachment.belongsTo(models.Document);
Attachment.belongsTo(models.User);
};
export default Attachment;