30375/backend/src/db/models/geospatial_files.js
2025-04-01 10:13:13 +00:00

86 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 geospatial_files = sequelize.define(
'geospatial_files',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
file_name: {
type: DataTypes.TEXT,
},
file_type: {
type: DataTypes.ENUM,
values: ['GeoTIFF', 'Shapefile', 'GeoJSON'],
},
uploaded_at: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
geospatial_files.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.geospatial_files.hasMany(db.map_layers, {
as: 'map_layers_geospatial_file',
foreignKey: {
name: 'geospatial_fileId',
},
constraints: false,
});
//end loop
db.geospatial_files.belongsTo(db.users, {
as: 'uploaded_by',
foreignKey: {
name: 'uploaded_byId',
},
constraints: false,
});
db.geospatial_files.hasMany(db.file, {
as: 'file_data',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.geospatial_files.getTableName(),
belongsToColumn: 'file_data',
},
});
db.geospatial_files.belongsTo(db.users, {
as: 'createdBy',
});
db.geospatial_files.belongsTo(db.users, {
as: 'updatedBy',
});
};
return geospatial_files;
};