38365-vm/backend/src/db/models/daily_achievements.js
2026-02-11 21:54:19 +00:00

144 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 daily_achievements = sequelize.define(
'daily_achievements',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
achievement_date: {
type: DataTypes.DATE,
},
actions_count: {
type: DataTypes.INTEGER,
},
shift: {
type: DataTypes.ENUM,
values: [
"morning",
"evening"
],
},
has_support: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
support_shift: {
type: DataTypes.ENUM,
values: [
"morning_support",
"evening_support"
],
},
support_actions_count: {
type: DataTypes.INTEGER,
},
notes: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
daily_achievements.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.daily_achievements.belongsTo(db.users, {
as: 'user',
foreignKey: {
name: 'userId',
},
constraints: false,
});
db.daily_achievements.belongsTo(db.users, {
as: 'createdBy',
});
db.daily_achievements.belongsTo(db.users, {
as: 'updatedBy',
});
};
return daily_achievements;
};