-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from andela/ft-create-article-model-#163359366
Ft create article model #163359366
- Loading branch information
Showing
6 changed files
with
272 additions
and
73 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
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,61 @@ | ||
/* eslint-disable no-unused-vars */ | ||
|
||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('Articles', { | ||
id: { | ||
allowNull: false, | ||
primaryKey: true, | ||
type: Sequelize.UUID, | ||
defaultValue: Sequelize.UUIDV4 | ||
}, | ||
title: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
description: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
content: { | ||
type: Sequelize.TEXT, | ||
allowNull: false, | ||
}, | ||
featuredImageUrl: { | ||
type: Sequelize.STRING | ||
}, | ||
averageRating: { | ||
type: Sequelize.FLOAT, | ||
defaultValue: 0 | ||
}, | ||
readTime: { | ||
type: Sequelize.INTEGER, | ||
}, | ||
slug: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
authorId: { | ||
type: Sequelize.UUID, | ||
onDelete: 'CASCADE', | ||
foreignKey: true, | ||
references: { | ||
model: 'Users', | ||
key: 'id' | ||
} | ||
}, | ||
ispublished: { | ||
type: Sequelize.BOOLEAN, | ||
defaultValue: false, | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
down: (queryInterface, Sequelize) => queryInterface.dropTable('Articles') | ||
}; |
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,74 @@ | ||
module.exports = (sequelize, DataTypes) => { | ||
const Articles = sequelize.define( | ||
'Articles', | ||
{ | ||
id: { | ||
type: DataTypes.UUID, | ||
primaryKey: true, | ||
defaultValue: DataTypes.UUIDV4 | ||
}, | ||
title: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
validate: { | ||
len: { | ||
args: [5, 400], | ||
msg: 'Title must be between 5 and 400 characters' | ||
} | ||
} | ||
}, | ||
description: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
validate: { | ||
len: { | ||
args: [5, 200], | ||
msg: 'Title must be between 5 and 200 characters' | ||
} | ||
} | ||
}, | ||
content: { | ||
type: DataTypes.TEXT, | ||
allowNull: false, | ||
validate: { | ||
min: 250, | ||
} | ||
}, | ||
featuredImageUrl: { | ||
type: DataTypes.STRING, | ||
validate: { | ||
is: ['(http(s?):)([/|.|[A-Za-z0-9_-]| |-])*.(?:jpg|gif|png)', 'i'] | ||
} | ||
}, | ||
averageRating: { | ||
type: DataTypes.FLOAT, | ||
validate: {} | ||
}, | ||
slug: { | ||
type: DataTypes.STRING, | ||
validate: {} | ||
}, | ||
readTime: { | ||
type: DataTypes.INTEGER, | ||
defaultValue: 0, | ||
}, | ||
ispublished: { | ||
type: DataTypes.BOOLEAN, | ||
defaultValue: false, | ||
validate: { | ||
isBoolean: { | ||
args: [true, false] | ||
} | ||
} | ||
} | ||
}, | ||
{} | ||
); | ||
Articles.associate = (models) => { | ||
Articles.belongsTo(models.User, { | ||
foreignKey: 'id', | ||
as: 'authorId', | ||
}); | ||
}; | ||
return Articles; | ||
}; |
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
Oops, something went wrong.