UNPKG

synt_backend

Version:

Synt light-weight node backend service

52 lines (51 loc) 1.38 kB
"use strict"; const { Model } = require("sequelize"); import { getPresignedUrl } from "./../../helpers/upload"; module.exports = (sequelize, DataTypes) => { class DocumentFile extends Model { /** * Helper method for defining associations. * This method is not a part of Sequelize lifecycle. * The `models/index` file will call this method automatically. */ static associate(models) { // define association here DocumentFile.belongsTo(models.Document); } async getPresignedUrl() { try { return await getPresignedUrl({ bucket: this.bucket, key: this.key, }); } catch (error) { console.error("Error generating signed URL:", error); return null; } } } DocumentFile.init( { original_name: { type: DataTypes.STRING, get() { let original_name = this.getDataValue("original_name"); if (original_name.indexOf(".") === -1) { original_name = original_name + "." + this.getDataValue("type").split("/").pop(); } return original_name; }, }, bucket: DataTypes.STRING, key: DataTypes.STRING, url: DataTypes.STRING, type: DataTypes.STRING, }, { sequelize, modelName: "DocumentFile", } ); return DocumentFile; };