38884-vm/backend/src/db/models/challenge_participations.js
2026-02-28 19:55:21 +00:00

147 lines
1.8 KiB
JavaScript

const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');
module.exports = function(sequelize, DataTypes) {
const challenge_participations = sequelize.define(
'challenge_participations',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
progress_value: {
type: DataTypes.INTEGER,
},
target_value: {
type: DataTypes.INTEGER,
},
is_completed: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
completed_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
challenge_participations.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.challenge_participations.belongsTo(db.weekly_challenges, {
as: 'challenge',
foreignKey: {
name: 'challengeId',
},
constraints: false,
});
db.challenge_participations.belongsTo(db.users, {
as: 'user',
foreignKey: {
name: 'userId',
},
constraints: false,
});
db.challenge_participations.belongsTo(db.users, {
as: 'createdBy',
});
db.challenge_participations.belongsTo(db.users, {
as: 'updatedBy',
});
};
return challenge_participations;
};