39202-vm/backend/src/db/models/troubleshooting_tickets.js
2026-03-15 14:56:11 +00:00

228 lines
2.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 troubleshooting_tickets = sequelize.define(
'troubleshooting_tickets',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
title: {
type: DataTypes.TEXT,
},
problem_description: {
type: DataTypes.TEXT,
},
category: {
type: DataTypes.ENUM,
values: [
"installation",
"boot",
"performance",
"network",
"google_login",
"google_talk",
"apps",
"storage",
"graphics",
"audio",
"other"
],
},
severity: {
type: DataTypes.ENUM,
values: [
"low",
"medium",
"high",
"critical"
],
},
status: {
type: DataTypes.ENUM,
values: [
"open",
"in_progress",
"resolved",
"closed"
],
},
environment_details: {
type: DataTypes.TEXT,
},
opened_at: {
type: DataTypes.DATE,
},
resolved_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
troubleshooting_tickets.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.troubleshooting_tickets.belongsTo(db.users, {
as: 'reporter',
foreignKey: {
name: 'reporterId',
},
constraints: false,
});
db.troubleshooting_tickets.belongsTo(db.emulator_profiles, {
as: 'emulator_profile',
foreignKey: {
name: 'emulator_profileId',
},
constraints: false,
});
db.troubleshooting_tickets.hasMany(db.file, {
as: 'log_files',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.troubleshooting_tickets.getTableName(),
belongsToColumn: 'log_files',
},
});
db.troubleshooting_tickets.hasMany(db.file, {
as: 'evidence_images',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.troubleshooting_tickets.getTableName(),
belongsToColumn: 'evidence_images',
},
});
db.troubleshooting_tickets.belongsTo(db.users, {
as: 'createdBy',
});
db.troubleshooting_tickets.belongsTo(db.users, {
as: 'updatedBy',
});
};
return troubleshooting_tickets;
};