2019-01-05 21:37:33 +00:00
|
|
|
// @flow
|
2020-06-20 20:59:15 +00:00
|
|
|
import { DataTypes, sequelize } from "../sequelize";
|
2019-01-05 21:37:33 +00:00
|
|
|
|
|
|
|
const CollectionUser = sequelize.define(
|
2020-06-20 20:59:15 +00:00
|
|
|
"collection_user",
|
2019-01-05 21:37:33 +00:00
|
|
|
{
|
|
|
|
permission: {
|
|
|
|
type: DataTypes.STRING,
|
2020-06-20 20:59:15 +00:00
|
|
|
defaultValue: "read_write",
|
2019-01-05 21:37:33 +00:00
|
|
|
validate: {
|
2020-06-20 20:59:15 +00:00
|
|
|
isIn: [["read", "read_write", "maintainer"]],
|
2019-01-05 21:37:33 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timestamps: true,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-08-09 01:53:11 +00:00
|
|
|
CollectionUser.associate = (models) => {
|
2019-01-05 21:37:33 +00:00
|
|
|
CollectionUser.belongsTo(models.Collection, {
|
2020-06-20 20:59:15 +00:00
|
|
|
as: "collection",
|
|
|
|
foreignKey: "collectionId",
|
2019-01-05 21:37:33 +00:00
|
|
|
});
|
|
|
|
CollectionUser.belongsTo(models.User, {
|
2020-06-20 20:59:15 +00:00
|
|
|
as: "user",
|
|
|
|
foreignKey: "userId",
|
2019-01-05 21:37:33 +00:00
|
|
|
});
|
|
|
|
CollectionUser.belongsTo(models.User, {
|
2020-06-20 20:59:15 +00:00
|
|
|
as: "createdBy",
|
|
|
|
foreignKey: "createdById",
|
2019-01-05 21:37:33 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CollectionUser;
|