Removed activities table; this will be handled after users are implemented
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Gregory Ballantine 2024-05-21 09:35:39 -04:00
parent 8119f49b4d
commit 82c2b91090
5 changed files with 0 additions and 89 deletions

View File

@ -1,30 +0,0 @@
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('activities', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
user: {
type: Sequelize.STRING,
allowNull: false,
},
action: {
type: Sequelize.STRING,
allowNull: false,
},
itemId: {
type: Sequelize.NUMBER,
allowNull: false,
},
createdAt: Sequelize.DataTypes.DATE,
updatedAt: Sequelize.DataTypes.DATE,
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('activities');
}
};

View File

@ -1,26 +0,0 @@
module.exports = (sequelize, Sequelize) => {
const Activity = sequelize.define('activity', {
user: {
type: Sequelize.STRING,
allowNull: false,
},
action: {
type: Sequelize.STRING,
allowNull: false,
},
itemId: {
type: Sequelize.NUMBER,
allowNull: false,
},
});
Activity.render = function() {
return this.user + ' has ' + this.action + ' this item at ' + this.createdAt + '.';
};
return Activity;
};

View File

@ -10,14 +10,6 @@ db.sequelize = sequelize;
db.items = require('./item.js')(sequelize, Sequelize);
db.licenses = require('./license.js')(sequelize, Sequelize);
db.activities = require('./activity.js')(sequelize, Sequelize);
// Model associations
db.items.hasMany(db.activities, {
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
});
db.activities.belongsTo(db.items);
module.exports = db;

View File

@ -1,6 +1,5 @@
const db = require('../models');
const Item = db.items;
const Activity = db.activities;
// GET - /item/add
exports.getAdd = async function(req, res) {
@ -21,12 +20,6 @@ exports.postAdd = async function(req, res) {
console.log(`Saved item ${item.name} to the database.`);
const activity = await Activity.create({
user: 'Admin',
action: 'create',
itemId: item.id,
});
res.redirect('/');
};
@ -36,11 +29,8 @@ exports.getItem = async function(req, res) {
where: {
id: req.params.id,
},
include: Activity,
});
console.log(item[0].activities[0].render());
res.render('item/view.twig', {
item: item[0],
});

View File

@ -44,19 +44,4 @@
</table>
</section>
<hr>
<section id="item-activity" class="row">
<h2>Recorded activity</h2>
{% if item.activities | length > 0 %}
<ul class="twelve columns">
{% for a in item.activities %}
<li><p>{{ a.render() }}</p></li>
{% endfor %}
</ul>
{% else %}
<p>There hasn't been any activity recorded for this item.</p>
{% endif %}
</section>
{% endblock %}