Files
starr-philproperties/models/assets/assets.mdl.js
T
kennethobsequio 439bb33f77 ready to test
Testing

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
2026-06-22 10:06:58 +08:00

78 lines
5.1 KiB
JavaScript

// models/Asset.js
const { DataTypes } = require("sequelize");
const sequelize = require("../../config/db.config");
const mdl_Users = require("../users/users.mdl")
const Asset = sequelize.define("Asset", {
// ─── Identity ─────────────────────────────────────────────────────────────
asset_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true, label: "Asset ID", order: 0, hidden: true },
uuid: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, allowNull: false, unique: true, label: "UUID", order: 0, hidden: true },
// ─── File info ────────────────────────────────────────────────────────────
original_name: { type: DataTypes.STRING(255), allowNull: false, label: "Original Name", order: 0, hidden: true },
display_name: { type: DataTypes.STRING(255), allowNull: false, label: "Name", order: 0 },
file_url: { type: DataTypes.STRING(512), allowNull: false, label: "File URL", order: 0, hidden: true },
file_size: { type: DataTypes.BIGINT, allowNull: false, label: "File Size", order: 0, hidden: true },
mime_type: { type: DataTypes.STRING(100), allowNull: false, label: "MIME Type", order: 0, hidden: true },
extension: { type: DataTypes.STRING(20), label: "File Type", order: 0 },
checksum: { type: DataTypes.STRING(64), label: "Checksum", order: 0, hidden: true },
// ─── Classification ───────────────────────────────────────────────────────
file_type: {
type: DataTypes.ENUM("avatar", "document", "video", "image"),
allowNull: false,
defaultValue: "image", label: "Classification", order: 0
},
// ─── Image & video dimensions ─────────────────────────────────────────────
width: { type: DataTypes.INTEGER, label: "", order: 0, hidden: true },
height: { type: DataTypes.INTEGER, label: "", order: 0, hidden: true },
// ─── Video-specific ───────────────────────────────────────────────────────
duration: { type: DataTypes.FLOAT, label: "", order: 0, hidden: true }, // seconds
resolution: { type: DataTypes.STRING(20), label: "", order: 0, hidden: true }, // "1080p", "720p", "4K"
frame_rate: { type: DataTypes.FLOAT, label: "", order: 0, hidden: true }, // fps
bitrate: { type: DataTypes.BIGINT, label: "", order: 0, hidden: true }, // bps
video_codec: { type: DataTypes.STRING(50), label: "", order: 0, hidden: true }, // "H.264", "H.265"
audio_codec: { type: DataTypes.STRING(50), label: "", order: 0, hidden: true }, // "AAC", "MP3"
thumbnail_url: { type: DataTypes.STRING(512), label: "", order: 0, hidden: true },
thumbnail_storage_key: { type: DataTypes.STRING(512), label: "", order: 0, hidden: true },
// ─── Description ──────────────────────────────────────────────────────────
description: { type: DataTypes.TEXT, label: "Description", hidden: true },
// ─── Storage ──────────────────────────────────────────────────────────────
storage_provider: {
type: DataTypes.ENUM("local", "s3", "gcs", "cloudinary", "chibisafe", "other"),
defaultValue: "local", label: "Storage Provider", order: 0
},
storage_bucket: { type: DataTypes.STRING(255), label: "", order: 0, hidden: true },
storage_key: { type: DataTypes.STRING(512), label: "", order: 0, hidden: true },
// ─── Access control ───────────────────────────────────────────────────────
is_public: {
type: DataTypes.BOOLEAN,
defaultValue: false, label: "Access Type", order: 0
},
// ── Audit trails ────────────────────────────────────────────────────────────
createdBy: { type: DataTypes.BIGINT, allowNull: true, label: "Created By" },
updatedBy: { type: DataTypes.BIGINT, allowNull: true, label: "Modified By" },
deletedBy: { type: DataTypes.BIGINT, allowNull: true, label: "Deleted By" },
}, {
tableName: "assets",
timestamps: true, // createdAt, updatedAt
paranoid: true,
indexes: [
{ fields: ["uuid"] },
{ fields: ["createdBy"] },
{ fields: ["file_type"] },
{ fields: ["deletedAt"] },
],
});
Asset.belongsTo(mdl_Users, { as: "creator", foreignKey: "createdBy" });
Asset.belongsTo(mdl_Users, { as: "updater", foreignKey: "updatedBy" });
module.exports = Asset;